Skip to content

Commit

Permalink
win32, stdlib: use _strtoi64() and _strtoui64() when available
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Mar 24, 2018
1 parent 460d095 commit a66cc7f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
10 changes: 10 additions & 0 deletions configure.in
Expand Up @@ -2123,6 +2123,16 @@ CheckWIN32()
])
fi

save_CFLAGS="$CFLAGS"
CFLAGS="$save_CFLAGS -Werror-implicit-function-declaration"
AC_TRY_LINK([#include <stdlib.h>],
[return (int) _strtoi64 (NULL,NULL,0);],
AC_DEFINE(HAVE__STRTOI64))
AC_TRY_LINK([#include <stdlib.h>],
[return (int) _strtoui64(NULL,NULL,0);],
AC_DEFINE(HAVE__STRTOUI64))
CFLAGS="$save_CFLAGS"

dnl See if the user wants to redirect standard output to files
AC_ARG_ENABLE(stdio-redirect,
AC_HELP_STRING([--enable-stdio-redirect], [Redirect STDIO to files on Win32 [[default=yes]]]),
Expand Down
2 changes: 2 additions & 0 deletions include/SDL_config.h.in
Expand Up @@ -117,6 +117,8 @@
#undef HAVE__UI64TOA
#undef HAVE_STRTOLL
#undef HAVE_STRTOULL
#undef HAVE__STRTOI64
#undef HAVE__STRTOUI64
#undef HAVE_STRTOD
#undef HAVE_ATOI
#undef HAVE_ATOF
Expand Down
4 changes: 4 additions & 0 deletions include/SDL_config_win32.h
Expand Up @@ -114,6 +114,10 @@ typedef unsigned int uintptr_t;
#define HAVE_STRTOLL 1
#define HAVE_STRTOULL 1
#endif
#if defined(__WATCOMC__) || (defined(_MSC_VER) && (_MSC_VER >= 1300)) || defined(_WIN64)
#define HAVE__STRTOI64 1
#define HAVE__STRTOUI64 1
#endif
#define HAVE_STRTOD 1
#define HAVE_ATOI 1
#define HAVE_ATOF 1
Expand Down
20 changes: 12 additions & 8 deletions include/SDL_stdinc.h
Expand Up @@ -505,13 +505,17 @@ extern DECLSPEC char* SDLCALL SDL_lltoa(Sint64 value, char *string, int radix);
extern DECLSPEC char* SDLCALL SDL_ulltoa(Uint64 value, char *string, int radix);
#endif

#ifdef HAVE_STRTOLL
#ifdef HAVE__STRTOI64
#define SDL_strtoll _strtoi64
#elif defined(HAVE_STRTOLL)
#define SDL_strtoll strtoll
#else
extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, int base);
#endif

#ifdef HAVE_STRTOULL
#ifdef HAVE__STRTOUI64
#define SDL_strtoull _strtoui64
#elif defined(HAVE_STRTOULL)
#define SDL_strtoull strtoull
#else
extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp, int base);
Expand Down Expand Up @@ -549,18 +553,18 @@ extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
#endif

#ifdef HAVE_STRCASECMP
#define SDL_strcasecmp strcasecmp
#elif defined(HAVE__STRICMP)
#if defined(HAVE__STRICMP)
#define SDL_strcasecmp _stricmp
#elif defined(HAVE_STRCASECMP)
#define SDL_strcasecmp strcasecmp
#else
extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
#endif

#ifdef HAVE_STRNCASECMP
#define SDL_strncasecmp strncasecmp
#elif defined(HAVE__STRNICMP)
#if defined(HAVE__STRNICMP)
#define SDL_strncasecmp _strnicmp
#elif defined(HAVE_STRNCASECMP)
#define SDL_strncasecmp strncasecmp
#else
extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/stdlib/SDL_string.c
Expand Up @@ -603,7 +603,7 @@ char *SDL_ulltoa(Uint64 value, char *string, int radix)
}
#endif

#ifndef HAVE_STRTOLL
#if !defined(HAVE_STRTOLL) && !defined(HAVE__STRTOI64)
Sint64 SDL_strtoll(const char *string, char **endp, int base)
{
size_t len;
Expand All @@ -625,7 +625,7 @@ Sint64 SDL_strtoll(const char *string, char **endp, int base)
}
#endif

#ifndef HAVE_STRTOULL
#if !defined(HAVE_STRTOULL) && !defined(HAVE__STRTOUI64)
Uint64 SDL_strtoull(const char *string, char **endp, int base)
{
size_t len;
Expand Down

0 comments on commit a66cc7f

Please sign in to comment.