sdl 2.0.8 update

This commit is contained in:
Tim 2018-05-09 23:09:05 +10:00
parent d6f6bc65a5
commit ec8f56b3b0
894 changed files with 66879 additions and 43299 deletions

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -29,6 +29,10 @@
#include "../core/windows/SDL_windows.h"
#endif
#if defined(__ANDROID__)
#include "../core/android/SDL_android.h"
#endif
#include "SDL_stdinc.h"
#if defined(__WIN32__) && (!defined(HAVE_SETENV) || !defined(HAVE_GETENV))
@ -60,9 +64,7 @@ SDL_setenv(const char *name, const char *value, int overwrite)
}
if (!overwrite) {
char ch = 0;
const size_t len = GetEnvironmentVariableA(name, &ch, sizeof (ch));
if (len > 0) {
if (GetEnvironmentVariableA(name, NULL, 0) > 0) {
return 0; /* asked not to overwrite existing value. */
}
}
@ -173,8 +175,13 @@ SDL_setenv(const char *name, const char *value, int overwrite)
char *
SDL_getenv(const char *name)
{
#if defined(__ANDROID__)
/* Make sure variables from the application manifest are available */
Android_JNI_GetManifestEnvironmentVariables();
#endif
/* Input validation */
if (!name || SDL_strlen(name)==0) {
if (!name || !*name) {
return NULL;
}

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -38,6 +38,7 @@
If we get this wrong, it's just a warning, so no big deal.
*/
#if defined(_XGP6) || defined(__APPLE__) || \
defined(__EMSCRIPTEN__) || \
(defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) || \
(defined(_NEWLIB_VERSION)))
#define ICONV_INBUF_NONCONST
@ -797,6 +798,7 @@ SDL_iconv(SDL_iconv_t cd,
if (ch > 0x10FFFF) {
ch = UNKNOWN_UNICODE;
}
/* fallthrough */
case ENCODING_UCS4BE:
if (ch > 0x7FFFFFFF) {
ch = UNKNOWN_UNICODE;
@ -818,6 +820,7 @@ SDL_iconv(SDL_iconv_t cd,
if (ch > 0x10FFFF) {
ch = UNKNOWN_UNICODE;
}
/* fallthrough */
case ENCODING_UCS4LE:
if (ch > 0x7FFFFFFF) {
ch = UNKNOWN_UNICODE;

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,33 +26,11 @@
#include "../SDL_internal.h"
/* This file contains portable memory management functions for SDL */
#include "SDL_stdinc.h"
#include "SDL_atomic.h"
#include "SDL_error.h"
#if defined(HAVE_MALLOC)
void *SDL_malloc(size_t size)
{
return malloc(size);
}
void *SDL_calloc(size_t nmemb, size_t size)
{
return calloc(nmemb, size);
}
void *SDL_realloc(void *ptr, size_t size)
{
return realloc(ptr, size);
}
void SDL_free(void *ptr)
{
free(ptr);
}
#else /* the rest of this is a LOT of tapdancing to implement malloc. :) */
#ifndef HAVE_MALLOC
#define LACKS_SYS_TYPES_H
#define LACKS_STDIO_H
#define LACKS_STRINGS_H
@ -60,6 +38,7 @@ void SDL_free(void *ptr)
#define LACKS_STDLIB_H
#define ABORT
#define USE_LOCKS 1
#define USE_DL_PREFIX
/*
This is a version (aka dlmalloc) of malloc/free/realloc written by
@ -636,12 +615,12 @@ DEFAULT_MMAP_THRESHOLD default: 256K
#define MALLINFO_FIELD_TYPE size_t
#endif /* MALLINFO_FIELD_TYPE */
#ifndef memset
#define memset SDL_memset
#endif
#ifndef memcpy
#define memcpy SDL_memcpy
#define malloc SDL_malloc
#define calloc SDL_calloc
#define realloc SDL_realloc
#define free SDL_free
#endif
/*
mallopt tuning options. SVID/XPG defines four standard parameter
@ -2946,13 +2925,17 @@ static void
internal_malloc_stats(mstate m)
{
if (!PREACTION(m)) {
#ifndef LACKS_STDIO_H
size_t maxfp = 0;
#endif
size_t fp = 0;
size_t used = 0;
check_malloc_state(m);
if (is_initialized(m)) {
msegmentptr s = &m->seg;
#ifndef LACKS_STDIO_H
maxfp = m->max_footprint;
#endif
fp = m->footprint;
used = fp - (m->topsize + TOP_FOOT_SIZE);
@ -5261,4 +5244,133 @@ History:
#endif /* !HAVE_MALLOC */
#ifdef HAVE_MALLOC
#define real_malloc malloc
#define real_calloc calloc
#define real_realloc realloc
#define real_free free
#else
#define real_malloc dlmalloc
#define real_calloc dlcalloc
#define real_realloc dlrealloc
#define real_free dlfree
#endif
/* Memory functions used by SDL that can be replaced by the application */
static struct
{
SDL_malloc_func malloc_func;
SDL_calloc_func calloc_func;
SDL_realloc_func realloc_func;
SDL_free_func free_func;
SDL_atomic_t num_allocations;
} s_mem = {
real_malloc, real_calloc, real_realloc, real_free, { 0 }
};
void SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
SDL_calloc_func *calloc_func,
SDL_realloc_func *realloc_func,
SDL_free_func *free_func)
{
if (malloc_func) {
*malloc_func = s_mem.malloc_func;
}
if (calloc_func) {
*calloc_func = s_mem.calloc_func;
}
if (realloc_func) {
*realloc_func = s_mem.realloc_func;
}
if (free_func) {
*free_func = s_mem.free_func;
}
}
int SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
SDL_calloc_func calloc_func,
SDL_realloc_func realloc_func,
SDL_free_func free_func)
{
if (!malloc_func) {
return SDL_InvalidParamError("malloc_func");
}
if (!calloc_func) {
return SDL_InvalidParamError("calloc_func");
}
if (!realloc_func) {
return SDL_InvalidParamError("realloc_func");
}
if (!free_func) {
return SDL_InvalidParamError("free_func");
}
s_mem.malloc_func = malloc_func;
s_mem.calloc_func = calloc_func;
s_mem.realloc_func = realloc_func;
s_mem.free_func = free_func;
return 0;
}
int SDL_GetNumAllocations(void)
{
return SDL_AtomicGet(&s_mem.num_allocations);
}
void *SDL_malloc(size_t size)
{
void *mem;
if (!size) {
size = 1;
}
mem = s_mem.malloc_func(size);
if (mem) {
SDL_AtomicIncRef(&s_mem.num_allocations);
}
return mem;
}
void *SDL_calloc(size_t nmemb, size_t size)
{
void *mem;
if (!nmemb || !size) {
nmemb = 1;
size = 1;
}
mem = s_mem.calloc_func(nmemb, size);
if (mem) {
SDL_AtomicIncRef(&s_mem.num_allocations);
}
return mem;
}
void *SDL_realloc(void *ptr, size_t size)
{
void *mem;
if (!ptr && !size) {
size = 1;
}
mem = s_mem.realloc_func(ptr, size);
if (mem && !ptr) {
SDL_AtomicIncRef(&s_mem.num_allocations);
}
return mem;
}
void SDL_free(void *ptr)
{
if (!ptr) {
return;
}
s_mem.free_func(ptr);
(void)SDL_AtomicDecRef(&s_mem.num_allocations);
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -275,7 +275,7 @@ typedef struct { char * first; char * last; } stack_entry;
/* and so is the pivoting logic (note: last is inclusive): */
#define Pivot(swapper,sz) \
if (last-first>PIVOT_THRESHOLD*sz) mid=pivot_big(first,mid,last,sz,compare);\
if ((size_t)(last-first)>PIVOT_THRESHOLD*sz) mid=pivot_big(first,mid,last,sz,compare);\
else { \
if (compare(first,mid)<0) { \
if (compare(mid,last)>0) { \
@ -362,7 +362,7 @@ typedef struct { char * first; char * last; } stack_entry;
static char * pivot_big(char *first, char *mid, char *last, size_t size,
int compare(const void *, const void *)) {
int d=(((last-first)/size)>>3)*size;
size_t d=(((last-first)/size)>>3)*size;
#ifdef DEBUG_QSORT
fprintf(stderr, "pivot_big: first=%p last=%p size=%lu n=%lu\n", first, (unsigned long)last, size, (unsigned long)((last-first+1)/size));
#endif
@ -413,7 +413,7 @@ static void qsort_nonaligned(void *base, size_t nmemb, size_t size,
first=(char*)base; last=first+(nmemb-1)*size;
if (last-first>=trunc) {
if ((size_t)(last-first)>=trunc) {
char *ffirst=first, *llast=last;
while (1) {
/* Select pivot */
@ -444,7 +444,7 @@ static void qsort_aligned(void *base, size_t nmemb, size_t size,
first=(char*)base; last=first+(nmemb-1)*size;
if (last-first>=trunc) {
if ((size_t)(last-first)>=trunc) {
char *ffirst=first,*llast=last;
while (1) {
/* Select pivot */
@ -519,7 +519,7 @@ extern void qsortG(void *base, size_t nmemb, size_t size,
int (*compare)(const void *, const void *)) {
if (nmemb<=1) return;
if (((int)base|size)&(WORD_BYTES-1))
if (((size_t)base|size)&(WORD_BYTES-1))
qsort_nonaligned(base,nmemb,size,compare);
else if (size!=WORD_BYTES)
qsort_aligned(base,nmemb,size,compare);

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -38,7 +38,17 @@ SDL_atan(double x)
return atan(x);
#else
return SDL_uclibc_atan(x);
#endif /* HAVE_ATAN */
#endif
}
float
SDL_atanf(float x)
{
#if defined(HAVE_ATANF)
return atanf(x);
#else
return (float)SDL_atan((double)x);
#endif
}
double
@ -48,7 +58,17 @@ SDL_atan2(double x, double y)
return atan2(x, y);
#else
return SDL_uclibc_atan2(x, y);
#endif /* HAVE_ATAN2 */
#endif
}
float
SDL_atan2f(float x, float y)
{
#if defined(HAVE_ATAN2F)
return atan2f(x, y);
#else
return (float)SDL_atan2((double)x, (double)y);
#endif
}
double
@ -71,6 +91,16 @@ SDL_acos(double val)
#endif
}
float
SDL_acosf(float val)
{
#if defined(HAVE_ACOSF)
return acosf(val);
#else
return (float)SDL_acos((double)val);
#endif
}
double
SDL_asin(double val)
{
@ -87,6 +117,16 @@ SDL_asin(double val)
#endif
}
float
SDL_asinf(float val)
{
#if defined(HAVE_ASINF)
return asinf(val);
#else
return (float)SDL_asin((double)val);
#endif
}
double
SDL_ceil(double x)
{
@ -102,6 +142,16 @@ SDL_ceil(double x)
#endif /* HAVE_CEIL */
}
float
SDL_ceilf(float x)
{
#if defined(HAVE_CEILF)
return ceilf(x);
#else
return (float)SDL_ceil((float)x);
#endif
}
double
SDL_copysign(double x, double y)
{
@ -109,11 +159,27 @@ SDL_copysign(double x, double y)
return copysign(x, y);
#elif defined(HAVE__COPYSIGN)
return _copysign(x, y);
#elif defined(__WATCOMC__) && defined(__386__)
/* this is nasty as hell, but it works.. */
unsigned int *xi = (unsigned int *) &x,
*yi = (unsigned int *) &y;
xi[1] = (yi[1] & 0x80000000) | (xi[1] & 0x7fffffff);
return x;
#else
return SDL_uclibc_copysign(x, y);
#endif /* HAVE_COPYSIGN */
}
float
SDL_copysignf(float x, float y)
{
#if defined(HAVE_COPYSIGNF)
return copysignf(x, y);
#else
return (float)SDL_copysign((double)x, (double)y);
#endif
}
double
SDL_cos(double x)
{
@ -121,7 +187,7 @@ SDL_cos(double x)
return cos(x);
#else
return SDL_uclibc_cos(x);
#endif /* HAVE_COS */
#endif
}
float
@ -141,7 +207,17 @@ SDL_fabs(double x)
return fabs(x);
#else
return SDL_uclibc_fabs(x);
#endif /* HAVE_FABS */
#endif
}
float
SDL_fabsf(float x)
{
#if defined(HAVE_FABSF)
return fabsf(x);
#else
return (float)SDL_fabs((double)x);
#endif
}
double
@ -151,7 +227,37 @@ SDL_floor(double x)
return floor(x);
#else
return SDL_uclibc_floor(x);
#endif /* HAVE_FLOOR */
#endif
}
float
SDL_floorf(float x)
{
#if defined(HAVE_FLOORF)
return floorf(x);
#else
return (float)SDL_floor((double)x);
#endif
}
double
SDL_fmod(double x, double y)
{
#if defined(HAVE_FMOD)
return fmod(x, y);
#else
return SDL_uclibc_fmod(x, y);
#endif
}
float
SDL_fmodf(float x, float y)
{
#if defined(HAVE_FMODF)
return fmodf(x, y);
#else
return (float)SDL_fmod((double)x, (double)y);
#endif
}
double
@ -161,7 +267,37 @@ SDL_log(double x)
return log(x);
#else
return SDL_uclibc_log(x);
#endif /* HAVE_LOG */
#endif
}
float
SDL_logf(float x)
{
#if defined(HAVE_LOGF)
return logf(x);
#else
return (float)SDL_log((double)x);
#endif
}
double
SDL_log10(double x)
{
#if defined(HAVE_LOG10)
return log10(x);
#else
return SDL_uclibc_log10(x);
#endif
}
float
SDL_log10f(float x)
{
#if defined(HAVE_LOG10F)
return log10f(x);
#else
return (float)SDL_log10((double)x);
#endif
}
double
@ -171,7 +307,17 @@ SDL_pow(double x, double y)
return pow(x, y);
#else
return SDL_uclibc_pow(x, y);
#endif /* HAVE_POW */
#endif
}
float
SDL_powf(float x, float y)
{
#if defined(HAVE_POWF)
return powf(x, y);
#else
return (float)SDL_pow((double)x, (double)y);
#endif
}
double
@ -181,9 +327,23 @@ SDL_scalbn(double x, int n)
return scalbn(x, n);
#elif defined(HAVE__SCALB)
return _scalb(x, n);
#elif defined(HAVE_LIBC) && defined(HAVE_FLOAT_H) && (FLT_RADIX == 2)
/* from scalbn(3): If FLT_RADIX equals 2 (which is
* usual), then scalbn() is equivalent to ldexp(3). */
return ldexp(x, n);
#else
return SDL_uclibc_scalbn(x, n);
#endif /* HAVE_SCALBN */
#endif
}
float
SDL_scalbnf(float x, int n)
{
#if defined(HAVE_SCALBNF)
return scalbnf(x, n);
#else
return (float)SDL_scalbn((double)x, n);
#endif
}
double
@ -193,7 +353,7 @@ SDL_sin(double x)
return sin(x);
#else
return SDL_uclibc_sin(x);
#endif /* HAVE_SIN */
#endif
}
float
@ -203,7 +363,7 @@ SDL_sinf(float x)
return sinf(x);
#else
return (float)SDL_sin((double)x);
#endif /* HAVE_SINF */
#endif
}
double
@ -914,8 +1074,8 @@ _allshr()
{
/* *INDENT-OFF* */
__asm {
cmp cl,40h
jae RETZERO
cmp cl,3Fh
jae RETSIGN
cmp cl,20h
jae MORE32
shrd eax,edx,cl
@ -923,13 +1083,13 @@ _allshr()
ret
MORE32:
mov eax,edx
xor edx,edx
sar edx,1Fh
and cl,1Fh
sar eax,cl
ret
RETZERO:
xor eax,eax
xor edx,edx
RETSIGN:
sar edx,1Fh
mov eax,edx
ret
}
/* *INDENT-ON* */

View file

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -18,24 +18,20 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
#if defined(__clang_analyzer__)
#define SDL_DISABLE_ANALYZE_MACROS 1
#endif
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
#include "../SDL_internal.h"
/* This file contains portable string manipulation functions for SDL */
#include "SDL_stdinc.h"
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOLL) || !defined(HAVE_STRTOULL) || !defined(HAVE_STRTOD)
#define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F'))
#define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f'))
#endif
#define UTF8_IsLeadByte(c) ((c) >= 0xC0 && (c) <= 0xF4)
#define UTF8_IsTrailingByte(c) ((c) >= 0x80 && (c) <= 0xBF)
@ -82,7 +78,7 @@ SDL_ScanLong(const char *text, int radix, long *valuep)
value += v;
++text;
}
if (valuep) {
if (valuep && text > textstart) {
if (negative && value) {
*valuep = -value;
} else {
@ -118,7 +114,7 @@ SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
value += v;
++text;
}
if (valuep) {
if (valuep && text > textstart) {
*valuep = value;
}
return (text - textstart);
@ -150,7 +146,7 @@ SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep)
value += v;
++text;
}
if (valuep) {
if (valuep && text > textstart) {
*valuep = value;
}
return (text - textstart);
@ -187,7 +183,7 @@ SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep)
value += v;
++text;
}
if (valuep) {
if (valuep && text > textstart) {
if (negative && value) {
*valuep = -value;
} else {
@ -223,7 +219,7 @@ SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep)
value += v;
++text;
}
if (valuep) {
if (valuep && text > textstart) {
*valuep = value;
}
return (text - textstart);
@ -255,7 +251,7 @@ SDL_ScanFloat(const char *text, double *valuep)
++text;
}
}
if (valuep) {
if (valuep && text > textstart) {
if (negative && value) {
*valuep = -value;
} else {
@ -465,6 +461,22 @@ SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t max
#endif /* HAVE_WCSLCAT */
}
int
SDL_wcscmp(const wchar_t *str1, const wchar_t *str2)
{
#if defined(HAVE_WCSCMP)
return wcscmp(str1, str2);
#else
while (*str1 && *str2) {
if (*str1 != *str2)
break;
++str1;
++str2;
}
return (int)(*str1 - *str2);
#endif /* HAVE_WCSCMP */
}
size_t
SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
{
@ -481,7 +493,8 @@ SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
#endif /* HAVE_STRLCPY */
}
size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
size_t
SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
{
size_t src_bytes = SDL_strlen(src);
size_t bytes = SDL_min(src_bytes, dst_bytes - 1);
@ -513,6 +526,23 @@ size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size
return bytes;
}
size_t
SDL_utf8strlen(const char *str)
{
size_t retval = 0;
const char *p = str;
char ch;
while ((ch = *(p++))) {
/* if top two bits are 1 and 0, it's a continuation byte. */
if ((ch & 0xc0) != 0x80) {
retval++;
}
}
return retval;
}
size_t
SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
{
@ -531,16 +561,12 @@ SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
char *
SDL_strdup(const char *string)
{
#if defined(HAVE_STRDUP)
return strdup(string);
#else
size_t len = SDL_strlen(string) + 1;
char *newstr = SDL_malloc(len);
if (newstr) {
SDL_strlcpy(newstr, string, len);
SDL_memcpy(newstr, string, len);
}
return newstr;
#endif /* HAVE_STRDUP */
}
char *
@ -789,7 +815,7 @@ SDL_strtol(const char *string, char **endp, int base)
return strtol(string, endp, base);
#else
size_t len;
long value;
long value = 0;
if (!base) {
if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
@ -814,7 +840,7 @@ SDL_strtoul(const char *string, char **endp, int base)
return strtoul(string, endp, base);
#else
size_t len;
unsigned long value;
unsigned long value = 0;
if (!base) {
if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
@ -839,7 +865,7 @@ SDL_strtoll(const char *string, char **endp, int base)
return strtoll(string, endp, base);
#else
size_t len;
Sint64 value;
Sint64 value = 0;
if (!base) {
if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
@ -864,7 +890,7 @@ SDL_strtoull(const char *string, char **endp, int base)
return strtoull(string, endp, base);
#else
size_t len;
Uint64 value;
Uint64 value = 0;
if (!base) {
if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
@ -889,7 +915,7 @@ SDL_strtod(const char *string, char **endp)
return strtod(string, endp);
#else
size_t len;
double value;
double value = 0.0;
len = SDL_ScanFloat(string, &value);
if (endp) {
@ -911,7 +937,7 @@ SDL_strcmp(const char *str1, const char *str2)
++str1;
++str2;
}
return (int) ((unsigned char) *str1 - (unsigned char) *str2);
return (int)((unsigned char) *str1 - (unsigned char) *str2);
#endif /* HAVE_STRCMP */
}
@ -1011,6 +1037,10 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
{
int retval = 0;
if (!text || !*text) {
return -1;
}
while (*fmt) {
if (*fmt == ' ') {
while (SDL_isspace((unsigned char) *text)) {
@ -1030,6 +1060,7 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
DO_LONG,
DO_LONGLONG
} inttype = DO_INT;
size_t advance;
SDL_bool suppress = SDL_FALSE;
++fmt;
@ -1109,16 +1140,18 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
case 'd':
if (inttype == DO_LONGLONG) {
Sint64 value;
text += SDL_ScanLongLong(text, radix, &value);
if (!suppress) {
advance = SDL_ScanLongLong(text, radix, &value);
text += advance;
if (advance && !suppress) {
Sint64 *valuep = va_arg(ap, Sint64 *);
*valuep = value;
++retval;
}
} else {
long value;
text += SDL_ScanLong(text, radix, &value);
if (!suppress) {
advance = SDL_ScanLong(text, radix, &value);
text += advance;
if (advance && !suppress) {
switch (inttype) {
case DO_SHORT:
{
@ -1160,17 +1193,19 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
/* Fall through to unsigned handling */
case 'u':
if (inttype == DO_LONGLONG) {
Uint64 value;
text += SDL_ScanUnsignedLongLong(text, radix, &value);
if (!suppress) {
Uint64 value = 0;
advance = SDL_ScanUnsignedLongLong(text, radix, &value);
text += advance;
if (advance && !suppress) {
Uint64 *valuep = va_arg(ap, Uint64 *);
*valuep = value;
++retval;
}
} else {
unsigned long value;
text += SDL_ScanUnsignedLong(text, radix, &value);
if (!suppress) {
unsigned long value = 0;
advance = SDL_ScanUnsignedLong(text, radix, &value);
text += advance;
if (advance && !suppress) {
switch (inttype) {
case DO_SHORT:
{
@ -1201,9 +1236,10 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
break;
case 'p':
{
uintptr_t value;
text += SDL_ScanUintPtrT(text, 16, &value);
if (!suppress) {
uintptr_t value = 0;
advance = SDL_ScanUintPtrT(text, 16, &value);
text += advance;
if (advance && !suppress) {
void **valuep = va_arg(ap, void **);
*valuep = (void *) value;
++retval;
@ -1214,8 +1250,9 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
case 'f':
{
double value;
text += SDL_ScanFloat(text, &value);
if (!suppress) {
advance = SDL_ScanFloat(text, &value);
text += advance;
if (advance && !suppress) {
float *valuep = va_arg(ap, float *);
*valuep = (float) value;
++retval;
@ -1317,6 +1354,10 @@ SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *str
size_t length = 0;
size_t slen;
if (string == NULL) {
string = "(null)";
}
if (info && info->width && (size_t)info->width > SDL_strlen(string)) {
char fill = info->pad_zeroes ? '0' : ' ';
size_t width = info->width - SDL_strlen(string);
@ -1488,7 +1529,7 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
if (!fmt) {
fmt = "";
}
while (*fmt) {
while (*fmt && left > 1) {
if (*fmt == '%') {
SDL_bool done = SDL_FALSE;
size_t len = 0;
@ -1632,6 +1673,16 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
len = SDL_PrintFloat(text, left, &info, va_arg(ap, double));
done = SDL_TRUE;
break;
case 'S':
{
/* In practice this is used on Windows for WCHAR strings */
wchar_t *wide_arg = va_arg(ap, wchar_t *);
char *arg = SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(wide_arg), (SDL_wcslen(wide_arg)+1)*sizeof(*wide_arg));
len = SDL_PrintString(text, left, &info, arg);
SDL_free(arg);
done = SDL_TRUE;
}
break;
case 's':
len = SDL_PrintString(text, left, &info, va_arg(ap, char *));
done = SDL_TRUE;
@ -1650,12 +1701,8 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
left -= len;
}
} else {
if (left > 1) {
*text = *fmt;
--left;
}
++fmt;
++text;
*text++ = *fmt++;
--left;
}
}
if (left > 0) {