Improvements to stdlib.
All SDL_* functions are always available as real symbols, so you can always link against them as a stable ABI. By default, however, all the things that might have dithered down to macros in your application are now force-inlined, to give you the same effect as before and theoretically better performance, but still solve the classic macro problems. Elsewhere, we provide real functions for these things that simply wrap the inline functions, in case one needs to have a real function available. Also: this exposed bugs: SDL_abs() does something different if you had the macro vs the libc function, SDL_memcpy() returns a void* in the function but not the macro, etc.
This commit is contained in:
parent
e79e3b2343
commit
7e934f8f75
7 changed files with 626 additions and 414 deletions
|
@ -22,18 +22,19 @@
|
|||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
#ifndef HAVE_GETENV
|
||||
|
||||
#if defined(__WIN32__)
|
||||
|
||||
#if !defined(SDL_setenv) && defined(__WIN32__)
|
||||
#include "../core/windows/SDL_windows.h"
|
||||
|
||||
/* Note this isn't thread-safe! */
|
||||
|
||||
static char *SDL_envmem = NULL; /* Ugh, memory leak */
|
||||
static size_t SDL_envmemlen = 0;
|
||||
#endif
|
||||
|
||||
|
||||
/* Put a variable into the environment */
|
||||
#ifdef SDL_setenv
|
||||
#undef SDL_setenv
|
||||
int SDL_setenv(const char *name, const char *value, int overwrite) { return SDL_setenv_inline(name, value, overwrite); }
|
||||
#elif defined(__WIN32__)
|
||||
int
|
||||
SDL_setenv(const char *name, const char *value, int overwrite)
|
||||
{
|
||||
|
@ -49,35 +50,34 @@ SDL_setenv(const char *name, const char *value, int overwrite)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Retrieve a variable named "name" from the environment */
|
||||
char *
|
||||
SDL_getenv(const char *name)
|
||||
/* We have a real environment table, but no real setenv? Fake it w/ putenv. */
|
||||
#elif (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV))
|
||||
int
|
||||
SDL_setenv(const char *name, const char *value, int overwrite)
|
||||
{
|
||||
size_t bufferlen;
|
||||
size_t len;
|
||||
char *new_variable;
|
||||
|
||||
bufferlen =
|
||||
GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
|
||||
if (bufferlen == 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (bufferlen > SDL_envmemlen) {
|
||||
char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen);
|
||||
if (newmem == NULL) {
|
||||
return NULL;
|
||||
if (getenv(name) != NULL) {
|
||||
if (overwrite) {
|
||||
unsetenv(name);
|
||||
} else {
|
||||
return 0; /* leave the existing one there. */
|
||||
}
|
||||
SDL_envmem = newmem;
|
||||
SDL_envmemlen = bufferlen;
|
||||
GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
|
||||
}
|
||||
return SDL_envmem;
|
||||
|
||||
/* This leaks. Sorry. Get a better OS so we don't have to do this. */
|
||||
len = SDL_strlen(name) + SDL_strlen(value) + 2;
|
||||
new_variable = (char *) SDL_malloc(len);
|
||||
if (!new_variable) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
SDL_snprintf(new_variable, len, "%s=%s", name, value);
|
||||
return putenv(new_variable);
|
||||
}
|
||||
|
||||
#else /* roll our own */
|
||||
|
||||
static char **SDL_env = (char **) 0;
|
||||
|
||||
/* Put a variable into the environment */
|
||||
int
|
||||
SDL_setenv(const char *name, const char *value, int overwrite)
|
||||
{
|
||||
|
@ -140,8 +140,35 @@ SDL_setenv(const char *name, const char *value, int overwrite)
|
|||
}
|
||||
return (added ? 0 : -1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Retrieve a variable named "name" from the environment */
|
||||
#ifdef SDL_getenv
|
||||
#undef SDL_getenv
|
||||
char *SDL_getenv(const char *name) { return SDL_getenv_inline(name); }
|
||||
#elif defined(__WIN32__)
|
||||
char *
|
||||
SDL_getenv(const char *name)
|
||||
{
|
||||
size_t bufferlen;
|
||||
|
||||
bufferlen =
|
||||
GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
|
||||
if (bufferlen == 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (bufferlen > SDL_envmemlen) {
|
||||
char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen);
|
||||
if (newmem == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
SDL_envmem = newmem;
|
||||
SDL_envmemlen = bufferlen;
|
||||
GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
|
||||
}
|
||||
return SDL_envmem;
|
||||
}
|
||||
#else
|
||||
char *
|
||||
SDL_getenv(const char *name)
|
||||
{
|
||||
|
@ -160,38 +187,6 @@ SDL_getenv(const char *name)
|
|||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
#endif /* __WIN32__ */
|
||||
|
||||
#endif /* !HAVE_GETENV */
|
||||
|
||||
|
||||
/* We have a real environment table, but no real setenv? Fake it w/ putenv. */
|
||||
#if (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV))
|
||||
int
|
||||
SDL_setenv(const char *name, const char *value, int overwrite)
|
||||
{
|
||||
size_t len;
|
||||
char *new_variable;
|
||||
|
||||
if (getenv(name) != NULL) {
|
||||
if (overwrite) {
|
||||
unsetenv(name);
|
||||
} else {
|
||||
return 0; /* leave the existing one there. */
|
||||
}
|
||||
}
|
||||
|
||||
/* This leaks. Sorry. Get a better OS so we don't have to do this. */
|
||||
len = SDL_strlen(name) + SDL_strlen(value) + 2;
|
||||
new_variable = (char *) SDL_malloc(len);
|
||||
if (!new_variable) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
SDL_snprintf(new_variable, len, "%s=%s", name, value);
|
||||
return putenv(new_variable);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -38,6 +38,20 @@
|
|||
|
||||
#include <errno.h>
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(iconv_t, sizeof (iconv_t) <= sizeof (SDL_iconv_t));
|
||||
|
||||
SDL_iconv_t
|
||||
SDL_iconv_open(const char *tocode, const char *fromcode)
|
||||
{
|
||||
return (SDL_iconv_t) ((size_t) iconv_open(tocode, fromcode));
|
||||
}
|
||||
|
||||
int
|
||||
SDL_iconv_close(SDL_iconv_t cd)
|
||||
{
|
||||
return iconv_close((iconv_t) ((size_t) cd));
|
||||
}
|
||||
|
||||
size_t
|
||||
SDL_iconv(SDL_iconv_t cd,
|
||||
const char **inbuf, size_t * inbytesleft,
|
||||
|
@ -45,9 +59,9 @@ SDL_iconv(SDL_iconv_t cd,
|
|||
{
|
||||
size_t retCode;
|
||||
#ifdef ICONV_INBUF_NONCONST
|
||||
retCode = iconv(cd, (char **) inbuf, inbytesleft, outbuf, outbytesleft);
|
||||
retCode = iconv((iconv_t) ((size_t) cd), (char **) inbuf, inbytesleft, outbuf, outbytesleft);
|
||||
#else
|
||||
retCode = iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft);
|
||||
retCode = iconv((iconv_t) ((size_t) cd), inbuf, inbytesleft, outbuf, outbytesleft);
|
||||
#endif
|
||||
if (retCode == (size_t) - 1) {
|
||||
switch (errno) {
|
||||
|
|
|
@ -24,7 +24,18 @@
|
|||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
#ifndef HAVE_MALLOC
|
||||
#ifdef SDL_malloc
|
||||
/* expose the symbol, but use what we figured out elsewhere. */
|
||||
#undef SDL_malloc
|
||||
#undef SDL_calloc
|
||||
#undef SDL_realloc
|
||||
#undef SDL_free
|
||||
void *SDL_malloc(size_t size) { return SDL_malloc_inline(size); }
|
||||
void *SDL_calloc(size_t nmemb, size_t size) { return SDL_calloc_inline(nmemb, size); }
|
||||
void *SDL_realloc(void *ptr, size_t size) { return SDL_realloc_inline(ptr, size); }
|
||||
void SDL_free(void *ptr) { SDL_free_inline(ptr); }
|
||||
|
||||
#else /* the rest of this is a LOT of tapdancing to implement malloc. :) */
|
||||
|
||||
#define LACKS_SYS_TYPES_H
|
||||
#define LACKS_STDIO_H
|
||||
|
|
|
@ -51,6 +51,15 @@
|
|||
#include "SDL_stdinc.h"
|
||||
#include "SDL_assert.h"
|
||||
|
||||
#ifdef SDL_qsort
|
||||
#undef SDL_qsort
|
||||
void
|
||||
SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *))
|
||||
{
|
||||
SDL_qsort_inline(base, nmemb, size, compare);
|
||||
}
|
||||
#else
|
||||
|
||||
#ifdef assert
|
||||
#undef assert
|
||||
#endif
|
||||
|
@ -76,9 +85,6 @@
|
|||
#endif
|
||||
#define qsort SDL_qsort
|
||||
|
||||
|
||||
#ifndef HAVE_QSORT
|
||||
|
||||
static const char _ID[] = "<qsort.c gjm 1.12 1998-03-19>";
|
||||
|
||||
/* How many bytes are there per word? (Must be a power of 2,
|
||||
|
@ -466,5 +472,6 @@ qsort(void *base, size_t nmemb, size_t size,
|
|||
qsort_words(base, nmemb, compare);
|
||||
}
|
||||
|
||||
#endif /* !HAVE_QSORT */
|
||||
#endif /* !SDL_qsort */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -24,6 +24,25 @@
|
|||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
/* these are always #defined, make them real symbol in the library, too... */
|
||||
#undef SDL_ceil
|
||||
#undef SDL_abs
|
||||
#undef SDL_sinf
|
||||
#undef SDL_cosf
|
||||
#undef SDL_isdigit
|
||||
#undef SDL_isspace
|
||||
#undef SDL_toupper
|
||||
#undef SDL_tolower
|
||||
double SDL_ceil(double x) { return SDL_ceil_inline(x); }
|
||||
float SDL_cosf(float x) { return SDL_cosf_inline(x); }
|
||||
float SDL_sinf(float x) { return SDL_sinf_inline(x); }
|
||||
int SDL_abs(int x) { return SDL_abs_inline(x); }
|
||||
int SDL_isdigit(int x) { return SDL_isdigit_inline(x); }
|
||||
int SDL_isspace(int x) { return SDL_isspace_inline(x); }
|
||||
int SDL_toupper(int x) { return SDL_toupper_inline(x); }
|
||||
int SDL_tolower(int x) { return SDL_tolower_inline(x); }
|
||||
|
||||
|
||||
#ifndef HAVE_LIBC
|
||||
/* These are some C runtime intrinsics that need to be defined */
|
||||
|
||||
|
|
|
@ -24,6 +24,17 @@
|
|||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
/* these are always #defined, make them real symbol in the library, too... */
|
||||
#undef SDL_itoa
|
||||
#undef SDL_uitoa
|
||||
#undef SDL_atoi
|
||||
#undef SDL_atof
|
||||
char *SDL_itoa(int value, char *str, int radix) { return SDL_itoa_inline(value, str, radix); }
|
||||
char *SDL_uitoa(unsigned int value, char *str, int radix) { return SDL_uitoa_inline(value, str, radix); }
|
||||
int SDL_atoi(const char *str) { return SDL_atoi(str); }
|
||||
double SDL_atof(const char *str) { return SDL_atof(str); }
|
||||
|
||||
|
||||
|
||||
#define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F'))
|
||||
#define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f'))
|
||||
|
@ -43,7 +54,7 @@ static int UTF8_TrailingBytes(unsigned char c)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOL)
|
||||
#if !defined(SDL_sscanf) || !defined(SDL_strtol)
|
||||
static size_t
|
||||
SDL_ScanLong(const char *text, int radix, long *valuep)
|
||||
{
|
||||
|
@ -84,7 +95,7 @@ SDL_ScanLong(const char *text, int radix, long *valuep)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
|
||||
#if !defined(SDL_sscanf) || !defined(SDL_strtoul) || !defined(SDL_strtod)
|
||||
static size_t
|
||||
SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
|
||||
{
|
||||
|
@ -116,7 +127,7 @@ SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SSCANF
|
||||
#ifndef SDL_sscanf
|
||||
static size_t
|
||||
SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep)
|
||||
{
|
||||
|
@ -148,7 +159,7 @@ SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL)
|
||||
#if !defined(SDL_sscanf) || !defined(SDL_strtoll)
|
||||
static size_t
|
||||
SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep)
|
||||
{
|
||||
|
@ -189,7 +200,7 @@ SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL)
|
||||
#if !defined(SDL_sscanf) || !defined(SDL_strtoull)
|
||||
static size_t
|
||||
SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep)
|
||||
{
|
||||
|
@ -221,7 +232,7 @@ SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD)
|
||||
#if !defined(SDL_sscanf) || !defined(SDL_strtod)
|
||||
static size_t
|
||||
SDL_ScanFloat(const char *text, double *valuep)
|
||||
{
|
||||
|
@ -257,7 +268,11 @@ SDL_ScanFloat(const char *text, double *valuep)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef SDL_memset
|
||||
|
||||
#ifdef SDL_memset
|
||||
#undef SDL_memset
|
||||
void *SDL_memset(void *dst, int c, size_t len) { return SDL_memset_inline(dst, c, len); }
|
||||
#else
|
||||
void *
|
||||
SDL_memset(void *dst, int c, size_t len)
|
||||
{
|
||||
|
@ -287,7 +302,11 @@ SDL_memset(void *dst, int c, size_t len)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef SDL_memcpy
|
||||
|
||||
#ifdef SDL_memcpy
|
||||
#undef SDL_memcpy
|
||||
void *SDL_memcpy(void *dst, const void *src, size_t len) { return SDL_memcpy_inline(dst, src, len); }
|
||||
#else
|
||||
void *
|
||||
SDL_memcpy(void *dst, const void *src, size_t len)
|
||||
{
|
||||
|
@ -317,7 +336,11 @@ SDL_memcpy(void *dst, const void *src, size_t len)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef SDL_memmove
|
||||
|
||||
#ifdef SDL_memmove
|
||||
#undef SDL_memmove
|
||||
void *SDL_memmove(void *dst, const void *src, size_t len) { return SDL_memmove_inline(dst, src, len); }
|
||||
#else
|
||||
void *
|
||||
SDL_memmove(void *dst, const void *src, size_t len)
|
||||
{
|
||||
|
@ -339,7 +362,10 @@ SDL_memmove(void *dst, const void *src, size_t len)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef SDL_memcmp
|
||||
#ifdef SDL_memcmp
|
||||
#undef SDL_memcmp
|
||||
int SDL_memcmp(const void *s1, const void *s2, size_t len) { return SDL_memcmp_inline(s1, s2, len); }
|
||||
#else
|
||||
int
|
||||
SDL_memcmp(const void *s1, const void *s2, size_t len)
|
||||
{
|
||||
|
@ -356,7 +382,10 @@ SDL_memcmp(const void *s1, const void *s2, size_t len)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRLEN
|
||||
#ifdef SDL_strlen
|
||||
#undef SDL_strlen
|
||||
size_t SDL_strlen(const char *string) { return SDL_strlen_inline(string); }
|
||||
#else
|
||||
size_t
|
||||
SDL_strlen(const char *string)
|
||||
{
|
||||
|
@ -368,7 +397,10 @@ SDL_strlen(const char *string)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_WCSLEN
|
||||
#ifdef SDL_wcslen
|
||||
#undef SDL_wcslen
|
||||
size_t SDL_wcslen(const wchar_t * string) { return SDL_wcslen_inline(string); }
|
||||
#else
|
||||
size_t
|
||||
SDL_wcslen(const wchar_t * string)
|
||||
{
|
||||
|
@ -380,7 +412,10 @@ SDL_wcslen(const wchar_t * string)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_WCSLCPY
|
||||
#ifdef SDL_wcslcpy
|
||||
#undef SDL_wcslcpy
|
||||
size_t SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen) { return SDL_wcslcpy_inline(dst, src, maxlen); }
|
||||
#else
|
||||
size_t
|
||||
SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
|
||||
{
|
||||
|
@ -394,7 +429,10 @@ SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_WCSLCAT
|
||||
#ifdef SDL_wcslcat
|
||||
#undef SDL_wcslcat
|
||||
size_t SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen) { return SDL_wcslcat_inline(dst, src, maxlen); }
|
||||
#else
|
||||
size_t
|
||||
SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
|
||||
{
|
||||
|
@ -407,7 +445,10 @@ SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
#ifdef SDL_strlcpy
|
||||
#undef SDL_strlcpy
|
||||
size_t SDL_strlcpy(char *dst, const char *src, size_t maxlen) { return SDL_strlcpy_inline(dst, src, maxlen); }
|
||||
#else
|
||||
size_t
|
||||
SDL_strlcpy(char *dst, const char *src, size_t maxlen)
|
||||
{
|
||||
|
@ -453,7 +494,10 @@ size_t SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes)
|
|||
return bytes;
|
||||
}
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
#ifdef SDL_strlcat
|
||||
#undef SDL_strlcat
|
||||
size_t SDL_strlcat(char *dst, const char *src, size_t maxlen) { return SDL_strlcat_inline(dst, src, maxlen); }
|
||||
#else
|
||||
size_t
|
||||
SDL_strlcat(char *dst, const char *src, size_t maxlen)
|
||||
{
|
||||
|
@ -466,7 +510,10 @@ SDL_strlcat(char *dst, const char *src, size_t maxlen)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
#ifdef SDL_strdup
|
||||
#undef SDL_strdup
|
||||
char *SDL_strdup(const char *string) { return SDL_strdup_inline(string); }
|
||||
#else
|
||||
char *
|
||||
SDL_strdup(const char *string)
|
||||
{
|
||||
|
@ -479,7 +526,10 @@ SDL_strdup(const char *string)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE__STRREV
|
||||
#ifdef SDL_strrev
|
||||
#undef SDL_strrev
|
||||
char *SDL_strrev(char *string) { return SDL_strrev_inline(string); }
|
||||
#else
|
||||
char *
|
||||
SDL_strrev(char *string)
|
||||
{
|
||||
|
@ -496,7 +546,10 @@ SDL_strrev(char *string)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE__STRUPR
|
||||
#ifdef SDL_strupr
|
||||
#undef SDL_strupr
|
||||
char *SDL_strupr(char *string) { return SDL_strupr_inline(string); }
|
||||
#else
|
||||
char *
|
||||
SDL_strupr(char *string)
|
||||
{
|
||||
|
@ -509,7 +562,10 @@ SDL_strupr(char *string)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE__STRLWR
|
||||
#ifdef SDL_strlwr
|
||||
#undef SDL_strlwr
|
||||
char *SDL_strlwr(char *string) { return SDL_strlwr_inline(string); }
|
||||
#else
|
||||
char *
|
||||
SDL_strlwr(char *string)
|
||||
{
|
||||
|
@ -522,7 +578,10 @@ SDL_strlwr(char *string)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRCHR
|
||||
#ifdef SDL_strchr
|
||||
#undef SDL_strchr
|
||||
char *SDL_strchr(const char *string, int c) { return SDL_strchr_inline(string, c); }
|
||||
#else
|
||||
char *
|
||||
SDL_strchr(const char *string, int c)
|
||||
{
|
||||
|
@ -536,7 +595,10 @@ SDL_strchr(const char *string, int c)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRRCHR
|
||||
#ifdef SDL_strrchr
|
||||
#undef SDL_strrchr
|
||||
char *SDL_strrchr(const char *string, int c) { return SDL_strrchr_inline(string, c); }
|
||||
#else
|
||||
char *
|
||||
SDL_strrchr(const char *string, int c)
|
||||
{
|
||||
|
@ -551,7 +613,10 @@ SDL_strrchr(const char *string, int c)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRSTR
|
||||
#ifdef SDL_strstr
|
||||
#undef SDL_strstr
|
||||
char *SDL_strstr(const char *haystack, const char *needle) { return SDL_strstr_inline(haystack, needle); }
|
||||
#else
|
||||
char *
|
||||
SDL_strstr(const char *haystack, const char *needle)
|
||||
{
|
||||
|
@ -566,8 +631,8 @@ SDL_strstr(const char *haystack, const char *needle)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE__LTOA) || !defined(HAVE__I64TOA) || \
|
||||
!defined(HAVE__ULTOA) || !defined(HAVE__UI64TOA)
|
||||
#if !defined(SDL_ltoa) || !defined(SDL_lltoa) || \
|
||||
!defined(SDL_ultoa) || !defined(SDL_ulltoa)
|
||||
static const char ntoa_table[] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
||||
|
@ -576,7 +641,10 @@ static const char ntoa_table[] = {
|
|||
};
|
||||
#endif /* ntoa() conversion table */
|
||||
|
||||
#ifndef HAVE__LTOA
|
||||
#ifdef SDL_ltoa
|
||||
#undef SDL_ltoa
|
||||
char *SDL_ltoa(long value, char *string, int radix) { return SDL_ltoa_inline(value, string, radix); }
|
||||
#else
|
||||
char *
|
||||
SDL_ltoa(long value, char *string, int radix)
|
||||
{
|
||||
|
@ -607,7 +675,10 @@ SDL_ltoa(long value, char *string, int radix)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE__ULTOA
|
||||
#ifdef SDL_ultoa
|
||||
#undef SDL_ultoa
|
||||
char *SDL_ultoa(unsigned long value, char *string, int radix) { return SDL_ultoa_inline(value, string, radix); }
|
||||
#else
|
||||
char *
|
||||
SDL_ultoa(unsigned long value, char *string, int radix)
|
||||
{
|
||||
|
@ -630,7 +701,10 @@ SDL_ultoa(unsigned long value, char *string, int radix)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRTOL
|
||||
#ifdef SDL_strtol
|
||||
#undef SDL_strtol
|
||||
long SDL_strtol(const char *string, char **endp, int base) { return SDL_strtol_inline(string, endp, base); }
|
||||
#else
|
||||
long
|
||||
SDL_strtol(const char *string, char **endp, int base)
|
||||
{
|
||||
|
@ -653,7 +727,10 @@ SDL_strtol(const char *string, char **endp, int base)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRTOUL
|
||||
#ifdef SDL_strtoul
|
||||
#undef SDL_strtoul
|
||||
unsigned long SDL_strtoul(const char *string, char **endp, int base) { return SDL_strtoul_inline(string, endp, base); }
|
||||
#else
|
||||
unsigned long
|
||||
SDL_strtoul(const char *string, char **endp, int base)
|
||||
{
|
||||
|
@ -676,7 +753,10 @@ SDL_strtoul(const char *string, char **endp, int base)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE__I64TOA
|
||||
#ifdef SDL_lltoa
|
||||
#undef SDL_lltoa
|
||||
char *SDL_lltoa(Sint64 value, char *string, int radix) { return SDL_lltoa_inline(value, string, radix); }
|
||||
#else
|
||||
char *
|
||||
SDL_lltoa(Sint64 value, char *string, int radix)
|
||||
{
|
||||
|
@ -707,7 +787,10 @@ SDL_lltoa(Sint64 value, char *string, int radix)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE__UI64TOA
|
||||
#ifdef SDL_ulltoa
|
||||
#undef SDL_ulltoa
|
||||
char *SDL_ulltoa(Uint64 value, char *string, int radix) { return SDL_ulltoa_inline(value, string, radix); }
|
||||
#else
|
||||
char *
|
||||
SDL_ulltoa(Uint64 value, char *string, int radix)
|
||||
{
|
||||
|
@ -730,7 +813,10 @@ SDL_ulltoa(Uint64 value, char *string, int radix)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRTOLL
|
||||
#ifdef SDL_strtoll
|
||||
#undef SDL_strtoll
|
||||
Sint64 SDL_strtoll(const char *string, char **endp, int base) { return SDL_strtoll_inline(string, endp, base); }
|
||||
#else
|
||||
Sint64
|
||||
SDL_strtoll(const char *string, char **endp, int base)
|
||||
{
|
||||
|
@ -753,7 +839,10 @@ SDL_strtoll(const char *string, char **endp, int base)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRTOULL
|
||||
#ifdef SDL_strtoull
|
||||
#undef SDL_strtoull
|
||||
Uint64 SDL_strtoull(const char *string, char **endp, int base) { return SDL_strtoull_inline(string, endp, base); }
|
||||
#else
|
||||
Uint64
|
||||
SDL_strtoull(const char *string, char **endp, int base)
|
||||
{
|
||||
|
@ -776,7 +865,10 @@ SDL_strtoull(const char *string, char **endp, int base)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRTOD
|
||||
#ifdef SDL_strtod
|
||||
#undef SDL_strtod
|
||||
double SDL_strtod(const char *string, char **endp) { return SDL_strtod_inline(string, endp); }
|
||||
#else
|
||||
double
|
||||
SDL_strtod(const char *string, char **endp)
|
||||
{
|
||||
|
@ -791,7 +883,10 @@ SDL_strtod(const char *string, char **endp)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRCMP
|
||||
#ifdef SDL_strcmp
|
||||
#undef SDL_strcmp
|
||||
int SDL_strcmp(const char *str1, const char *str2) { return SDL_strcmp_inline(str1, str2); }
|
||||
#else
|
||||
int
|
||||
SDL_strcmp(const char *str1, const char *str2)
|
||||
{
|
||||
|
@ -805,7 +900,10 @@ SDL_strcmp(const char *str1, const char *str2)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRNCMP
|
||||
#ifdef SDL_strncmp
|
||||
#undef SDL_strncmp
|
||||
int SDL_strncmp(const char *str1, const char *str2, size_t maxlen) { return SDL_strncmp_inline(str1, str2, maxlen); }
|
||||
#else
|
||||
int
|
||||
SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
|
||||
{
|
||||
|
@ -823,7 +921,10 @@ SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_STRCASECMP) && !defined(HAVE__STRICMP)
|
||||
#ifdef SDL_strcasecmp
|
||||
#undef SDL_strcasecmp
|
||||
int SDL_strcasecmp(const char *str1, const char *str2) { return SDL_strcasecmp(str1, str2); }
|
||||
#else
|
||||
int
|
||||
SDL_strcasecmp(const char *str1, const char *str2)
|
||||
{
|
||||
|
@ -843,7 +944,10 @@ SDL_strcasecmp(const char *str1, const char *str2)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_STRNCASECMP) && !defined(HAVE__STRNICMP)
|
||||
#ifdef SDL_strncasecmp
|
||||
#undef SDL_strncasecmp
|
||||
int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) { return SDL_strncasecmp_inline(str1, str2, maxlen); }
|
||||
#else
|
||||
int
|
||||
SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
|
||||
{
|
||||
|
@ -868,7 +972,19 @@ SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SSCANF
|
||||
#ifdef SDL_sscanf
|
||||
#undef SDL_sscanf
|
||||
int
|
||||
SDL_sscanf(const char *text, const char *fmt, ...)
|
||||
{
|
||||
int rc;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
rc = vsscanf(text, fmt, ap);
|
||||
va_end(ap);
|
||||
return rc;
|
||||
}
|
||||
#else
|
||||
int
|
||||
SDL_sscanf(const char *text, const char *fmt, ...)
|
||||
{
|
||||
|
@ -1136,7 +1252,10 @@ SDL_sscanf(const char *text, const char *fmt, ...)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SNPRINTF
|
||||
/* just undef; the headers only define this to snprintf because of varargs. */
|
||||
#ifdef SDL_snprintf
|
||||
#undef SDL_snprintf
|
||||
#endif
|
||||
int
|
||||
SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
|
||||
{
|
||||
|
@ -1149,9 +1268,11 @@ SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
|
|||
|
||||
return retval;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VSNPRINTF
|
||||
#ifdef SDL_vsnprintf
|
||||
#undef SDL_vsnprintf
|
||||
int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) { return SDL_vsnprintf_inline(text, maxlen, fmt, ap); }
|
||||
#else
|
||||
static size_t
|
||||
SDL_PrintLong(char *text, long value, int radix, size_t maxlen)
|
||||
{
|
||||
|
@ -1414,4 +1535,5 @@ SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
|
|||
return (int)(text - textstart);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue