src/stdlib/SDL_string.c
author Ryan C. Gordon <icculus@icculus.org>
Thu, 09 Apr 2015 22:33:39 -0400
branchiOS-improvements
changeset 9542 618662dc9e82
parent 9306 817656bd36ec
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Closing the iOS-improvements branch.
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
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
     3
  Copyright (C) 1997-2014 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
*/
9306
817656bd36ec Clang static analysis builds should use C runtime directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 8888
diff changeset
    21
817656bd36ec Clang static analysis builds should use C runtime directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 8888
diff changeset
    22
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
817656bd36ec Clang static analysis builds should use C runtime directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 8888
diff changeset
    23
#define SDL_DISABLE_ANALYZE_MACROS 1
817656bd36ec Clang static analysis builds should use C runtime directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 8888
diff changeset
    24
#endif
817656bd36ec Clang static analysis builds should use C runtime directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 8888
diff changeset
    25
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 8092
diff changeset
    26
#include "../SDL_internal.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
    27
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
/* 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
    29
1354
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1343
diff changeset
    30
#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
    31
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
1354
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1343
diff changeset
    33
#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
    34
#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
    35
4754
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    36
#define UTF8_IsLeadByte(c) ((c) >= 0xC0 && (c) <= 0xF4)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    37
#define UTF8_IsTrailingByte(c) ((c) >= 0x80 && (c) <= 0xBF)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    38
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 6029
diff changeset
    39
static int UTF8_TrailingBytes(unsigned char c)
4754
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    40
{
6029
4a8bbaa52b9b Added SDL_GetScancodeFromName() and SDL_GetKeyFromName()
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    41
    if (c >= 0xC0 && c <= 0xDF)
4754
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    42
        return 1;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    43
    else if (c >= 0xE0 && c <= 0xEF)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    44
        return 2;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    45
    else if (c >= 0xF0 && c <= 0xF4)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    46
        return 3;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    47
    else
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    48
        return 0;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    49
}
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
    50
8089
de8b6fdf6544 Added SDL_vsscanf().
Ryan C. Gordon <icculus@icculus.org>
parents: 8059
diff changeset
    51
#if !defined(HAVE_VSSCANF) || !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
    52
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
    53
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
    54
{
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
    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
    56
    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
    57
    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
    58
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
    59
    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
    60
        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
    61
        ++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
    62
    }
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
    63
    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
    64
        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
    65
    }
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
    66
    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
    67
        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
    68
        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
    69
            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
    70
        } 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
    71
            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
    72
        } 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
    73
            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
    74
        } 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
    75
            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
    76
        }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
        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
    78
        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
    79
        ++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
    80
    }
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
    81
    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
    82
        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
    83
            *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
    84
        } 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
    85
            *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
    86
        }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
    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
    89
}
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
#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
    91
8089
de8b6fdf6544 Added SDL_vsscanf().
Ryan C. Gordon <icculus@icculus.org>
parents: 8059
diff changeset
    92
#if !defined(HAVE_VSSCANF) || !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
    93
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
    94
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
    95
{
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
    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
    97
    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
    98
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
    99
    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
   100
        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
   101
    }
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
   102
    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
   103
        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
   104
        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
   105
            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
   106
        } 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
   107
            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
   108
        } 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
   109
            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
   110
        } 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
   111
            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
   112
        }
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
        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
   114
        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
   115
        ++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
   116
    }
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
   117
    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
   118
        *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
   119
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
    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
   121
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
#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
   123
8089
de8b6fdf6544 Added SDL_vsscanf().
Ryan C. Gordon <icculus@icculus.org>
parents: 8059
diff changeset
   124
#ifndef HAVE_VSSCANF
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
   125
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
   126
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
   127
{
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   128
    const char *textstart = text;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   129
    uintptr_t value = 0;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   130
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
   131
    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
   132
        text += 2;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   133
    }
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
   134
    for (;;) {
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   135
        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
   136
        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
   137
            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
   138
        } 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
   139
            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
   140
        } 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
   141
            v = 10 + (*text - 'a');
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   142
        } else {
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   143
            break;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   144
        }
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   145
        value *= radix;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   146
        value += v;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   147
        ++text;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   148
    }
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
   149
    if (valuep) {
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   150
        *valuep = value;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   151
    }
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   152
    return (text - textstart);
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   153
}
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   154
#endif
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   155
8089
de8b6fdf6544 Added SDL_vsscanf().
Ryan C. Gordon <icculus@icculus.org>
parents: 8059
diff changeset
   156
#if !defined(HAVE_VSSCANF) || !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
   157
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
   158
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
   159
{
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
    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
   161
    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
   162
    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
   163
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
   164
    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
   165
        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
   166
        ++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
   167
    }
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
   168
    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
   169
        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
   170
    }
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
   171
    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
   172
        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
   173
        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
   174
            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
   175
        } 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
   176
            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
   177
        } 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
   178
            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
   179
        } 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
   180
            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
   181
        }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
        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
   183
        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
   184
        ++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
   185
    }
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
   186
    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
   187
        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
   188
            *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
   189
        } 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
   190
            *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
   191
        }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
    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
   194
}
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
#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
   196
8089
de8b6fdf6544 Added SDL_vsscanf().
Ryan C. Gordon <icculus@icculus.org>
parents: 8059
diff changeset
   197
#if !defined(HAVE_VSSCANF) || !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
   198
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
   199
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
   200
{
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
    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
   202
    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
   203
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
   204
    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
   205
        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
   206
    }
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
   207
    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
   208
        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
   209
        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
   210
            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
   211
        } 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
   212
            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
   213
        } 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
   214
            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
   215
        } 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
   216
            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
   217
        }
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
        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
   219
        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
   220
        ++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
   221
    }
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
   222
    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
   223
        *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
   224
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
    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
   226
}
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
#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
   228
8089
de8b6fdf6544 Added SDL_vsscanf().
Ryan C. Gordon <icculus@icculus.org>
parents: 8059
diff changeset
   229
#if !defined(HAVE_VSSCANF) || !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
   230
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
   231
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
   232
{
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
    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
   234
    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
   235
    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
   236
    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
   237
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
   238
    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
   239
        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
   240
        ++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
   241
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   242
    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
   243
    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
   244
    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
   245
        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
   246
        ++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
   247
        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
   248
            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
   249
            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
   250
            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
   251
            ++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
   252
        }
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
    }
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
   254
    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
   255
        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
   256
            *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
   257
        } 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
   258
            *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
   259
        }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
    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
   262
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
#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
   264
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
   265
void *
8820
0e935d5b193a Added annotations to help code analysis tools
Sam Lantinga <slouken@libsdl.org>
parents: 8779
diff changeset
   266
SDL_memset(SDL_OUT_BYTECAP(len) 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
   267
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   268
#if defined(HAVE_MEMSET)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   269
    return memset(dst, c, len);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   270
#else
8779
d21a3ff2b0d2 Align pointer in SDL_memset before doing Uint32 loop
Yuri Kunde Schlesner <yuriks@yuriks.net>
parents: 8149
diff changeset
   271
    size_t left;
5325
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   272
    Uint32 *dstp4;
8779
d21a3ff2b0d2 Align pointer in SDL_memset before doing Uint32 loop
Yuri Kunde Schlesner <yuriks@yuriks.net>
parents: 8149
diff changeset
   273
    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
   274
    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
   275
    Uint8 value1 = (Uint8) c;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   276
8779
d21a3ff2b0d2 Align pointer in SDL_memset before doing Uint32 loop
Yuri Kunde Schlesner <yuriks@yuriks.net>
parents: 8149
diff changeset
   277
    /* The destination pointer needs to be aligned on a 4-byte boundary to
d21a3ff2b0d2 Align pointer in SDL_memset before doing Uint32 loop
Yuri Kunde Schlesner <yuriks@yuriks.net>
parents: 8149
diff changeset
   278
     * execute a 32-bit set. Set first bytes manually if needed until it is
d21a3ff2b0d2 Align pointer in SDL_memset before doing Uint32 loop
Yuri Kunde Schlesner <yuriks@yuriks.net>
parents: 8149
diff changeset
   279
     * aligned. */
d21a3ff2b0d2 Align pointer in SDL_memset before doing Uint32 loop
Yuri Kunde Schlesner <yuriks@yuriks.net>
parents: 8149
diff changeset
   280
    while ((intptr_t)dstp1 & 0x3) {
d21a3ff2b0d2 Align pointer in SDL_memset before doing Uint32 loop
Yuri Kunde Schlesner <yuriks@yuriks.net>
parents: 8149
diff changeset
   281
        if (len--) {
d21a3ff2b0d2 Align pointer in SDL_memset before doing Uint32 loop
Yuri Kunde Schlesner <yuriks@yuriks.net>
parents: 8149
diff changeset
   282
            *dstp1++ = value1;
d21a3ff2b0d2 Align pointer in SDL_memset before doing Uint32 loop
Yuri Kunde Schlesner <yuriks@yuriks.net>
parents: 8149
diff changeset
   283
        } else {
d21a3ff2b0d2 Align pointer in SDL_memset before doing Uint32 loop
Yuri Kunde Schlesner <yuriks@yuriks.net>
parents: 8149
diff changeset
   284
            return dst;
d21a3ff2b0d2 Align pointer in SDL_memset before doing Uint32 loop
Yuri Kunde Schlesner <yuriks@yuriks.net>
parents: 8149
diff changeset
   285
        }
d21a3ff2b0d2 Align pointer in SDL_memset before doing Uint32 loop
Yuri Kunde Schlesner <yuriks@yuriks.net>
parents: 8149
diff changeset
   286
    }
d21a3ff2b0d2 Align pointer in SDL_memset before doing Uint32 loop
Yuri Kunde Schlesner <yuriks@yuriks.net>
parents: 8149
diff changeset
   287
d21a3ff2b0d2 Align pointer in SDL_memset before doing Uint32 loop
Yuri Kunde Schlesner <yuriks@yuriks.net>
parents: 8149
diff changeset
   288
    dstp4 = (Uint32 *) dstp1;
d21a3ff2b0d2 Align pointer in SDL_memset before doing Uint32 loop
Yuri Kunde Schlesner <yuriks@yuriks.net>
parents: 8149
diff changeset
   289
    left = (len % 4);
5325
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   290
    len /= 4;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   291
    while (len--) {
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   292
        *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
   293
    }
5325
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   294
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   295
    dstp1 = (Uint8 *) dstp4;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   296
    switch (left) {
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   297
    case 3:
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   298
        *dstp1++ = value1;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   299
    case 2:
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   300
        *dstp1++ = value1;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   301
    case 1:
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   302
        *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
   303
    }
5325
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   304
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
   305
    return dst;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   306
#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
   307
}
7003
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   308
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
   309
void *
8820
0e935d5b193a Added annotations to help code analysis tools
Sam Lantinga <slouken@libsdl.org>
parents: 8779
diff changeset
   310
SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) 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
   311
{
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
   312
#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
   313
    /* 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
   314
       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
   315
     */
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
    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
   317
#elif defined(HAVE_MEMCPY)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   318
    return memcpy(dst, src, len);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   319
#elif defined(HAVE_BCOPY)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   320
    bcopy(src, dst, len);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   321
    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
   322
#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
   323
    /* 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
   324
       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
   325
       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
   326
     */
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
    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
   328
        /* 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
   329
        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
   330
        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
   331
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
   332
        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
   333
            *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
   334
        }
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
    } 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
   336
        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
   337
        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
   338
        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
   339
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
   340
        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
   341
        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
   342
        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
   343
        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
   344
            *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
   345
        }
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
   346
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
   347
        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
   348
        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
   349
        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
   350
        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
   351
            *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
   352
        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
   353
            *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
   354
        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
   355
            *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
   356
        }
5325
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   357
    }
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
   358
    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
   359
#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
   360
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   361
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
   362
void *
8820
0e935d5b193a Added annotations to help code analysis tools
Sam Lantinga <slouken@libsdl.org>
parents: 8779
diff changeset
   363
SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) 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
   364
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   365
#if defined(HAVE_MEMMOVE)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   366
    return memmove(dst, src, len);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   367
#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
   368
    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
   369
    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
   370
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   371
    if (src < dst) {
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   372
        srcp += len - 1;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   373
        dstp += len - 1;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   374
        while (len--) {
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   375
            *dstp-- = *srcp--;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   376
        }
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   377
    } else {
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   378
        while (len--) {
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   379
            *dstp++ = *srcp++;
b9c224e16859 Fixed bug #1090 (SDL_BlitCopyOverlap() assumes memcpy() operates in order)
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   380
        }
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
   381
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   382
    return dst;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   383
#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
   384
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   385
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
   386
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
   387
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
   388
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   389
#if defined(HAVE_MEMCMP)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   390
    return memcmp(s1, s2, len);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   391
#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
   392
    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
   393
    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
   394
    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
   395
        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
   396
            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
   397
        }
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
   398
        ++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
   399
        ++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
   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
    return 0;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   402
#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
   403
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
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
   405
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
   406
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
   407
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   408
#if defined(HAVE_STRLEN)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   409
    return strlen(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   410
#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
   411
    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
   412
    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
   413
        ++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
   414
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   415
    return len;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   416
#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
   417
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   418
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
   419
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
   420
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
   421
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   422
#if defined(HAVE_WCSLEN)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   423
    return wcslen(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   424
#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
   425
    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
   426
    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
   427
        ++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
   428
    }
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
   429
    return len;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   430
#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
   431
}
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
   432
4758
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   433
size_t
8820
0e935d5b193a Added annotations to help code analysis tools
Sam Lantinga <slouken@libsdl.org>
parents: 8779
diff changeset
   434
SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
4758
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   435
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   436
#if defined(HAVE_WCSLCPY)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   437
    return wcslcpy(dst, src, maxlen);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   438
#else
4758
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 (maxlen > 0) {
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   441
        size_t len = SDL_min(srclen, maxlen - 1);
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   442
        SDL_memcpy(dst, src, len * sizeof(wchar_t));
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   443
        dst[len] = '\0';
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   444
    }
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   445
    return srclen;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   446
#endif /* HAVE_WCSLCPY */
4758
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   447
}
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   448
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   449
size_t
8820
0e935d5b193a Added annotations to help code analysis tools
Sam Lantinga <slouken@libsdl.org>
parents: 8779
diff changeset
   450
SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
4758
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   451
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   452
#if defined(HAVE_WCSLCAT)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   453
    return wcslcat(dst, src, maxlen);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   454
#else
4758
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   455
    size_t dstlen = SDL_wcslen(dst);
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   456
    size_t srclen = SDL_wcslen(src);
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   457
    if (dstlen < maxlen) {
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   458
        SDL_wcslcpy(dst + dstlen, src, maxlen - dstlen);
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   459
    }
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   460
    return dstlen + srclen;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   461
#endif /* HAVE_WCSLCAT */
4758
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   462
}
e2f4e31b41fc Added SDL_wcslcpy and SDL_wcslcat.
dewyatt
parents: 4754
diff changeset
   463
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
   464
size_t
8820
0e935d5b193a Added annotations to help code analysis tools
Sam Lantinga <slouken@libsdl.org>
parents: 8779
diff changeset
   465
SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) 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
   466
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   467
#if defined(HAVE_STRLCPY)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   468
    return strlcpy(dst, src, maxlen);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   469
#else
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   470
    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
   471
    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
   472
        size_t len = SDL_min(srclen, maxlen - 1);
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   473
        SDL_memcpy(dst, src, len);
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   474
        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
   475
    }
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   476
    return srclen;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   477
#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
   478
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   479
8820
0e935d5b193a Added annotations to help code analysis tools
Sam Lantinga <slouken@libsdl.org>
parents: 8779
diff changeset
   480
size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
4754
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
    size_t src_bytes = SDL_strlen(src);
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   483
    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
   484
    size_t i = 0;
4754
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   485
    char trailing_bytes = 0;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   486
    if (bytes)
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
        unsigned char c = (unsigned char)src[bytes - 1];
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   489
        if (UTF8_IsLeadByte(c))
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   490
            --bytes;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   491
        else if (UTF8_IsTrailingByte(c))
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   492
        {
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   493
            for (i = bytes - 1; i != 0; --i)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   494
            {
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   495
                c = (unsigned char)src[i];
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   496
                trailing_bytes = UTF8_TrailingBytes(c);
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   497
                if (trailing_bytes)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   498
                {
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   499
                    if (bytes - i != trailing_bytes + 1)
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   500
                        bytes = i;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   501
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   502
                    break;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   503
                }
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   504
            }
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   505
        }
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   506
        SDL_memcpy(dst, src, bytes);
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   507
    }
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   508
    dst[bytes] = '\0';
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   509
    return bytes;
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   510
}
2072fed2f583 Added SDL_utf8strlcpy to copy at UTF-8 character boundaries.
dewyatt
parents: 3697
diff changeset
   511
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
   512
size_t
8820
0e935d5b193a Added annotations to help code analysis tools
Sam Lantinga <slouken@libsdl.org>
parents: 8779
diff changeset
   513
SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) 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
   514
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   515
#if defined(HAVE_STRLCAT)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   516
    return strlcat(dst, src, maxlen);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   517
#else
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   518
    size_t dstlen = SDL_strlen(dst);
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   519
    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
   520
    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
   521
        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
   522
    }
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
   523
    return dstlen + srclen;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   524
#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
   525
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   526
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
   527
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
   528
SDL_strdup(const char *string)
1341
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   529
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   530
#if defined(HAVE_STRDUP)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   531
    return strdup(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   532
#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
   533
    size_t len = SDL_strlen(string) + 1;
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   534
    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
   535
    if (newstr) {
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
   536
        SDL_strlcpy(newstr, string, len);
1341
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   537
    }
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   538
    return newstr;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   539
#endif /* HAVE_STRDUP */
1341
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   540
}
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   541
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
   542
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
   543
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
   544
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   545
#if defined(HAVE__STRREV)
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   546
    return _strrev(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   547
#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
   548
    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
   549
    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
   550
    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
   551
    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
   552
    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
   553
        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
   554
        *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
   555
        *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
   556
    }
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
    return string;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   558
#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
   559
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   560
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
   561
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
   562
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
   563
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   564
#if defined(HAVE__STRUPR)
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   565
    return _strupr(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   566
#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
   567
    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
   568
    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
   569
        *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
   570
        ++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
   571
    }
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
    return string;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   573
#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
   574
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   575
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
   576
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
   577
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
   578
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   579
#if defined(HAVE__STRLWR)
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   580
    return _strlwr(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   581
#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
   582
    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
   583
    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
   584
        *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
   585
        ++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
   586
    }
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
    return string;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   588
#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
   589
}
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
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
   591
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
   592
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
   593
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   594
#ifdef HAVE_STRCHR
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   595
    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
   596
#elif defined(HAVE_INDEX)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   597
    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
   598
#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
   599
    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
   600
        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
   601
            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
   602
        }
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
   603
        ++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
   604
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   605
    return NULL;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   606
#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
   607
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   608
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
   609
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
   610
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
   611
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   612
#ifdef HAVE_STRRCHR
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   613
    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
   614
#elif defined(HAVE_RINDEX)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   615
    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
   616
#else
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   617
    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
   618
    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
   619
        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
   620
            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
   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
        --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
   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_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
   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
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
   628
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
   629
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
   630
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   631
#if defined(HAVE_STRSTR)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   632
    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
   633
#else
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   634
    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
   635
    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
   636
        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
   637
            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
   638
        }
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
   639
        ++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
   640
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   641
    return NULL;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   642
#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
   643
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   644
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   645
#if !defined(HAVE__LTOA) || !defined(HAVE__I64TOA) || \
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   646
    !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
   647
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
   648
    '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
   649
    '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
   650
    '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
   651
    '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
   652
};
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   653
#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
   654
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   655
char *
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   656
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
   657
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   658
#ifdef HAVE_ITOA
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   659
    return itoa(value, string, radix);
7003
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   660
#else
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   661
    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
   662
#endif /* HAVE_ITOA */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   663
}
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   664
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   665
char *
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   666
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
   667
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   668
#ifdef HAVE__UITOA
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   669
    return _uitoa(value, string, radix);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   670
#else
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   671
    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
   672
#endif /* HAVE__UITOA */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   673
}
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   674
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
   675
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
   676
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
   677
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   678
#if defined(HAVE__LTOA)
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   679
    return _ltoa(value, string, radix);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   680
#else
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   681
    char *bufp = string;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   682
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   683
    if (value < 0) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   684
        *bufp++ = '-';
8059
e70f5749f692 Fixed bug 2050 - Obvious bugs in SDL_ltoa and SDL_lltoa
Sam Lantinga <slouken@libsdl.org>
parents: 7728
diff changeset
   685
        SDL_ultoa(-value, bufp, radix);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   686
    } else {
8059
e70f5749f692 Fixed bug 2050 - Obvious bugs in SDL_ltoa and SDL_lltoa
Sam Lantinga <slouken@libsdl.org>
parents: 7728
diff changeset
   687
        SDL_ultoa(value, bufp, radix);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   688
    }
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
    return string;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   691
#endif /* HAVE__LTOA */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   692
}
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
char *
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   695
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
   696
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   697
#if defined(HAVE__ULTOA)
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   698
    return _ultoa(value, string, radix);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   699
#else
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   700
    char *bufp = string;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   701
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   702
    if (value) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   703
        while (value > 0) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   704
            *bufp++ = ntoa_table[value % radix];
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   705
            value /= radix;
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
    } else {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   708
        *bufp++ = '0';
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   709
    }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   710
    *bufp = '\0';
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
    /* 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
   713
    SDL_strrev(string);
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
    return string;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   716
#endif /* HAVE__ULTOA */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   717
}
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
char *
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   720
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
   721
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   722
#if defined(HAVE__I64TOA)
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   723
    return _i64toa(value, string, radix);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   724
#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
   725
    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
   726
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
   727
    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
   728
        *bufp++ = '-';
8059
e70f5749f692 Fixed bug 2050 - Obvious bugs in SDL_ltoa and SDL_lltoa
Sam Lantinga <slouken@libsdl.org>
parents: 7728
diff changeset
   729
        SDL_ulltoa(-value, bufp, 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
   730
    } else {
8059
e70f5749f692 Fixed bug 2050 - Obvious bugs in SDL_ltoa and SDL_lltoa
Sam Lantinga <slouken@libsdl.org>
parents: 7728
diff changeset
   731
        SDL_ulltoa(value, bufp, 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
   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
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
    return string;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   735
#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
   736
}
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
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
   738
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
   739
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
   740
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   741
#if defined(HAVE__UI64TOA)
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   742
    return _ui64toa(value, string, radix);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   743
#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
   744
    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
   745
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
   746
    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
   747
        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
   748
            *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
   749
            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
   750
        }
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
    } 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
   752
        *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
   753
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   754
    *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
   755
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
    /* 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
   757
    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
   758
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
    return string;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   760
#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
   761
}
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   762
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   763
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
   764
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   765
#ifdef HAVE_ATOI
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   766
    return atoi(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   767
#else
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   768
    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
   769
#endif /* HAVE_ATOI */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   770
}
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   771
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   772
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
   773
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   774
#ifdef HAVE_ATOF
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   775
    return (double) atof(string);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   776
#else
7353
80e081e7538d Fixed mingw32 build
Sam Lantinga <slouken@libsdl.org>
parents: 7352
diff changeset
   777
    return SDL_strtod(string, NULL);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   778
#endif /* HAVE_ATOF */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   779
}
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   780
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   781
long
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   782
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
   783
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   784
#if defined(HAVE_STRTOL)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   785
    return strtol(string, endp, base);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   786
#else
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   787
    size_t len;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   788
    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
   789
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   790
    if (!base) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   791
        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
   792
            base = 16;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   793
        } else {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   794
            base = 10;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   795
        }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   796
    }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   797
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   798
    len = SDL_ScanLong(string, base, &value);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   799
    if (endp) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   800
        *endp = (char *) string + len;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   801
    }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   802
    return value;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   803
#endif /* HAVE_STRTOL */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   804
}
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   805
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   806
unsigned long
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   807
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
   808
{
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   809
#if defined(HAVE_STRTOUL)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   810
    return strtoul(string, endp, base);
7003
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   811
#else
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   812
    size_t len;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   813
    unsigned long value;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   814
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   815
    if (!base) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   816
        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
   817
            base = 16;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   818
        } else {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   819
            base = 10;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   820
        }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   821
    }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   822
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   823
    len = SDL_ScanUnsignedLong(string, base, &value);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   824
    if (endp) {
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   825
        *endp = (char *) string + len;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   826
    }
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   827
    return value;
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   828
#endif /* HAVE_STRTOUL */
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   829
}
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   830
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
   831
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
   832
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
   833
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   834
#if defined(HAVE_STRTOLL)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   835
    return strtoll(string, endp, base);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   836
#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
   837
    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
   838
    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
   839
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
   840
    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
   841
        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
   842
            base = 16;
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   843
        } else {
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   844
            base = 10;
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   845
        }
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   846
    }
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   847
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   848
    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
   849
    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
   850
        *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
   851
    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   852
    return value;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   853
#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
   854
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   855
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
   856
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
   857
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
   858
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   859
#if defined(HAVE_STRTOULL)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   860
    return strtoull(string, endp, base);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   861
#else
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   862
    size_t len;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   863
    Uint64 value;
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   864
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
   865
    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
   866
        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
   867
            base = 16;
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   868
        } else {
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   869
            base = 10;
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   870
        }
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   871
    }
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   872
887c3600826b Fixed bug #251
Sam Lantinga <slouken@libsdl.org>
parents: 1818
diff changeset
   873
    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
   874
    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
   875
        *endp = (char *) string + len;
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   876
    }
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   877
    return value;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   878
#endif /* HAVE_STRTOULL */
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   879
}
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   880
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
   881
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
   882
SDL_strtod(const char *string, char **endp)
1341
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   883
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   884
#if defined(HAVE_STRTOD)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   885
    return strtod(string, endp);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   886
#else
1341
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   887
    size_t len;
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   888
    double value;
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   889
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   890
    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
   891
    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
   892
        *endp = (char *) string + len;
1341
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   893
    }
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   894
    return value;
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   895
#endif /* HAVE_STRTOD */
1341
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   896
}
d02b552e5304 Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
   897
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
   898
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
   899
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
   900
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   901
#if defined(HAVE_STRCMP)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   902
    return strcmp(str1, str2);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   903
#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
   904
    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
   905
        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
   906
            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
   907
        ++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
   908
        ++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
   909
    }
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
   910
    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
   911
#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
   912
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   913
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
   914
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
   915
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
   916
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   917
#if defined(HAVE_STRNCMP)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   918
    return strncmp(str1, str2, maxlen);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   919
#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
   920
    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
   921
        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
   922
            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
   923
        ++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
   924
        ++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
   925
        --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
   926
    }
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
   927
    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
   928
        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
   929
    }
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
   930
    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
   931
#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
   932
}
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
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
   934
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
   935
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
   936
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   937
#ifdef HAVE_STRCASECMP
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   938
    return strcasecmp(str1, str2);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   939
#elif defined(HAVE__STRICMP)
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   940
    return _stricmp(str1, str2);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   941
#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
   942
    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
   943
    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
   944
    while (*str1 && *str2) {
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   945
        a = SDL_toupper((unsigned char) *str1);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   946
        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
   947
        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
   948
            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
   949
        ++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
   950
        ++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
   951
    }
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   952
    a = SDL_toupper(*str1);
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   953
    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
   954
    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
   955
#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
   956
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   957
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
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
   959
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
   960
{
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   961
#ifdef HAVE_STRNCASECMP
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   962
    return strncasecmp(str1, str2, maxlen);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   963
#elif defined(HAVE__STRNICMP)
7352
de96caa46c09 Fixed build errors on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 7351
diff changeset
   964
    return _strnicmp(str1, str2, maxlen);
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   965
#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
   966
    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
   967
    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
   968
    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
   969
        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
   970
        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
   971
        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
   972
            break;
73dc5d39bbf8 Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   973
        ++str1;
73dc5d39bbf8 Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   974
        ++str2;
73dc5d39bbf8 Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   975
        --maxlen;
73dc5d39bbf8 Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   976
    }
6766
2b8a507c278b Fixed bug in SDL_strcasecmp() with strings of different sizes
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   977
    if (maxlen == 0) {
2b8a507c278b Fixed bug in SDL_strcasecmp() with strings of different sizes
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   978
        return 0;
2b8a507c278b Fixed bug in SDL_strcasecmp() with strings of different sizes
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   979
    } else {
2b8a507c278b Fixed bug in SDL_strcasecmp() with strings of different sizes
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   980
        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
   981
        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
   982
        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
   983
    }
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7236
diff changeset
   984
#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
   985
}
73dc5d39bbf8 Added UTF-8 <-> UTF-16 <-> UTF-32 <-> UCS-2 <-> UCS-4 conversion capability
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   986
7003
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   987
int
8820
0e935d5b193a Added annotations to help code analysis tools
Sam Lantinga <slouken@libsdl.org>
parents: 8779
diff changeset
   988
SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...)
7003
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   989
{
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   990
    int rc;
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   991
    va_list ap;
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   992
    va_start(ap, fmt);
8089
de8b6fdf6544 Added SDL_vsscanf().
Ryan C. Gordon <icculus@icculus.org>
parents: 8059
diff changeset
   993
    rc = SDL_vsscanf(text, fmt, ap);
7003
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   994
    va_end(ap);
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   995
    return rc;
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   996
}
8089
de8b6fdf6544 Added SDL_vsscanf().
Ryan C. Gordon <icculus@icculus.org>
parents: 8059
diff changeset
   997
de8b6fdf6544 Added SDL_vsscanf().
Ryan C. Gordon <icculus@icculus.org>
parents: 8059
diff changeset
   998
#ifdef HAVE_VSSCANF
de8b6fdf6544 Added SDL_vsscanf().
Ryan C. Gordon <icculus@icculus.org>
parents: 8059
diff changeset
   999
int
de8b6fdf6544 Added SDL_vsscanf().
Ryan C. Gordon <icculus@icculus.org>
parents: 8059
diff changeset
  1000
SDL_vsscanf(const char *text, const char *fmt, va_list ap)
de8b6fdf6544 Added SDL_vsscanf().
Ryan C. Gordon <icculus@icculus.org>
parents: 8059
diff changeset
  1001
{
de8b6fdf6544 Added SDL_vsscanf().
Ryan C. Gordon <icculus@icculus.org>
parents: 8059
diff changeset
  1002
    return vsscanf(text, fmt, ap);
de8b6fdf6544 Added SDL_vsscanf().
Ryan C. Gordon <icculus@icculus.org>
parents: 8059
diff changeset
  1003
}
7003
eeaf77005c30 Improvements to stdlib.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
  1004
#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
  1005
int
8092
46fb898f098d Patched stdlib changes to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 8089
diff changeset
  1006
SDL_vsscanf(const char *text, const char *fmt, va_list ap)
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
  1007
{
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1008
    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
  1009
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
    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
  1011
        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
  1012
            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
  1013
                ++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
  1014
            }
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
            ++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
  1016
            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
  1017
        }
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
  1018
        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
  1019
            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
  1020
            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
  1021
            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
  1022
            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
  1023
            {
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
  1024
                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
  1025
                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
  1026
                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
  1027
                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
  1028
            } 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
  1029
            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
  1030
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
            ++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
  1032
            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
  1033
                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
  1034
                    ++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
  1035
                    ++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
  1036
                    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
  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
                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
  1039
            }
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
  1040
            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
  1041
                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
  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
            }
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
            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
  1045
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
  1046
            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
  1047
                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
  1048
                    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
  1049
                }
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
  1050
                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
  1051
                    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
  1052
                        ++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
  1053
                    }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1054
                } 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
  1055
                    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
  1056
                    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
  1057
                        *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
  1058
                    }
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
                    ++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
  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
                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
  1062
            }
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
  1063
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
  1064
            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
  1065
                ++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
  1066
            }
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
            /* 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
  1069
            while (!done) {
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
  1070
                switch (*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
  1071
                case '*':
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lanting