src/stdlib/SDL_string.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 23 Jul 2013 12:44:14 -0700
changeset 7503 701f4a25df89
parent 7482 249d8ecbbb7d
child 7728 800313a3533d
permissions -rw-r--r--
Fixed SDL printf output for 0x%.8x
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5512
diff changeset
     2
  Simple DirectMedia Layer
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6766
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5512
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5512
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5512
diff changeset
     7
  arising from the use of this software.
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5512
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5512
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5512
diff changeset
    11
  freely, subject to the following restrictions:
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5512
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5512
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5512
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5512
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5512
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5512
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5512
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1379
diff changeset
    21
#include "SDL_config.h"
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
/* This file contains portable string manipulation functions for SDL */
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
1354
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1343
diff changeset
    25
#include "SDL_stdinc.h"
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
1354
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1343
diff changeset
    28
#define SDL_isupperhex(X)   (((X) >= 'A') && ((X) <= 'F'))
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1343
diff changeset
    29
#define SDL_islowerhex(X)   (((X) >= 'a') && ((X) <= 'f'))
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
4754
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    31
#define UTF8_IsLeadByte(c) ((c) >= 0xC0 && (c) <= 0xF4)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    32
#define UTF8_IsTrailingByte(c) ((c) >= 0x80 && (c) <= 0xBF)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    33
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6029
diff changeset
    34
static int UTF8_TrailingBytes(unsigned char c)
4754
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    35
{
6029
4a8bbaa52b9b Added SDL_GetScancodeFromName() and SDL_GetKeyFromName()
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    36
    if (c >= 0xC0 && c <= 0xDF)
4754
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    37
        return 1;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    38
    else if (c >= 0xE0 && c <= 0xEF)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    39
        return 2;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    40
    else if (c >= 0xF0 && c <= 0xF4)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    41
        return 3;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    42
    else
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    43
        return 0;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    44
}
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    45
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
    46
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOL)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
    47
static size_t
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
    48
SDL_ScanLong(const char *text, int radix, long *valuep)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
{
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
    const char *textstart = text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
    long value = 0;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
    SDL_bool negative = SDL_FALSE;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
    54
    if (*text == '-') {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
        negative = SDL_TRUE;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
        ++text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
    58
    if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
        text += 2;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
    61
    for (;;) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
        int v;
2092
8e761d6af583 Merged r2979:2980 from branches/SDL-1.2: unsigned char in ctype funcs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1916
diff changeset
    63
        if (SDL_isdigit((unsigned char) *text)) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
            v = *text - '0';
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
    65
        } else if (radix == 16 && SDL_isupperhex(*text)) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
            v = 10 + (*text - 'A');
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
    67
        } else if (radix == 16 && SDL_islowerhex(*text)) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
            v = 10 + (*text - 'a');
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
        } else {
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
            break;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
        }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
        value *= radix;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
        value += v;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
        ++text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
    76
    if (valuep) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
    77
        if (negative && value) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
            *valuep = -value;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
        } else {
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
            *valuep = value;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
        }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
    return (text - textstart);
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
#endif
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
    87
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
    88
static size_t
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
    89
SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
{
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    const char *textstart = text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
    unsigned long value = 0;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
    94
    if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
        text += 2;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
    97
    for (;;) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
        int v;
2092
8e761d6af583 Merged r2979:2980 from branches/SDL-1.2: unsigned char in ctype funcs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1916
diff changeset
    99
        if (SDL_isdigit((unsigned char) *text)) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
            v = *text - '0';
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   101
        } else if (radix == 16 && SDL_isupperhex(*text)) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
            v = 10 + (*text - 'A');
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   103
        } else if (radix == 16 && SDL_islowerhex(*text)) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
            v = 10 + (*text - 'a');
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
        } else {
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
            break;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
        }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
        value *= radix;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
        value += v;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
        ++text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   112
    if (valuep) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
        *valuep = value;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
    return (text - textstart);
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
#endif
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   119
#ifndef HAVE_SSCANF
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   120
static size_t
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   121
SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep)
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   122
{
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   123
    const char *textstart = text;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   124
    uintptr_t value = 0;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   125
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   126
    if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   127
        text += 2;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   128
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   129
    for (;;) {
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   130
        int v;
2092
8e761d6af583 Merged r2979:2980 from branches/SDL-1.2: unsigned char in ctype funcs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1916
diff changeset
   131
        if (SDL_isdigit((unsigned char) *text)) {
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   132
            v = *text - '0';
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   133
        } else if (radix == 16 && SDL_isupperhex(*text)) {
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   134
            v = 10 + (*text - 'A');
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   135
        } else if (radix == 16 && SDL_islowerhex(*text)) {
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   136
            v = 10 + (*text - 'a');
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   137
        } else {
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   138
            break;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   139
        }
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   140
        value *= radix;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   141
        value += v;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   142
        ++text;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   143
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   144
    if (valuep) {
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   145
        *valuep = value;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   146
    }
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   147
    return (text - textstart);
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   148
}
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   149
#endif
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   150
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   151
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   152
static size_t
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   153
SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
{
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
    const char *textstart = text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
    Sint64 value = 0;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
    SDL_bool negative = SDL_FALSE;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   159
    if (*text == '-') {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
        negative = SDL_TRUE;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
        ++text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   163
    if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
        text += 2;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   166
    for (;;) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
        int v;
2092
8e761d6af583 Merged r2979:2980 from branches/SDL-1.2: unsigned char in ctype funcs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1916
diff changeset
   168
        if (SDL_isdigit((unsigned char) *text)) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
            v = *text - '0';
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   170
        } else if (radix == 16 && SDL_isupperhex(*text)) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
            v = 10 + (*text - 'A');
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   172
        } else if (radix == 16 && SDL_islowerhex(*text)) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
            v = 10 + (*text - 'a');
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
        } else {
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
            break;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
        }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
        value *= radix;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
        value += v;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
        ++text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   181
    if (valuep) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   182
        if (negative && value) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
            *valuep = -value;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
        } else {
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
            *valuep = value;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
        }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
    return (text - textstart);
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
#endif
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   192
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   193
static size_t
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   194
SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
{
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
    const char *textstart = text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
    Uint64 value = 0;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   199
    if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   200
        text += 2;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   201
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   202
    for (;;) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
        int v;
2092
8e761d6af583 Merged r2979:2980 from branches/SDL-1.2: unsigned char in ctype funcs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1916
diff changeset
   204
        if (SDL_isdigit((unsigned char) *text)) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
            v = *text - '0';
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   206
        } else if (radix == 16 && SDL_isupperhex(*text)) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   207
            v = 10 + (*text - 'A');
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   208
        } else if (radix == 16 && SDL_islowerhex(*text)) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
            v = 10 + (*text - 'a');
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
        } else {
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
            break;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
        }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
        value *= radix;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
        value += v;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
        ++text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   217
    if (valuep) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
        *valuep = value;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
    return (text - textstart);
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
#endif
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   224
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   225
static size_t
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   226
SDL_ScanFloat(const char *text, double *valuep)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
{
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
    const char *textstart = text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
    unsigned long lvalue = 0;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
    double value = 0.0;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
    SDL_bool negative = SDL_FALSE;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   233
    if (*text == '-') {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
        negative = SDL_TRUE;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
        ++text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   236
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
    text += SDL_ScanUnsignedLong(text, 10, &lvalue);
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
    value += lvalue;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   239
    if (*text == '.') {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
        int mult = 10;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
        ++text;
2092
8e761d6af583 Merged r2979:2980 from branches/SDL-1.2: unsigned char in ctype funcs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1916
diff changeset
   242
        while (SDL_isdigit((unsigned char) *text)) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
            lvalue = *text - '0';
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   244
            value += (double) lvalue / mult;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
            mult *= 10;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
            ++text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
        }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   249
    if (valuep) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   250
        if (negative && value) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
            *valuep = -value;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
        } else {
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
            *valuep = value;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
        }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
    return (text - textstart);
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
#endif
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   260
void *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   261
SDL_memset(void *dst, int c, size_t len)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   263
#if defined(HAVE_MEMSET)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   264
    return memset(dst, c, len);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   265
#else
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   266
    size_t left = (len % 4);
5325
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   267
    Uint32 *dstp4;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   268
    Uint8 *dstp1;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   269
    Uint32 value4 = (c | (c << 8) | (c << 16) | (c << 24));
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   270
    Uint8 value1 = (Uint8) c;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   271
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   272
    dstp4 = (Uint32 *) dst;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   273
    len /= 4;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   274
    while (len--) {
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   275
        *dstp4++ = value4;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
    }
5325
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   277
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   278
    dstp1 = (Uint8 *) dstp4;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   279
    switch (left) {
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   280
    case 3:
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   281
        *dstp1++ = value1;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   282
    case 2:
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   283
        *dstp1++ = value1;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   284
    case 1:
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   285
        *dstp1++ = value1;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   286
    }
5325
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   287
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
    return dst;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   289
#endif /* HAVE_MEMSET */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
}
7003
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   291
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   292
void *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   293
SDL_memcpy(void *dst, const void *src, size_t len)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
{
7236
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   295
#ifdef __GNUC__
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   296
    /* Presumably this is well tuned for speed.
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   297
       On my machine this is twice as fast as the C code below.
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   298
     */
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   299
    return __builtin_memcpy(dst, src, len);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   300
#elif defined(HAVE_MEMCPY)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   301
    return memcpy(dst, src, len);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   302
#elif defined(HAVE_BCOPY)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   303
    bcopy(src, dst, len);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   304
    return dst;
7236
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   305
#else
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   306
    /* GCC 4.9.0 with -O3 will generate movaps instructions with the loop
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   307
       using Uint32* pointers, so we need to make sure the pointers are
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   308
       aligned before we loop using them.
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   309
     */
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   310
    if (((intptr_t)src & 0x3) || ((intptr_t)dst & 0x3)) {
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   311
        /* Do an unaligned byte copy */
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   312
        Uint8 *srcp1 = (Uint8 *)src;
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   313
        Uint8 *dstp1 = (Uint8 *)dst;
5325
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   314
7236
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   315
        while (len--) {
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   316
            *dstp1++ = *srcp1++;
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   317
        }
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   318
    } else {
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   319
        size_t left = (len % 4);
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   320
        Uint32 *srcp4, *dstp4;
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   321
        Uint8 *srcp1, *dstp1;
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   322
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   323
        srcp4 = (Uint32 *) src;
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   324
        dstp4 = (Uint32 *) dst;
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   325
        len /= 4;
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   326
        while (len--) {
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   327
            *dstp4++ = *srcp4++;
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   328
        }
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   329
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   330
        srcp1 = (Uint8 *) srcp4;
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   331
        dstp1 = (Uint8 *) dstp4;
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   332
        switch (left) {
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   333
        case 3:
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   334
            *dstp1++ = *srcp1++;
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   335
        case 2:
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   336
            *dstp1++ = *srcp1++;
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   337
        case 1:
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   338
            *dstp1++ = *srcp1++;
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   339
        }
5325
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   340
    }
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   341
    return dst;
7236
81ebe816a6da Fixed crash with movaps instruction in SDL_memcpy(), due to unaligned Uint32* cast and -O3 vectorization optimizations with gcc 4.9.0
Sam Lantinga <slouken@libsdl.org>
parents: 7217
diff changeset
   342
#endif /* __GNUC__ */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   343
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   345
void *
5325
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   346
SDL_memmove(void *dst, const void *src, size_t len)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   348
#if defined(HAVE_MEMMOVE)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   349
    return memmove(dst, src, len);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   350
#else
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   351
    char *srcp = (char *) src;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   352
    char *dstp = (char *) dst;
5325
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   353
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   354
    if (src < dst) {
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   355
        srcp += len - 1;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   356
        dstp += len - 1;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   357
        while (len--) {
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   358
            *dstp-- = *srcp--;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   359
        }
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   360
    } else {
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   361
        while (len--) {
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   362
            *dstp++ = *srcp++;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   363
        }
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   364
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   365
    return dst;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   366
#endif /* HAVE_MEMMOVE */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   367
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   368
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   369
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   370
SDL_memcmp(const void *s1, const void *s2, size_t len)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   372
#if defined(HAVE_MEMCMP)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   373
    return memcmp(s1, s2, len);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   374
#else
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   375
    char *s1p = (char *) s1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   376
    char *s2p = (char *) s2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   377
    while (len--) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   378
        if (*s1p != *s2p) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   379
            return (*s1p - *s2p);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   380
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   381
        ++s1p;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   382
        ++s2p;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   383
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   384
    return 0;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   385
#endif /* HAVE_MEMCMP */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   386
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   387
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   388
size_t
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   389
SDL_strlen(const char *string)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   390
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   391
#if defined(HAVE_STRLEN)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   392
    return strlen(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   393
#else
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   394
    size_t len = 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   395
    while (*string++) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   396
        ++len;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   397
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   398
    return len;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   399
#endif /* HAVE_STRLEN */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   401
1901
f1828a500391 Removed libc dependency on Windows again, to fix building with Visual C++ 2005 Express Edition.
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   402
size_t
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   403
SDL_wcslen(const wchar_t * string)
1901
f1828a500391 Removed libc dependency on Windows again, to fix building with Visual C++ 2005 Express Edition.
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   404
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   405
#if defined(HAVE_WCSLEN)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   406
    return wcslen(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   407
#else
1901
f1828a500391 Removed libc dependency on Windows again, to fix building with Visual C++ 2005 Express Edition.
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   408
    size_t len = 0;
f1828a500391 Removed libc dependency on Windows again, to fix building with Visual C++ 2005 Express Edition.
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   409
    while (*string++) {
f1828a500391 Removed libc dependency on Windows again, to fix building with Visual C++ 2005 Express Edition.
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   410
        ++len;
f1828a500391 Removed libc dependency on Windows again, to fix building with Visual C++ 2005 Express Edition.
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   411
    }
f1828a500391 Removed libc dependency on Windows again, to fix building with Visual C++ 2005 Express Edition.
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   412
    return len;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   413
#endif /* HAVE_WCSLEN */
1901
f1828a500391 Removed libc dependency on Windows again, to fix building with Visual C++ 2005 Express Edition.
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   414
}
f1828a500391 Removed libc dependency on Windows again, to fix building with Visual C++ 2005 Express Edition.
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   415
4758
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   416
size_t
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   417
SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   418
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   419
#if defined(HAVE_WCSLCPY)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   420
    return wcslcpy(dst, src, maxlen);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   421
#else
4758
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   422
    size_t srclen = SDL_wcslen(src);
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   423
    if (maxlen > 0) {
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   424
        size_t len = SDL_min(srclen, maxlen - 1);
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   425
        SDL_memcpy(dst, src, len * sizeof(wchar_t));
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   426
        dst[len] = '\0';
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   427
    }
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   428
    return srclen;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   429
#endif /* HAVE_WCSLCPY */
4758
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   430
}
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   431
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   432
size_t
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   433
SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   434
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   435
#if defined(HAVE_WCSLCAT)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   436
    return wcslcat(dst, src, maxlen);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   437
#else
4758
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   438
    size_t dstlen = SDL_wcslen(dst);
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   439
    size_t srclen = SDL_wcslen(src);
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   440
    if (dstlen < maxlen) {
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   441
        SDL_wcslcpy(dst + dstlen, src, maxlen - dstlen);
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   442
    }
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   443
    return dstlen + srclen;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   444
#endif /* HAVE_WCSLCAT */
4758
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   445
}
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   446
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   447
size_t
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   448
SDL_strlcpy(char *dst, const char *src, size_t maxlen)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   449
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   450
#if defined(HAVE_STRLCPY)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   451
    return strlcpy(dst, src, maxlen);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   452
#else
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   453
    size_t srclen = SDL_strlen(src);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   454
    if (maxlen > 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   455
        size_t len = SDL_min(srclen, maxlen - 1);
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   456
        SDL_memcpy(dst, src, len);
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   457
        dst[len] = '\0';
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   458
    }
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   459
    return srclen;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   460
#endif /* HAVE_STRLCPY */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   461
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   462
4754
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   463
size_t SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   464
{
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   465
    size_t src_bytes = SDL_strlen(src);
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   466
    size_t bytes = SDL_min(src_bytes, dst_bytes - 1);
5076
8bf5781fc582 Fixed size_t warnings on 64-bit build
Sam Lantinga <slouken@libsdl.org>
parents: 4758
diff changeset
   467
    size_t i = 0;
4754
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   468
    char trailing_bytes = 0;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   469
    if (bytes)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   470
    {
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   471
        unsigned char c = (unsigned char)src[bytes - 1];
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   472
        if (UTF8_IsLeadByte(c))
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   473
            --bytes;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   474
        else if (UTF8_IsTrailingByte(c))
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   475
        {
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   476
            for (i = bytes - 1; i != 0; --i)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   477
            {
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   478
                c = (unsigned char)src[i];
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   479
                trailing_bytes = UTF8_TrailingBytes(c);
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   480
                if (trailing_bytes)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   481
                {
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   482
                    if (bytes - i != trailing_bytes + 1)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   483
                        bytes = i;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   484
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   485
                    break;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   486
                }
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   487
            }
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   488
        }
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   489
        SDL_memcpy(dst, src, bytes);
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   490
    }
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   491
    dst[bytes] = '\0';
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   492
    return bytes;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   493
}
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   494
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   495
size_t
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   496
SDL_strlcat(char *dst, const char *src, size_t maxlen)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   497
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   498
#if defined(HAVE_STRLCAT)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   499
    return strlcat(dst, src, maxlen);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   500
#else
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   501
    size_t dstlen = SDL_strlen(dst);
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   502
    size_t srclen = SDL_strlen(src);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   503
    if (dstlen < maxlen) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   504
        SDL_strlcpy(dst + dstlen, src, maxlen - dstlen);
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   505
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   506
    return dstlen + srclen;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   507
#endif /* HAVE_STRLCAT */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   508
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   509
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   510
char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   511
SDL_strdup(const char *string)
1341
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   512
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   513
#if defined(HAVE_STRDUP)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   514
    return strdup(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   515
#else
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   516
    size_t len = SDL_strlen(string) + 1;
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   517
    char *newstr = SDL_malloc(len);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   518
    if (newstr) {
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   519
        SDL_strlcpy(newstr, string, len);
1341
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   520
    }
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   521
    return newstr;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   522
#endif /* HAVE_STRDUP */
1341
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   523
}
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   524
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   525
char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   526
SDL_strrev(char *string)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   527
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   528
#if defined(HAVE__STRREV)
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   529
    return _strrev(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   530
#else
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   531
    size_t len = SDL_strlen(string);
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   532
    char *a = &string[0];
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   533
    char *b = &string[len - 1];
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   534
    len /= 2;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   535
    while (len--) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   536
        char c = *a;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   537
        *a++ = *b;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   538
        *b-- = c;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   539
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   540
    return string;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   541
#endif /* HAVE__STRREV */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   542
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   543
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   544
char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   545
SDL_strupr(char *string)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   546
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   547
#if defined(HAVE__STRUPR)
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   548
    return _strupr(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   549
#else
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   550
    char *bufp = string;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   551
    while (*bufp) {
2092
8e761d6af583 Merged r2979:2980 from branches/SDL-1.2: unsigned char in ctype funcs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1916
diff changeset
   552
        *bufp = SDL_toupper((unsigned char) *bufp);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   553
        ++bufp;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   554
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   555
    return string;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   556
#endif /* HAVE__STRUPR */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   557
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   558
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   559
char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   560
SDL_strlwr(char *string)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   561
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   562
#if defined(HAVE__STRLWR)
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   563
    return _strlwr(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   564
#else
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   565
    char *bufp = string;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   566
    while (*bufp) {
2092
8e761d6af583 Merged r2979:2980 from branches/SDL-1.2: unsigned char in ctype funcs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1916
diff changeset
   567
        *bufp = SDL_tolower((unsigned char) *bufp);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   568
        ++bufp;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   569
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   570
    return string;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   571
#endif /* HAVE__STRLWR */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   572
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   573
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   574
char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   575
SDL_strchr(const char *string, int c)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   576
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   577
#ifdef HAVE_STRCHR
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   578
    return SDL_const_cast(char*,strchr(string, c));
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   579
#elif defined(HAVE_INDEX)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   580
    return SDL_const_cast(char*,index(string, c));
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   581
#else
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   582
    while (*string) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   583
        if (*string == c) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   584
            return (char *) string;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   585
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   586
        ++string;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   587
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   588
    return NULL;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   589
#endif /* HAVE_STRCHR */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   590
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   591
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   592
char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   593
SDL_strrchr(const char *string, int c)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   594
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   595
#ifdef HAVE_STRRCHR
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   596
    return SDL_const_cast(char*,strrchr(string, c));
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   597
#elif defined(HAVE_RINDEX)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   598
    return SDL_const_cast(char*,rindex(string, c));
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   599
#else
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   600
    const char *bufp = string + SDL_strlen(string) - 1;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   601
    while (bufp >= string) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   602
        if (*bufp == c) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   603
            return (char *) bufp;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   604
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   605
        --bufp;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   606
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   607
    return NULL;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   608
#endif /* HAVE_STRRCHR */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   609
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   610
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   611
char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   612
SDL_strstr(const char *haystack, const char *needle)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   613
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   614
#if defined(HAVE_STRSTR)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   615
    return SDL_const_cast(char*,strstr(haystack, needle));
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   616
#else
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   617
    size_t length = SDL_strlen(needle);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   618
    while (*haystack) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   619
        if (SDL_strncmp(haystack, needle, length) == 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   620
            return (char *) haystack;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   621
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   622
        ++haystack;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   623
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   624
    return NULL;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   625
#endif /* HAVE_STRSTR */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   626
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   627
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   628
#if !defined(HAVE__LTOA) || !defined(HAVE__I64TOA) || \
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   629
    !defined(HAVE__ULTOA) || !defined(HAVE__UI64TOA)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   630
static const char ntoa_table[] = {
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   631
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   632
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   633
    'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   634
    'U', 'V', 'W', 'X', 'Y', 'Z'
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   635
};
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   636
#endif /* ntoa() conversion table */
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   637
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   638
char *
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   639
SDL_itoa(int value, char *string, int radix)
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   640
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   641
#ifdef HAVE_ITOA
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   642
    return itoa(value, string, radix);
7003
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   643
#else
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   644
    return SDL_ltoa((long)value, string, radix);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   645
#endif /* HAVE_ITOA */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   646
}
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   647
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   648
char *
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   649
SDL_uitoa(unsigned int value, char *string, int radix)
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   650
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   651
#ifdef HAVE__UITOA
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   652
    return _uitoa(value, string, radix);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   653
#else
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   654
    return SDL_ultoa((unsigned long)value, string, radix);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   655
#endif /* HAVE__UITOA */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   656
}
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   657
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   658
char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   659
SDL_ltoa(long value, char *string, int radix)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   660
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   661
#if defined(HAVE__LTOA)
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   662
    return _ltoa(value, string, radix);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   663
#else
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   664
    char *bufp = string;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   665
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   666
    if (value < 0) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   667
        *bufp++ = '-';
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   668
        value = -value;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   669
    }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   670
    if (value) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   671
        while (value > 0) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   672
            *bufp++ = ntoa_table[value % radix];
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   673
            value /= radix;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   674
        }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   675
    } else {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   676
        *bufp++ = '0';
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   677
    }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   678
    *bufp = '\0';
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   679
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   680
    /* The numbers went into the string backwards. :) */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   681
    if (*string == '-') {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   682
        SDL_strrev(string + 1);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   683
    } else {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   684
        SDL_strrev(string);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   685
    }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   686
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   687
    return string;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   688
#endif /* HAVE__LTOA */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   689
}
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   690
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   691
char *
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   692
SDL_ultoa(unsigned long value, char *string, int radix)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   693
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   694
#if defined(HAVE__ULTOA)
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   695
    return _ultoa(value, string, radix);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   696
#else
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   697
    char *bufp = string;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   698
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   699
    if (value) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   700
        while (value > 0) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   701
            *bufp++ = ntoa_table[value % radix];
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   702
            value /= radix;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   703
        }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   704
    } else {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   705
        *bufp++ = '0';
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   706
    }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   707
    *bufp = '\0';
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   708
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   709
    /* The numbers went into the string backwards. :) */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   710
    SDL_strrev(string);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   711
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   712
    return string;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   713
#endif /* HAVE__ULTOA */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   714
}
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   715
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   716
char *
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   717
SDL_lltoa(Sint64 value, char *string, int radix)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   718
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   719
#if defined(HAVE__I64TOA)
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   720
    return _i64toa(value, string, radix);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   721
#else
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   722
    char *bufp = string;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   723
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   724
    if (value < 0) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   725
        *bufp++ = '-';
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   726
        value = -value;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   727
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   728
    if (value) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   729
        while (value > 0) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   730
            *bufp++ = ntoa_table[value % radix];
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   731
            value /= radix;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   732
        }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   733
    } else {
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   734
        *bufp++ = '0';
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   735
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   736
    *bufp = '\0';
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   737
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   738
    /* The numbers went into the string backwards. :) */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   739
    if (*string == '-') {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   740
        SDL_strrev(string + 1);
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   741
    } else {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   742
        SDL_strrev(string);
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   743
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   744
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   745
    return string;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   746
#endif /* HAVE__I64TOA */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   747
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   748
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   749
char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   750
SDL_ulltoa(Uint64 value, char *string, int radix)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   751
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   752
#if defined(HAVE__UI64TOA)
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   753
    return _ui64toa(value, string, radix);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   754
#else
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   755
    char *bufp = string;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   756
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   757
    if (value) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   758
        while (value > 0) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   759
            *bufp++ = ntoa_table[value % radix];
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   760
            value /= radix;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   761
        }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   762
    } else {
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   763
        *bufp++ = '0';
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   764
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   765
    *bufp = '\0';
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   766
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   767
    /* The numbers went into the string backwards. :) */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   768
    SDL_strrev(string);
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   769
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   770
    return string;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   771
#endif /* HAVE__UI64TOA */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   772
}
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   773
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   774
int SDL_atoi(const char *string)
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   775
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   776
#ifdef HAVE_ATOI
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   777
    return atoi(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   778
#else
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   779
    return SDL_strtol(string, NULL, 0);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   780
#endif /* HAVE_ATOI */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   781
}
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   782
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   783
double SDL_atof(const char *string)
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   784
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   785
#ifdef HAVE_ATOF
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   786
    return (double) atof(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   787
#else
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   788
    return SDL_strtod(string, NULL);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   789
#endif /* HAVE_ATOF */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   790
}
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   791
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   792
long
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   793
SDL_strtol(const char *string, char **endp, int base)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   794
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   795
#if defined(HAVE_STRTOL)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   796
    return strtol(string, endp, base);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   797
#else
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   798
    size_t len;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   799
    long value;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   800
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   801
    if (!base) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   802
        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   803
            base = 16;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   804
        } else {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   805
            base = 10;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   806
        }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   807
    }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   808
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   809
    len = SDL_ScanLong(string, base, &value);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   810
    if (endp) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   811
        *endp = (char *) string + len;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   812
    }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   813
    return value;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   814
#endif /* HAVE_STRTOL */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   815
}
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   816
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   817
unsigned long
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   818
SDL_strtoul(const char *string, char **endp, int base)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   819
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   820
#if defined(HAVE_STRTOUL)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   821
    return strtoul(string, endp, base);
7003
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   822
#else
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   823
    size_t len;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   824
    unsigned long value;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   825
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   826
    if (!base) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   827
        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   828
            base = 16;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   829
        } else {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   830
            base = 10;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   831
        }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   832
    }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   833
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   834
    len = SDL_ScanUnsignedLong(string, base, &value);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   835
    if (endp) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   836
        *endp = (char *) string + len;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   837
    }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   838
    return value;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   839
#endif /* HAVE_STRTOUL */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   840
}
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   841
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   842
Sint64
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   843
SDL_strtoll(const char *string, char **endp, int base)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   844
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   845
#if defined(HAVE_STRTOLL)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   846
    return strtoll(string, endp, base);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   847
#else
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   848
    size_t len;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   849
    Sint64 value;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   850
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   851
    if (!base) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   852
        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
1867
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   853
            base = 16;
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   854
        } else {
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   855
            base = 10;
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   856
        }
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   857
    }
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   858
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   859
    len = SDL_ScanLongLong(string, base, &value);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   860
    if (endp) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   861
        *endp = (char *) string + len;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   862
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   863
    return value;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   864
#endif /* HAVE_STRTOLL */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   865
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   866
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   867
Uint64
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   868
SDL_strtoull(const char *string, char **endp, int base)
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   869
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   870
#if defined(HAVE_STRTOULL)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   871
    return strtoull(string, endp, base);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   872
#else
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   873
    size_t len;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   874
    Uint64 value;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   875
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   876
    if (!base) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   877
        if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
1867
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   878
            base = 16;
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   879
        } else {
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   880
            base = 10;
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   881
        }
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   882
    }
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   883
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   884
    len = SDL_ScanUnsignedLongLong(string, base, &value);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   885
    if (endp) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   886
        *endp = (char *) string + len;
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   887
    }
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   888
    return value;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   889
#endif /* HAVE_STRTOULL */
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   890
}
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   891
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   892
double
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   893
SDL_strtod(const char *string, char **endp)
1341
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   894
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   895
#if defined(HAVE_STRTOD)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   896
    return strtod(string, endp);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   897
#else
1341
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   898
    size_t len;
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   899
    double value;
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   900
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   901
    len = SDL_ScanFloat(string, &value);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   902
    if (endp) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   903
        *endp = (char *) string + len;
1341
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   904
    }
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   905
    return value;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   906
#endif /* HAVE_STRTOD */
1341
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   907
}
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   908
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   909
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   910
SDL_strcmp(const char *str1, const char *str2)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   911
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   912
#if defined(HAVE_STRCMP)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   913
    return strcmp(str1, str2);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   914
#else
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   915
    while (*str1 && *str2) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   916
        if (*str1 != *str2)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   917
            break;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   918
        ++str1;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   919
        ++str2;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   920
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   921
    return (int) ((unsigned char) *str1 - (unsigned char) *str2);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   922
#endif /* HAVE_STRCMP */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   923
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   924
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   925
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   926
SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   927
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   928
#if defined(HAVE_STRNCMP)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   929
    return strncmp(str1, str2, maxlen);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   930
#else
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   931
    while (*str1 && *str2 && maxlen) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   932
        if (*str1 != *str2)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   933
            break;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   934
        ++str1;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   935
        ++str2;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   936
        --maxlen;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   937
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   938
    if (!maxlen) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   939
        return 0;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   940
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   941
    return (int) ((unsigned char) *str1 - (unsigned char) *str2);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   942
#endif /* HAVE_STRNCMP */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   943
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   944
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   945
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   946
SDL_strcasecmp(const char *str1, const char *str2)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   947
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   948
#ifdef HAVE_STRCASECMP
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   949
    return strcasecmp(str1, str2);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   950
#elif defined(HAVE__STRICMP)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   951
    return _stricmp(str1, str2);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   952
#else
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   953
    char a = 0;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   954
    char b = 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   955
    while (*str1 && *str2) {
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   956
        a = SDL_toupper((unsigned char) *str1);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   957
        b = SDL_toupper((unsigned char) *str2);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   958
        if (a != b)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   959
            break;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   960
        ++str1;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   961
        ++str2;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   962
    }
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   963
    a = SDL_toupper(*str1);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   964
    b = SDL_toupper(*str2);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   965
    return (int) ((unsigned char) a - (unsigned char) b);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   966
#endif /* HAVE_STRCASECMP */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   967
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   968
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   969
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   970
SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
1501
73dc5d39bbf8 Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   971
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   972
#ifdef HAVE_STRNCASECMP
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   973
    return strncasecmp(str1, str2, maxlen);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   974
#elif defined(HAVE__STRNICMP)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   975
    return _strnicmp(str1, str2, maxlen);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   976
#else
1501
73dc5d39bbf8 Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   977
    char a = 0;
73dc5d39bbf8 Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   978
    char b = 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   979
    while (*str1 && *str2 && maxlen) {
2092
8e761d6af583 Merged r2979:2980 from branches/SDL-1.2: unsigned char in ctype funcs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1916
diff changeset
   980
        a = SDL_tolower((unsigned char) *str1);
8e761d6af583 Merged r2979:2980 from branches/SDL-1.2: unsigned char in ctype funcs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1916
diff changeset
   981
        b = SDL_tolower((unsigned char) *str2);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
   982
        if (a != b)
1501
73dc5d39bbf8 Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   983
            break;
73dc5d39bbf8 Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   984
        ++str1;
73dc5d39bbf8 Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   985
        ++str2;
73dc5d39bbf8 Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   986
        --maxlen;
73dc5d39bbf8 Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   987
    }
6766
2b8a507c278b Fixed bug in SDL_strcasecmp() with strings of different sizes
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   988
    if (maxlen == 0) {
2b8a507c278b Fixed bug in SDL_strcasecmp() with strings of different sizes
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   989
        return 0;
2b8a507c278b Fixed bug in SDL_strcasecmp() with strings of different sizes
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   990
    } else {
2b8a507c278b Fixed bug in SDL_strcasecmp() with strings of different sizes
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   991
        a = SDL_tolower((unsigned char) *str1);
2b8a507c278b Fixed bug in SDL_strcasecmp() with strings of different sizes
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   992
        b = SDL_tolower((unsigned char) *str2);
2b8a507c278b Fixed bug in SDL_strcasecmp() with strings of different sizes
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   993
        return (int) ((unsigned char) a - (unsigned char) b);
2b8a507c278b Fixed bug in SDL_strcasecmp() with strings of different sizes
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   994
    }
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   995
#endif /* HAVE_STRNCASECMP */
1501
73dc5d39bbf8 Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   996
}
73dc5d39bbf8 Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   997
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   998
#ifdef HAVE_SSCANF
7003
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   999
int
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
  1000
SDL_sscanf(const char *text, const char *fmt, ...)
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
  1001
{
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
  1002
    int rc;
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
  1003
    va_list ap;
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
  1004
    va_start(ap, fmt);
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
  1005
    rc = vsscanf(text, fmt, ap);
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
  1006
    va_end(ap);
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
  1007
    return rc;
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
  1008
}
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
  1009
#else
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1010
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1011
SDL_sscanf(const char *text, const char *fmt, ...)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1012
{
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1013
    va_list ap;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1014
    int retval = 0;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1015
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1016
    va_start(ap, fmt);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1017
    while (*fmt) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1018
        if (*fmt == ' ') {
2092
8e761d6af583 Merged r2979:2980 from branches/SDL-1.2: unsigned char in ctype funcs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1916
diff changeset
  1019
            while (SDL_isspace((unsigned char) *text)) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1020
                ++text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1021
            }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1022
            ++fmt;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1023
            continue;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1024
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1025
        if (*fmt == '%') {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1026
            SDL_bool done = SDL_FALSE;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1027
            long count = 0;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1028
            int radix = 10;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1029
            enum
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1030
            {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1031
                DO_SHORT,
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1032
                DO_INT,
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1033
                DO_LONG,
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1034
                DO_LONGLONG
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1035
            } inttype = DO_INT;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1036
            SDL_bool suppress = SDL_FALSE;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1037
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1038
            ++fmt;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1039
            if (*fmt == '%') {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1040
                if (*text == '%') {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1041
                    ++text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1042
                    ++fmt;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1043
                    continue;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1044
                }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1045
                break;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1046
            }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1047
            if (*fmt == '*') {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1048
                suppress = SDL_TRUE;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1049
                ++fmt;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1050
            }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1051
            fmt += SDL_ScanLong(fmt, 10, &count);
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1052
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1053
            if (*fmt == 'c') {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1054
                if (!count) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1055
                    count = 1;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1056
                }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1057
                if (suppress) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1058
                    while (count--) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1059
                        ++text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1060
                    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1061
                } else {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1062
                    char *valuep = va_arg(ap, char *);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1867
diff changeset
  1063
                    while (count--) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1064
                        *valuep++ = *text++;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1065
                    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1066
                    ++retval;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1067
                }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1068
                continue;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1069
            }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1070
2092
8e761d6af583 Merged r2979:2980 from branches/SDL-1.2: unsigned char in ctype funcs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1916
diff changeset
  1071
            while (SDL_isspace((unsigned char) *text)) {
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1072
                ++text;
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1073
            }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1074
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1075
            /* FIXME: implement more of the format specifiers */
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1076
            while (!done) {
1895