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