crt: Define atoll/strto[u]ll/strto[iu]max functions for all msvcrt builds
Functions _atoi64, _strtoi64 and _strtoui64 are available since the first
release of msvcrt.dll as part of MS Visual C++ 4.2.
Define functions atoll, strtoll, strtoull, strtoimax and strtoumax as
aliases for msvcrt _atoi64, _strtoi64 and _strtoui64 functions directly in
def files. This would allow applications to directly link to msvcrt
functions. Currently these functions are provided by mingw-w64 functions
strtoimax and strtoumax which are (statically) linked into executables.
Note that all these functions are provided since msvcr120.dll which is part
of MS Visual Studio 2013.
For compatibility with older msvcrt versions, functions _strtoi64 and
_strtoui64 are provided by mingw-w64 as aliases to mingw-w64 strtoimax and
strtoumax implementations.
Also implement atoll() and _atoi64() via strtoll() for older msvcrt
versions.
This change also removes static inline function atoll as now it is always
provided as alias at the link time for every msvcrt version.
Note that mingw-w64 functions strtoimax(), strtoumax() and atoll() should
not be packed into libmingwex.a because libmingwex.a takes precedence over
libmsvcr*.a. To ensure that version from libmsvcr*.a is used, it is
required to move mingw-w64 implementations from libmingwex.a to libmsvcr*.a
(for msvcrt versions which do not provide these functions).
Tested with following simple program and verified that compiled binary
calls _atoi64 and _strtoi64 symbols from msvcrt.dll:
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
int main(int argc, char *argv[]) {
printf("%lld\n", atoll(argv[1]));
printf("%lld\n", strtoll(argv[1], NULL, 0));
printf("%lld\n", strtoimax(argv[1], NULL, 0));
}
Signed-off-by: LIU Hao <lh_mouse@126.com>
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 28d74c6..5aac06e 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -439,8 +439,11 @@
misc/invalid_parameter_handler.c \
misc/lc_locale_func.c \
misc/seterrno.c \
+ misc/strtoimax.c \
+ misc/strtoumax.c \
stdio/_scprintf.c \
stdio/_vscprintf.c \
+ stdio/atoll.c \
stdio/mingw_dummy__lock.c \
stdio/mingw_lock.c
@@ -456,8 +459,11 @@
misc/invalid_parameter_handler.c \
misc/lc_locale_func.c \
misc/seterrno.c \
+ misc/strtoimax.c \
+ misc/strtoumax.c \
stdio/_scprintf.c \
stdio/_vscprintf.c \
+ stdio/atoll.c \
stdio/mingw_dummy__lock.c \
stdio/mingw_lock.c
@@ -468,8 +474,11 @@
misc/invalid_parameter_handler.c \
misc/lc_locale_func.c \
misc/seterrno.c \
+ misc/strtoimax.c \
+ misc/strtoumax.c \
stdio/_scprintf.c \
stdio/_vscprintf.c \
+ stdio/atoll.c \
stdio/mingw_dummy__lock.c \
stdio/mingw_lock.c
@@ -478,8 +487,11 @@
misc/invalid_parameter_handler.c \
misc/lc_locale_func.c \
misc/seterrno.c \
+ misc/strtoimax.c \
+ misc/strtoumax.c \
stdio/_scprintf.c \
stdio/_vscprintf.c \
+ stdio/atoll.c \
stdio/mingw_dummy__lock.c \
stdio/mingw_lock.c
@@ -563,7 +575,7 @@
misc/mingw_wcstold.c \
misc/mkstemp.c misc/sleep.c \
misc/strnlen.c misc/strsafe.c \
- misc/strtoimax.c misc/strtoumax.c misc/tdelete.c misc/tdestroy.c misc/tfind.c \
+ misc/tdelete.c misc/tdestroy.c misc/tfind.c \
misc/tsearch.c misc/twalk.c \
misc/wcsnlen.c misc/wcstof.c \
misc/wcstoimax.c misc/wcstold.c misc/wcstoumax.c misc/wctob.c misc/wctrans.c \
@@ -582,7 +594,7 @@
stdio/_Exit.c stdio/_findfirst64i32.c stdio/_findnext64i32.c stdio/_fstat.c \
stdio/_fstat64i32.c stdio/_ftime.c \
stdio/_stat.c stdio/_stat64i32.c stdio/_wfindfirst64i32.c stdio/_wfindnext64i32.c \
- stdio/_wstat.c stdio/_wstat64i32.c stdio/asprintf.c stdio/atoll.c stdio/fgetpos64.c \
+ stdio/_wstat.c stdio/_wstat64i32.c stdio/asprintf.c stdio/fgetpos64.c \
stdio/fopen64.c stdio/fseeko32.c stdio/fseeko64.c stdio/fsetpos64.c stdio/ftello.c \
stdio/ftello64.c stdio/ftruncate64.c stdio/lltoa.c stdio/lltow.c stdio/lseek64.c \
stdio/mingw_fprintf.c stdio/mingw_fprintfw.c stdio/mingw_fscanf.c stdio/mingw_fwscanf.c stdio/mingw_pformat.c \
diff --git a/mingw-w64-crt/lib-common/msvcrt.def.in b/mingw-w64-crt/lib-common/msvcrt.def.in
index 942c4c4..695a4d7 100644
--- a/mingw-w64-crt/lib-common/msvcrt.def.in
+++ b/mingw-w64-crt/lib-common/msvcrt.def.in
@@ -387,7 +387,9 @@
_atof_l
_atoflt_l
_atoi64
+atoll == _atoi64
_atoi64_l
+_atoll_l == _atoi64_l
_atoi_l
_atol_l
_atoldbl
@@ -1034,10 +1036,18 @@
; _strtime_s replaced by emu
_strtod_l
_strtoi64
+strtoll == _strtoi64
+strtoimax == _strtoi64
_strtoi64_l
+_strtoll_l == _strtoi64_l
+_strtoimax_l == _strtoi64_l
_strtol_l
_strtoui64
+strtoull == _strtoui64
+strtoumax == _strtoui64
_strtoui64_l
+_strtoull_l == _strtoui64_l
+_strtoumax_l == _strtoui64_l
_strtoul_l
_strupr
_strupr_l
diff --git a/mingw-w64-crt/lib32/msvcr100.def.in b/mingw-w64-crt/lib32/msvcr100.def.in
index 8e8dfb4..6765892 100644
--- a/mingw-w64-crt/lib32/msvcr100.def.in
+++ b/mingw-w64-crt/lib32/msvcr100.def.in
@@ -738,7 +738,9 @@
_atoflt
_atoflt_l
_atoi64
+atoll == _atoi64
_atoi64_l
+_atoll_l == _atoi64_l
_atoi_l
_atol_l
_atoldbl
@@ -1402,10 +1404,18 @@
_strtime_s
_strtod_l
_strtoi64
+strtoll == _strtoi64
+strtoimax == _strtoi64
_strtoi64_l
+_strtoll_l == _strtoi64_l
+_strtoimax_l == _strtoi64_l
_strtol_l
_strtoui64
+strtoull == _strtoui64
+strtoumax == _strtoui64
_strtoui64_l
+_strtoull_l == _strtoui64_l
+_strtoumax_l == _strtoui64_l
_strtoul_l
_strupr
_strupr_l
diff --git a/mingw-w64-crt/lib32/msvcr110.def.in b/mingw-w64-crt/lib32/msvcr110.def.in
index b864009..2f2e19b 100644
--- a/mingw-w64-crt/lib32/msvcr110.def.in
+++ b/mingw-w64-crt/lib32/msvcr110.def.in
@@ -862,7 +862,9 @@
_atoflt
_atoflt_l
_atoi64
+atoll == _atoi64
_atoi64_l
+_atoll_l == _atoi64_l
_atoi_l
_atol_l
_atoldbl
@@ -1535,10 +1537,18 @@
_strtime_s
_strtod_l
_strtoi64
+strtoll == _strtoi64
+strtoimax == _strtoi64
_strtoi64_l
+_strtoll_l == _strtoi64_l
+_strtoimax_l == _strtoi64_l
_strtol_l
_strtoui64
+strtoull == _strtoui64
+strtoumax == _strtoui64
_strtoui64_l
+_strtoull_l == _strtoui64_l
+_strtoumax_l == _strtoui64_l
_strtoul_l
_strupr
_strupr_l
diff --git a/mingw-w64-crt/lib32/msvcr70.def b/mingw-w64-crt/lib32/msvcr70.def
index 5ec73e7..43c469f 100644
--- a/mingw-w64-crt/lib32/msvcr70.def
+++ b/mingw-w64-crt/lib32/msvcr70.def
@@ -259,6 +259,7 @@
_assert
_atodbl
_atoi64
+atoll == _atoi64
_atoldbl
_beep
_beginthread
@@ -581,7 +582,11 @@
_strset
_strtime
_strtoi64
+strtoll == _strtoi64
+strtoimax == _strtoi64
_strtoui64
+strtoull == _strtoui64
+strtoumax == _strtoui64
_strupr
_swab
_sys_errlist DATA
diff --git a/mingw-w64-crt/lib32/msvcr71.def b/mingw-w64-crt/lib32/msvcr71.def
index 1db6d0b..5ec0f2a 100644
--- a/mingw-w64-crt/lib32/msvcr71.def
+++ b/mingw-w64-crt/lib32/msvcr71.def
@@ -253,6 +253,7 @@
_assert
_atodbl
_atoi64
+atoll == _atoi64
_atoldbl
_beep
_beginthread
@@ -576,7 +577,11 @@
_strset
_strtime
_strtoi64
+strtoll == _strtoi64
+strtoimax == _strtoi64
_strtoui64
+strtoull == _strtoui64
+strtoumax == _strtoui64
_strupr
_swab
_sys_errlist DATA
diff --git a/mingw-w64-crt/lib32/msvcr80.def.in b/mingw-w64-crt/lib32/msvcr80.def.in
index bb1ec84..42ded14 100644
--- a/mingw-w64-crt/lib32/msvcr80.def.in
+++ b/mingw-w64-crt/lib32/msvcr80.def.in
@@ -114,6 +114,7 @@
_assert
_atodbl
_atoi64
+atoll == _atoi64
_atoldbl
_beep
_beginthread
@@ -842,7 +843,11 @@
_snscanf
_snwscanf
_strtoi64
+strtoll == _strtoi64
+strtoimax == _strtoi64
_strtoui64
+strtoull == _strtoui64
+strtoumax == _strtoui64
_ungetwch
_vscprintf
_vscwprintf
diff --git a/mingw-w64-crt/lib32/msvcr90.def.in b/mingw-w64-crt/lib32/msvcr90.def.in
index 6278933..f6de764 100644
--- a/mingw-w64-crt/lib32/msvcr90.def.in
+++ b/mingw-w64-crt/lib32/msvcr90.def.in
@@ -363,7 +363,9 @@
_atoflt
_atoflt_l
_atoi64
+atoll == _atoi64
_atoi64_l
+_atoll_l == _atoi64_l
_atoi_l
_atol_l
_atoldbl
@@ -1038,10 +1040,18 @@
_strtime_s
_strtod_l
_strtoi64
+strtoll == _strtoi64
+strtoimax == _strtoi64
_strtoi64_l
+_strtoll_l == _strtoi64_l
+_strtoimax_l == _strtoi64_l
_strtol_l
_strtoui64
+strtoull == _strtoui64
+strtoumax == _strtoui64
_strtoui64_l
+_strtoull_l == _strtoui64_l
+_strtoumax_l == _strtoui64_l
_strtoul_l
_strupr
_strupr_l
diff --git a/mingw-w64-crt/lib32/msvcr90d.def.in b/mingw-w64-crt/lib32/msvcr90d.def.in
index 1175bfe..52c33dc 100644
--- a/mingw-w64-crt/lib32/msvcr90d.def.in
+++ b/mingw-w64-crt/lib32/msvcr90d.def.in
@@ -414,7 +414,9 @@
_atoflt
_atoflt_l
_atoi64
+atoll == _atoi64
_atoi64_l
+_atoll_l == _atoi64_l
_atoi_l
_atol_l
_atoldbl
@@ -1103,10 +1105,18 @@
_strtime_s
_strtod_l
_strtoi64
+strtoll == _strtoi64
+strtoimax == _strtoi64
_strtoi64_l
+_strtoll_l == _strtoi64_l
+_strtoimax_l == _strtoi64_l
_strtol_l
_strtoui64
+strtoull == _strtoui64
+strtoumax == _strtoui64
_strtoui64_l
+_strtoull_l == _strtoui64_l
+_strtoumax_l == _strtoui64_l
_strtoul_l
_strupr
_strupr_l
diff --git a/mingw-w64-crt/lib64/msvcr100.def.in b/mingw-w64-crt/lib64/msvcr100.def.in
index aab9826..1530a71 100644
--- a/mingw-w64-crt/lib64/msvcr100.def.in
+++ b/mingw-w64-crt/lib64/msvcr100.def.in
@@ -696,7 +696,9 @@
_atoflt
_atoflt_l
_atoi64
+atoll == _atoi64
_atoi64_l
+_atoll_l == _atoi64_l
_atoi_l
_atol_l
_atoldbl
@@ -1349,10 +1351,18 @@
_strtime_s
_strtod_l
_strtoi64
+strtoll == _strtoi64
+strtoimax == _strtoi64
_strtoi64_l
+_strtoll_l == _strtoi64_l
+_strtoimax_l == _strtoi64_l
_strtol_l
_strtoui64
+strtoull == _strtoui64
+strtoumax == _strtoui64
_strtoui64_l
+_strtoull_l == _strtoui64_l
+_strtoumax_l == _strtoui64_l
_strtoul_l
_strupr
_strupr_l
diff --git a/mingw-w64-crt/lib64/msvcr110.def.in b/mingw-w64-crt/lib64/msvcr110.def.in
index 60304f9..b5b9e3e 100644
--- a/mingw-w64-crt/lib64/msvcr110.def.in
+++ b/mingw-w64-crt/lib64/msvcr110.def.in
@@ -822,7 +822,9 @@
_atoflt
_atoflt_l
_atoi64
+atoll == _atoi64
_atoi64_l
+_atoll_l == _atoi64_l
_atoi_l
_atol_l
_atoldbl
@@ -1473,10 +1475,18 @@
_strtime_s
_strtod_l
_strtoi64
+strtoll == _strtoi64
+strtoimax == _strtoi64
_strtoi64_l
+_strtoll_l == _strtoi64_l
+_strtoimax_l == _strtoi64_l
_strtol_l
_strtoui64
+strtoull == _strtoui64
+strtoumax == _strtoui64
_strtoui64_l
+_strtoull_l == _strtoui64_l
+_strtoumax_l == _strtoui64_l
_strtoul_l
_strupr
_strupr_l
diff --git a/mingw-w64-crt/lib64/msvcr80.def.in b/mingw-w64-crt/lib64/msvcr80.def.in
index 045052e..171f585 100644
--- a/mingw-w64-crt/lib64/msvcr80.def.in
+++ b/mingw-w64-crt/lib64/msvcr80.def.in
@@ -195,6 +195,7 @@
_assert
_atodbl
_atoi64
+atoll == _atoi64
_atoldbl
_beep
_beginthread
@@ -530,7 +531,11 @@
_strset
_strtime
_strtoi64
+strtoll == _strtoi64
+strtoimax == _strtoi64
_strtoui64
+strtoull == _strtoui64
+strtoumax == _strtoui64
_strupr
_swab
_sys_errlist DATA
diff --git a/mingw-w64-crt/lib64/msvcr90.def.in b/mingw-w64-crt/lib64/msvcr90.def.in
index c8cf9b2..876a672 100644
--- a/mingw-w64-crt/lib64/msvcr90.def.in
+++ b/mingw-w64-crt/lib64/msvcr90.def.in
@@ -311,7 +311,9 @@
_atoflt
_atoflt_l
_atoi64
+atoll == _atoi64
_atoi64_l
+_atoll_l == _atoi64_l
_atoi_l
_atol_l
_atoldbl
@@ -971,10 +973,18 @@
_strtime_s
_strtod_l
_strtoi64
+strtoll == _strtoi64
+strtoimax == _strtoi64
_strtoi64_l
+_strtoll_l == _strtoi64_l
+_strtoimax_l == _strtoi64_l
_strtol_l
_strtoui64
+strtoull == _strtoui64
+strtoumax == _strtoui64
_strtoui64_l
+_strtoull_l == _strtoui64_l
+_strtoumax_l == _strtoui64_l
_strtoul_l
_strupr
_strupr_l
diff --git a/mingw-w64-crt/lib64/msvcr90d.def.in b/mingw-w64-crt/lib64/msvcr90d.def.in
index 2acdc3f..26c5888 100644
--- a/mingw-w64-crt/lib64/msvcr90d.def.in
+++ b/mingw-w64-crt/lib64/msvcr90d.def.in
@@ -356,7 +356,9 @@
_atoflt
_atoflt_l
_atoi64
+atoll == _atoi64
_atoi64_l
+_atoll_l == _atoi64_l
_atoi_l
_atol_l
_atoldbl
@@ -1030,10 +1032,18 @@
_strtime_s
_strtod_l
_strtoi64
+strtoll == _strtoi64
+strtoimax == _strtoi64
_strtoi64_l
+_strtoll_l == _strtoi64_l
+_strtoimax_l == _strtoi64_l
_strtol_l
_strtoui64
+strtoull == _strtoui64
+strtoumax == _strtoui64
_strtoui64_l
+_strtoull_l == _strtoui64_l
+_strtoumax_l == _strtoui64_l
_strtoul_l
_strupr
_strupr_l
diff --git a/mingw-w64-crt/misc/strtoimax.c b/mingw-w64-crt/misc/strtoimax.c
index 9e75f8a..7f09869 100644
--- a/mingw-w64-crt/misc/strtoimax.c
+++ b/mingw-w64-crt/misc/strtoimax.c
@@ -31,6 +31,7 @@
#define valid(n, b) ((n) >= 0 && (n) < (b))
intmax_t
+__cdecl
strtoimax(const char * __restrict__ nptr, char ** __restrict__ endptr, int base)
{
register uintmax_t accum; /* accumulates converted value */
@@ -109,6 +110,14 @@
else
return (intmax_t)(minus ? -accum : accum);
}
+intmax_t (__cdecl *__MINGW_IMP_SYMBOL(strtoimax))(const char* __restrict__, char ** __restrict__, int) = strtoimax;
long long __attribute__ ((alias ("strtoimax")))
+__cdecl
strtoll (const char* __restrict__ nptr, char ** __restrict__ endptr, int base);
+long long (__cdecl *__MINGW_IMP_SYMBOL(strtoll))(const char* __restrict__, char ** __restrict__, int) = strtoll;
+
+__int64 __attribute__ ((alias ("strtoimax")))
+__cdecl
+_strtoi64 (const char* __restrict__ nptr, char ** __restrict__ endptr, int base);
+__int64 (__cdecl *__MINGW_IMP_SYMBOL(_strtoi64))(const char* __restrict__, char ** __restrict__, int) = _strtoi64;
diff --git a/mingw-w64-crt/misc/strtoumax.c b/mingw-w64-crt/misc/strtoumax.c
index 2c24db1..d47a7c9 100644
--- a/mingw-w64-crt/misc/strtoumax.c
+++ b/mingw-w64-crt/misc/strtoumax.c
@@ -31,6 +31,7 @@
#define valid(n, b) ((n) >= 0 && (n) < (b))
uintmax_t
+__cdecl
strtoumax(const char * __restrict__ nptr, char ** __restrict__ endptr, int base)
{
register uintmax_t accum; /* accumulates converted value */
@@ -107,6 +108,14 @@
else
return minus ? -accum : accum; /* (yes!) */
}
+uintmax_t (__cdecl *__MINGW_IMP_SYMBOL(strtoumax))(const char* __restrict__, char ** __restrict__, int) = strtoumax;
unsigned long long __attribute__ ((alias ("strtoumax")))
+__cdecl
strtoull (const char* __restrict__ nptr, char ** __restrict__ endptr, int base);
+unsigned long long (__cdecl *__MINGW_IMP_SYMBOL(strtoull))(const char* __restrict__, char ** __restrict__, int) = strtoull;
+
+unsigned __int64 __attribute__ ((alias ("strtoumax")))
+__cdecl
+_strtoui64 (const char* __restrict__ nptr, char ** __restrict__ endptr, int base);
+unsigned __int64 (__cdecl *__MINGW_IMP_SYMBOL(_strtoui64))(const char* __restrict__, char ** __restrict__, int) = _strtoui64;
diff --git a/mingw-w64-crt/stdio/atoll.c b/mingw-w64-crt/stdio/atoll.c
index 39df013..278c01c 100644
--- a/mingw-w64-crt/stdio/atoll.c
+++ b/mingw-w64-crt/stdio/atoll.c
@@ -6,5 +6,8 @@
#define __CRT__NO_INLINE
#include <stdlib.h>
-long long atoll (const char * _c)
- { return _atoi64 (_c); }
+long long __cdecl atoll(const char * nptr) { return strtoll(nptr, NULL, 10); }
+long long (__cdecl *__MINGW_IMP_SYMBOL(atoll))(const char *) = atoll;
+
+__int64 __attribute__((alias("atoll"))) __cdecl _atoi64(const char * nptr);
+__int64 (__cdecl *__MINGW_IMP_SYMBOL(_atoi64))(const char *) = _atoi64;
diff --git a/mingw-w64-headers/crt/stdlib.h b/mingw-w64-headers/crt/stdlib.h
index 1d864bb..128f3bf 100644
--- a/mingw-w64-headers/crt/stdlib.h
+++ b/mingw-w64-headers/crt/stdlib.h
@@ -749,7 +749,6 @@
/* __CRT_INLINE using non-ansi functions */
#ifndef __CRT__NO_INLINE
- __MINGW_EXTENSION __CRT_INLINE long long __cdecl atoll (const char * _c) { return _atoi64 (_c); }
__MINGW_EXTENSION __CRT_INLINE char *__cdecl lltoa (long long _n, char * _c, int _i) { return _i64toa (_n, _c, _i); }
__MINGW_EXTENSION __CRT_INLINE char *__cdecl ulltoa (unsigned long long _n, char * _c, int _i) { return _ui64toa (_n, _c, _i); }
__MINGW_EXTENSION __CRT_INLINE long long __cdecl wtoll (const wchar_t * _w) { return _wtoi64 (_w); }