Fixed a bunch of 64-bit compatibility problems
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401460
This commit is contained in:
parent
e539f5ab85
commit
a9ee23bb9f
18 changed files with 117 additions and 48 deletions
|
@ -33,12 +33,12 @@
|
|||
/* Note this isn't thread-safe! */
|
||||
|
||||
static char *SDL_envmem = NULL; /* Ugh, memory leak */
|
||||
static DWORD SDL_envmemlen = 0;
|
||||
static size_t SDL_envmemlen = 0;
|
||||
|
||||
/* Put a variable of the form "name=value" into the environment */
|
||||
int SDL_putenv(const char *variable)
|
||||
{
|
||||
DWORD bufferlen;
|
||||
size_t bufferlen;
|
||||
char *value;
|
||||
const char *sep;
|
||||
|
||||
|
@ -67,7 +67,7 @@ int SDL_putenv(const char *variable)
|
|||
/* Retrieve a variable named "name" from the environment */
|
||||
char *SDL_getenv(const char *name)
|
||||
{
|
||||
DWORD bufferlen;
|
||||
size_t bufferlen;
|
||||
|
||||
bufferlen = GetEnvironmentVariable(name, SDL_envmem, SDL_envmemlen);
|
||||
if ( bufferlen == 0 ) {
|
||||
|
|
|
@ -1647,7 +1647,7 @@ struct malloc_chunk {
|
|||
typedef struct malloc_chunk mchunk;
|
||||
typedef struct malloc_chunk* mchunkptr;
|
||||
typedef struct malloc_chunk* sbinptr; /* The type of bins of chunks */
|
||||
typedef unsigned int bindex_t; /* Described below */
|
||||
typedef size_t bindex_t; /* Described below */
|
||||
typedef unsigned int binmap_t; /* Described below */
|
||||
typedef unsigned int flag_t; /* The type of various bit flag sets */
|
||||
|
||||
|
|
|
@ -263,7 +263,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;
|
||||
char *m1,*m2,*m3;
|
||||
{ char *a=first, *b=first+d, *c=first+2*d;
|
||||
#ifdef DEBUG_QSORT
|
||||
|
@ -414,7 +414,7 @@ void qsort(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 (((uintptr_t)base|size)&(WORD_BYTES-1))
|
||||
qsort_nonaligned(base,nmemb,size,compare);
|
||||
else if (size!=WORD_BYTES)
|
||||
qsort_aligned(base,nmemb,size,compare);
|
||||
|
|
|
@ -69,7 +69,7 @@ static size_t SDL_ScanLong(const char *text, int radix, long *valuep)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD)
|
||||
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
|
||||
static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
|
||||
{
|
||||
const char *textstart = text;
|
||||
|
@ -100,6 +100,37 @@ static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *v
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SSCANF
|
||||
static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t *valuep)
|
||||
{
|
||||
const char *textstart = text;
|
||||
uintptr_t value = 0;
|
||||
|
||||
if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) {
|
||||
text += 2;
|
||||
}
|
||||
for ( ; ; ) {
|
||||
int v;
|
||||
if ( SDL_isdigit(*text) ) {
|
||||
v = *text - '0';
|
||||
} else if ( radix == 16 && SDL_isupperhex(*text) ) {
|
||||
v = 10 + (*text - 'A');
|
||||
} else if ( radix == 16 && SDL_islowerhex(*text) ) {
|
||||
v = 10 + (*text - 'a');
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
value *= radix;
|
||||
value += v;
|
||||
++text;
|
||||
}
|
||||
if ( valuep ) {
|
||||
*valuep = value;
|
||||
}
|
||||
return (text - textstart);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SDL_HAS_64BIT_TYPE
|
||||
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL)
|
||||
static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 *valuep)
|
||||
|
@ -141,7 +172,7 @@ static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 *valuep)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SSCANF
|
||||
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL)
|
||||
static size_t SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 *valuep)
|
||||
{
|
||||
const char *textstart = text;
|
||||
|
@ -488,6 +519,20 @@ long SDL_strtol(const char *string, char **endp, int base)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRTOUL
|
||||
unsigned long SDL_strtoul(const char *string, char **endp, int base)
|
||||
{
|
||||
size_t len;
|
||||
unsigned long value;
|
||||
|
||||
len = SDL_ScanUnsignedLong(string, base ? base : 10, &value);
|
||||
if ( endp ) {
|
||||
*endp = (char *)string + len;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SDL_HAS_64BIT_TYPE
|
||||
|
||||
#ifndef HAVE__I64TOA
|
||||
|
@ -556,6 +601,20 @@ Sint64 SDL_strtoll(const char *string, char **endp, int base)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRTOULL
|
||||
Uint64 SDL_strtoull(const char *string, char **endp, int base)
|
||||
{
|
||||
size_t len;
|
||||
Uint64 value;
|
||||
|
||||
len = SDL_ScanUnsignedLongLong(string, base ? base : 10, &value);
|
||||
if ( endp ) {
|
||||
*endp = (char *)string + len;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_HAS_64BIT_TYPE */
|
||||
|
||||
#ifndef HAVE_STRTOD
|
||||
|
@ -817,8 +876,8 @@ int SDL_sscanf(const char *text, const char *fmt, ...)
|
|||
break;
|
||||
case 'p':
|
||||
{
|
||||
unsigned long value;
|
||||
text += SDL_ScanUnsignedLong(text, 16, &value);
|
||||
uintptr_t value;
|
||||
text += SDL_ScanUintPtrT(text, 16, &value);
|
||||
if ( ! suppress ) {
|
||||
void** valuep = va_arg(ap, void**);
|
||||
*valuep = (void*)value;
|
||||
|
@ -1003,7 +1062,7 @@ static size_t SDL_PrintString(char *text, const char *string, size_t maxlen)
|
|||
}
|
||||
return (text - textstart);
|
||||
}
|
||||
int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
|
||||
int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
|
||||
{
|
||||
char *textstart = text;
|
||||
if ( maxlen <= 0 ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue