SDL 2.0
SDL_string.c
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#if defined(__clang_analyzer__)
22#define SDL_DISABLE_ANALYZE_MACROS 1
23#endif
24
25#include "../SDL_internal.h"
26
27/* This file contains portable string manipulation functions for SDL */
28
29#include "SDL_stdinc.h"
30
31#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOLL) || !defined(HAVE_STRTOULL) || !defined(HAVE_STRTOD)
32#define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F'))
33#define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f'))
34#endif
35
36#define UTF8_IsLeadByte(c) ((c) >= 0xC0 && (c) <= 0xF4)
37#define UTF8_IsTrailingByte(c) ((c) >= 0x80 && (c) <= 0xBF)
38
39static int UTF8_TrailingBytes(unsigned char c)
40{
41 if (c >= 0xC0 && c <= 0xDF)
42 return 1;
43 else if (c >= 0xE0 && c <= 0xEF)
44 return 2;
45 else if (c >= 0xF0 && c <= 0xF4)
46 return 3;
47 else
48 return 0;
49}
50
51#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL)
52static size_t
53SDL_ScanLong(const char *text, int radix, long *valuep)
54{
55 const char *textstart = text;
56 long value = 0;
57 SDL_bool negative = SDL_FALSE;
58
59 if (*text == '-') {
60 negative = SDL_TRUE;
61 ++text;
62 }
63 if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
64 text += 2;
65 }
66 for (;;) {
67 int v;
68 if (SDL_isdigit((unsigned char) *text)) {
69 v = *text - '0';
70 } else if (radix == 16 && SDL_isupperhex(*text)) {
71 v = 10 + (*text - 'A');
72 } else if (radix == 16 && SDL_islowerhex(*text)) {
73 v = 10 + (*text - 'a');
74 } else {
75 break;
76 }
77 value *= radix;
78 value += v;
79 ++text;
80 }
81 if (valuep && text > textstart) {
82 if (negative && value) {
83 *valuep = -value;
84 } else {
85 *valuep = value;
86 }
87 }
88 return (text - textstart);
89}
90#endif
91
92#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
93static size_t
94SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
95{
96 const char *textstart = text;
97 unsigned long value = 0;
98
99 if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
100 text += 2;
101 }
102 for (;;) {
103 int v;
104 if (SDL_isdigit((unsigned char) *text)) {
105 v = *text - '0';
106 } else if (radix == 16 && SDL_isupperhex(*text)) {
107 v = 10 + (*text - 'A');
108 } else if (radix == 16 && SDL_islowerhex(*text)) {
109 v = 10 + (*text - 'a');
110 } else {
111 break;
112 }
113 value *= radix;
114 value += v;
115 ++text;
116 }
117 if (valuep && text > textstart) {
118 *valuep = value;
119 }
120 return (text - textstart);
121}
122#endif
123
124#ifndef HAVE_VSSCANF
125static size_t
126SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep)
127{
128 const char *textstart = text;
129 uintptr_t value = 0;
130
131 if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
132 text += 2;
133 }
134 for (;;) {
135 int v;
136 if (SDL_isdigit((unsigned char) *text)) {
137 v = *text - '0';
138 } else if (radix == 16 && SDL_isupperhex(*text)) {
139 v = 10 + (*text - 'A');
140 } else if (radix == 16 && SDL_islowerhex(*text)) {
141 v = 10 + (*text - 'a');
142 } else {
143 break;
144 }
145 value *= radix;
146 value += v;
147 ++text;
148 }
149 if (valuep && text > textstart) {
150 *valuep = value;
151 }
152 return (text - textstart);
153}
154#endif
155
156#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOLL)
157static size_t
158SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep)
159{
160 const char *textstart = text;
161 Sint64 value = 0;
162 SDL_bool negative = SDL_FALSE;
163
164 if (*text == '-') {
165 negative = SDL_TRUE;
166 ++text;
167 }
168 if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
169 text += 2;
170 }
171 for (;;) {
172 int v;
173 if (SDL_isdigit((unsigned char) *text)) {
174 v = *text - '0';
175 } else if (radix == 16 && SDL_isupperhex(*text)) {
176 v = 10 + (*text - 'A');
177 } else if (radix == 16 && SDL_islowerhex(*text)) {
178 v = 10 + (*text - 'a');
179 } else {
180 break;
181 }
182 value *= radix;
183 value += v;
184 ++text;
185 }
186 if (valuep && text > textstart) {
187 if (negative && value) {
188 *valuep = -value;
189 } else {
190 *valuep = value;
191 }
192 }
193 return (text - textstart);
194}
195#endif
196
197#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOULL)
198static size_t
199SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep)
200{
201 const char *textstart = text;
202 Uint64 value = 0;
203
204 if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
205 text += 2;
206 }
207 for (;;) {
208 int v;
209 if (SDL_isdigit((unsigned char) *text)) {
210 v = *text - '0';
211 } else if (radix == 16 && SDL_isupperhex(*text)) {
212 v = 10 + (*text - 'A');
213 } else if (radix == 16 && SDL_islowerhex(*text)) {
214 v = 10 + (*text - 'a');
215 } else {
216 break;
217 }
218 value *= radix;
219 value += v;
220 ++text;
221 }
222 if (valuep && text > textstart) {
223 *valuep = value;
224 }
225 return (text - textstart);
226}
227#endif
228
229#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOD)
230static size_t
231SDL_ScanFloat(const char *text, double *valuep)
232{
233 const char *textstart = text;
234 unsigned long lvalue = 0;
235 double value = 0.0;
236 SDL_bool negative = SDL_FALSE;
237
238 if (*text == '-') {
239 negative = SDL_TRUE;
240 ++text;
241 }
242 text += SDL_ScanUnsignedLong(text, 10, &lvalue);
243 value += lvalue;
244 if (*text == '.') {
245 int mult = 10;
246 ++text;
247 while (SDL_isdigit((unsigned char) *text)) {
248 lvalue = *text - '0';
249 value += (double) lvalue / mult;
250 mult *= 10;
251 ++text;
252 }
253 }
254 if (valuep && text > textstart) {
255 if (negative && value) {
256 *valuep = -value;
257 } else {
258 *valuep = value;
259 }
260 }
261 return (text - textstart);
262}
263#endif
264
265void *
266SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
267{
268#if defined(HAVE_MEMSET)
269 return memset(dst, c, len);
270#else
271 size_t left;
272 Uint32 *dstp4;
273 Uint8 *dstp1 = (Uint8 *) dst;
274 Uint8 value1;
275 Uint32 value4;
276
277 /* The value used in memset() is a byte, passed as an int */
278 c &= 0xff;
279
280 /* The destination pointer needs to be aligned on a 4-byte boundary to
281 * execute a 32-bit set. Set first bytes manually if needed until it is
282 * aligned. */
283 value1 = (Uint8)c;
284 while ((intptr_t)dstp1 & 0x3) {
285 if (len--) {
286 *dstp1++ = value1;
287 } else {
288 return dst;
289 }
290 }
291
292 value4 = (c | (c << 8) | (c << 16) | (c << 24));
293 dstp4 = (Uint32 *) dstp1;
294 left = (len % 4);
295 len /= 4;
296 while (len--) {
297 *dstp4++ = value4;
298 }
299
300 dstp1 = (Uint8 *) dstp4;
301 switch (left) {
302 case 3:
303 *dstp1++ = value1;
304 case 2:
305 *dstp1++ = value1;
306 case 1:
307 *dstp1++ = value1;
308 }
309
310 return dst;
311#endif /* HAVE_MEMSET */
312}
313
314void *
316{
317#ifdef __GNUC__
318 /* Presumably this is well tuned for speed.
319 On my machine this is twice as fast as the C code below.
320 */
321 return __builtin_memcpy(dst, src, len);
322#elif defined(HAVE_MEMCPY)
323 return memcpy(dst, src, len);
324#elif defined(HAVE_BCOPY)
325 bcopy(src, dst, len);
326 return dst;
327#else
328 /* GCC 4.9.0 with -O3 will generate movaps instructions with the loop
329 using Uint32* pointers, so we need to make sure the pointers are
330 aligned before we loop using them.
331 */
332 if (((intptr_t)src & 0x3) || ((intptr_t)dst & 0x3)) {
333 /* Do an unaligned byte copy */
334 Uint8 *srcp1 = (Uint8 *)src;
335 Uint8 *dstp1 = (Uint8 *)dst;
336
337 while (len--) {
338 *dstp1++ = *srcp1++;
339 }
340 } else {
341 size_t left = (len % 4);
342 Uint32 *srcp4, *dstp4;
343 Uint8 *srcp1, *dstp1;
344
345 srcp4 = (Uint32 *) src;
346 dstp4 = (Uint32 *) dst;
347 len /= 4;
348 while (len--) {
349 *dstp4++ = *srcp4++;
350 }
351
352 srcp1 = (Uint8 *) srcp4;
353 dstp1 = (Uint8 *) dstp4;
354 switch (left) {
355 case 3:
356 *dstp1++ = *srcp1++;
357 case 2:
358 *dstp1++ = *srcp1++;
359 case 1:
360 *dstp1++ = *srcp1++;
361 }
362 }
363 return dst;
364#endif /* __GNUC__ */
365}
366
367void *
369{
370#if defined(HAVE_MEMMOVE)
371 return memmove(dst, src, len);
372#else
373 char *srcp = (char *) src;
374 char *dstp = (char *) dst;
375
376 if (src < dst) {
377 srcp += len - 1;
378 dstp += len - 1;
379 while (len--) {
380 *dstp-- = *srcp--;
381 }
382 } else {
383 while (len--) {
384 *dstp++ = *srcp++;
385 }
386 }
387 return dst;
388#endif /* HAVE_MEMMOVE */
389}
390
391int
392SDL_memcmp(const void *s1, const void *s2, size_t len)
393{
394#if defined(HAVE_MEMCMP)
395 return memcmp(s1, s2, len);
396#else
397 char *s1p = (char *) s1;
398 char *s2p = (char *) s2;
399 while (len--) {
400 if (*s1p != *s2p) {
401 return (*s1p - *s2p);
402 }
403 ++s1p;
404 ++s2p;
405 }
406 return 0;
407#endif /* HAVE_MEMCMP */
408}
409
410size_t
411SDL_strlen(const char *string)
412{
413#if defined(HAVE_STRLEN)
414 return strlen(string);
415#else
416 size_t len = 0;
417 while (*string++) {
418 ++len;
419 }
420 return len;
421#endif /* HAVE_STRLEN */
422}
423
424wchar_t *
425SDL_wcsdup(const wchar_t *string)
426{
427 size_t len = ((SDL_wcslen(string) + 1) * sizeof(wchar_t));
428 wchar_t *newstr = (wchar_t *)SDL_malloc(len);
429 if (newstr) {
430 SDL_memcpy(newstr, string, len);
431 }
432 return newstr;
433}
434
435size_t
436SDL_wcslen(const wchar_t * string)
437{
438#if defined(HAVE_WCSLEN)
439 return wcslen(string);
440#else
441 size_t len = 0;
442 while (*string++) {
443 ++len;
444 }
445 return len;
446#endif /* HAVE_WCSLEN */
447}
448
449size_t
450SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
451{
452#if defined(HAVE_WCSLCPY)
453 return wcslcpy(dst, src, maxlen);
454#else
455 size_t srclen = SDL_wcslen(src);
456 if (maxlen > 0) {
457 size_t len = SDL_min(srclen, maxlen - 1);
458 SDL_memcpy(dst, src, len * sizeof(wchar_t));
459 dst[len] = '\0';
460 }
461 return srclen;
462#endif /* HAVE_WCSLCPY */
463}
464
465size_t
466SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
467{
468#if defined(HAVE_WCSLCAT)
469 return wcslcat(dst, src, maxlen);
470#else
471 size_t dstlen = SDL_wcslen(dst);
472 size_t srclen = SDL_wcslen(src);
473 if (dstlen < maxlen) {
474 SDL_wcslcpy(dst + dstlen, src, maxlen - dstlen);
475 }
476 return dstlen + srclen;
477#endif /* HAVE_WCSLCAT */
478}
479
480int
481SDL_wcscmp(const wchar_t *str1, const wchar_t *str2)
482{
483#if defined(HAVE_WCSCMP)
484 return wcscmp(str1, str2);
485#else
486 while (*str1 && *str2) {
487 if (*str1 != *str2)
488 break;
489 ++str1;
490 ++str2;
491 }
492 return (int)(*str1 - *str2);
493#endif /* HAVE_WCSCMP */
494}
495
496size_t
497SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
498{
499#if defined(HAVE_STRLCPY)
500 return strlcpy(dst, src, maxlen);
501#else
502 size_t srclen = SDL_strlen(src);
503 if (maxlen > 0) {
504 size_t len = SDL_min(srclen, maxlen - 1);
506 dst[len] = '\0';
507 }
508 return srclen;
509#endif /* HAVE_STRLCPY */
510}
511
512size_t
513SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
514{
515 size_t src_bytes = SDL_strlen(src);
516 size_t bytes = SDL_min(src_bytes, dst_bytes - 1);
517 size_t i = 0;
518 char trailing_bytes = 0;
519 if (bytes)
520 {
521 unsigned char c = (unsigned char)src[bytes - 1];
522 if (UTF8_IsLeadByte(c))
523 --bytes;
524 else if (UTF8_IsTrailingByte(c))
525 {
526 for (i = bytes - 1; i != 0; --i)
527 {
528 c = (unsigned char)src[i];
529 trailing_bytes = UTF8_TrailingBytes(c);
530 if (trailing_bytes)
531 {
532 if (bytes - i != trailing_bytes + 1)
533 bytes = i;
534
535 break;
536 }
537 }
538 }
539 SDL_memcpy(dst, src, bytes);
540 }
541 dst[bytes] = '\0';
542 return bytes;
543}
544
545size_t
546SDL_utf8strlen(const char *str)
547{
548 size_t retval = 0;
549 const char *p = str;
550 char ch;
551
552 while ((ch = *(p++))) {
553 /* if top two bits are 1 and 0, it's a continuation byte. */
554 if ((ch & 0xc0) != 0x80) {
555 retval++;
556 }
557 }
558
559 return retval;
560}
561
562size_t
563SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
564{
565#if defined(HAVE_STRLCAT)
566 return strlcat(dst, src, maxlen);
567#else
568 size_t dstlen = SDL_strlen(dst);
569 size_t srclen = SDL_strlen(src);
570 if (dstlen < maxlen) {
571 SDL_strlcpy(dst + dstlen, src, maxlen - dstlen);
572 }
573 return dstlen + srclen;
574#endif /* HAVE_STRLCAT */
575}
576
577char *
578SDL_strdup(const char *string)
579{
580 size_t len = SDL_strlen(string) + 1;
581 char *newstr = (char *)SDL_malloc(len);
582 if (newstr) {
583 SDL_memcpy(newstr, string, len);
584 }
585 return newstr;
586}
587
588char *
589SDL_strrev(char *string)
590{
591#if defined(HAVE__STRREV)
592 return _strrev(string);
593#else
594 size_t len = SDL_strlen(string);
595 char *a = &string[0];
596 char *b = &string[len - 1];
597 len /= 2;
598 while (len--) {
599 char c = *a;
600 *a++ = *b;
601 *b-- = c;
602 }
603 return string;
604#endif /* HAVE__STRREV */
605}
606
607char *
608SDL_strupr(char *string)
609{
610#if defined(HAVE__STRUPR)
611 return _strupr(string);
612#else
613 char *bufp = string;
614 while (*bufp) {
615 *bufp = SDL_toupper((unsigned char) *bufp);
616 ++bufp;
617 }
618 return string;
619#endif /* HAVE__STRUPR */
620}
621
622char *
623SDL_strlwr(char *string)
624{
625#if defined(HAVE__STRLWR)
626 return _strlwr(string);
627#else
628 char *bufp = string;
629 while (*bufp) {
630 *bufp = SDL_tolower((unsigned char) *bufp);
631 ++bufp;
632 }
633 return string;
634#endif /* HAVE__STRLWR */
635}
636
637char *
638SDL_strchr(const char *string, int c)
639{
640#ifdef HAVE_STRCHR
641 return SDL_const_cast(char*,strchr(string, c));
642#elif defined(HAVE_INDEX)
643 return SDL_const_cast(char*,index(string, c));
644#else
645 while (*string) {
646 if (*string == c) {
647 return (char *) string;
648 }
649 ++string;
650 }
651 return NULL;
652#endif /* HAVE_STRCHR */
653}
654
655char *
656SDL_strrchr(const char *string, int c)
657{
658#ifdef HAVE_STRRCHR
659 return SDL_const_cast(char*,strrchr(string, c));
660#elif defined(HAVE_RINDEX)
661 return SDL_const_cast(char*,rindex(string, c));
662#else
663 const char *bufp = string + SDL_strlen(string) - 1;
664 while (bufp >= string) {
665 if (*bufp == c) {
666 return (char *) bufp;
667 }
668 --bufp;
669 }
670 return NULL;
671#endif /* HAVE_STRRCHR */
672}
673
674char *
675SDL_strstr(const char *haystack, const char *needle)
676{
677#if defined(HAVE_STRSTR)
678 return SDL_const_cast(char*,strstr(haystack, needle));
679#else
680 size_t length = SDL_strlen(needle);
681 while (*haystack) {
682 if (SDL_strncmp(haystack, needle, length) == 0) {
683 return (char *) haystack;
684 }
685 ++haystack;
686 }
687 return NULL;
688#endif /* HAVE_STRSTR */
689}
690
691#if !defined(HAVE__LTOA) || !defined(HAVE__I64TOA) || \
692 !defined(HAVE__ULTOA) || !defined(HAVE__UI64TOA)
693static const char ntoa_table[] = {
694 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
695 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
696 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
697 'U', 'V', 'W', 'X', 'Y', 'Z'
698};
699#endif /* ntoa() conversion table */
700
701char *
702SDL_itoa(int value, char *string, int radix)
703{
704#ifdef HAVE_ITOA
705 return itoa(value, string, radix);
706#else
707 return SDL_ltoa((long)value, string, radix);
708#endif /* HAVE_ITOA */
709}
710
711char *
712SDL_uitoa(unsigned int value, char *string, int radix)
713{
714#ifdef HAVE__UITOA
715 return _uitoa(value, string, radix);
716#else
717 return SDL_ultoa((unsigned long)value, string, radix);
718#endif /* HAVE__UITOA */
719}
720
721char *
722SDL_ltoa(long value, char *string, int radix)
723{
724#if defined(HAVE__LTOA)
725 return _ltoa(value, string, radix);
726#else
727 char *bufp = string;
728
729 if (value < 0) {
730 *bufp++ = '-';
731 SDL_ultoa(-value, bufp, radix);
732 } else {
733 SDL_ultoa(value, bufp, radix);
734 }
735
736 return string;
737#endif /* HAVE__LTOA */
738}
739
740char *
741SDL_ultoa(unsigned long value, char *string, int radix)
742{
743#if defined(HAVE__ULTOA)
744 return _ultoa(value, string, radix);
745#else
746 char *bufp = string;
747
748 if (value) {
749 while (value > 0) {
750 *bufp++ = ntoa_table[value % radix];
751 value /= radix;
752 }
753 } else {
754 *bufp++ = '0';
755 }
756 *bufp = '\0';
757
758 /* The numbers went into the string backwards. :) */
759 SDL_strrev(string);
760
761 return string;
762#endif /* HAVE__ULTOA */
763}
764
765char *
766SDL_lltoa(Sint64 value, char *string, int radix)
767{
768#if defined(HAVE__I64TOA)
769 return _i64toa(value, string, radix);
770#else
771 char *bufp = string;
772
773 if (value < 0) {
774 *bufp++ = '-';
775 SDL_ulltoa(-value, bufp, radix);
776 } else {
777 SDL_ulltoa(value, bufp, radix);
778 }
779
780 return string;
781#endif /* HAVE__I64TOA */
782}
783
784char *
785SDL_ulltoa(Uint64 value, char *string, int radix)
786{
787#if defined(HAVE__UI64TOA)
788 return _ui64toa(value, string, radix);
789#else
790 char *bufp = string;
791
792 if (value) {
793 while (value > 0) {
794 *bufp++ = ntoa_table[value % radix];
795 value /= radix;
796 }
797 } else {
798 *bufp++ = '0';
799 }
800 *bufp = '\0';
801
802 /* The numbers went into the string backwards. :) */
803 SDL_strrev(string);
804
805 return string;
806#endif /* HAVE__UI64TOA */
807}
808
809int SDL_atoi(const char *string)
810{
811#ifdef HAVE_ATOI
812 return atoi(string);
813#else
814 return SDL_strtol(string, NULL, 0);
815#endif /* HAVE_ATOI */
816}
817
818double SDL_atof(const char *string)
819{
820#ifdef HAVE_ATOF
821 return (double) atof(string);
822#else
823 return SDL_strtod(string, NULL);
824#endif /* HAVE_ATOF */
825}
826
827long
828SDL_strtol(const char *string, char **endp, int base)
829{
830#if defined(HAVE_STRTOL)
831 return strtol(string, endp, base);
832#else
833 size_t len;
834 long value = 0;
835
836 if (!base) {
837 if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
838 base = 16;
839 } else {
840 base = 10;
841 }
842 }
843
844 len = SDL_ScanLong(string, base, &value);
845 if (endp) {
846 *endp = (char *) string + len;
847 }
848 return value;
849#endif /* HAVE_STRTOL */
850}
851
852unsigned long
853SDL_strtoul(const char *string, char **endp, int base)
854{
855#if defined(HAVE_STRTOUL)
856 return strtoul(string, endp, base);
857#else
858 size_t len;
859 unsigned long value = 0;
860
861 if (!base) {
862 if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
863 base = 16;
864 } else {
865 base = 10;
866 }
867 }
868
869 len = SDL_ScanUnsignedLong(string, base, &value);
870 if (endp) {
871 *endp = (char *) string + len;
872 }
873 return value;
874#endif /* HAVE_STRTOUL */
875}
876
877Sint64
878SDL_strtoll(const char *string, char **endp, int base)
879{
880#if defined(HAVE_STRTOLL)
881 return strtoll(string, endp, base);
882#else
883 size_t len;
884 Sint64 value = 0;
885
886 if (!base) {
887 if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
888 base = 16;
889 } else {
890 base = 10;
891 }
892 }
893
894 len = SDL_ScanLongLong(string, base, &value);
895 if (endp) {
896 *endp = (char *) string + len;
897 }
898 return value;
899#endif /* HAVE_STRTOLL */
900}
901
902Uint64
903SDL_strtoull(const char *string, char **endp, int base)
904{
905#if defined(HAVE_STRTOULL)
906 return strtoull(string, endp, base);
907#else
908 size_t len;
909 Uint64 value = 0;
910
911 if (!base) {
912 if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
913 base = 16;
914 } else {
915 base = 10;
916 }
917 }
918
919 len = SDL_ScanUnsignedLongLong(string, base, &value);
920 if (endp) {
921 *endp = (char *) string + len;
922 }
923 return value;
924#endif /* HAVE_STRTOULL */
925}
926
927double
928SDL_strtod(const char *string, char **endp)
929{
930#if defined(HAVE_STRTOD)
931 return strtod(string, endp);
932#else
933 size_t len;
934 double value = 0.0;
935
936 len = SDL_ScanFloat(string, &value);
937 if (endp) {
938 *endp = (char *) string + len;
939 }
940 return value;
941#endif /* HAVE_STRTOD */
942}
943
944int
945SDL_strcmp(const char *str1, const char *str2)
946{
947#if defined(HAVE_STRCMP)
948 return strcmp(str1, str2);
949#else
950 while (*str1 && *str2) {
951 if (*str1 != *str2)
952 break;
953 ++str1;
954 ++str2;
955 }
956 return (int)((unsigned char) *str1 - (unsigned char) *str2);
957#endif /* HAVE_STRCMP */
958}
959
960int
961SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
962{
963#if defined(HAVE_STRNCMP)
964 return strncmp(str1, str2, maxlen);
965#else
966 while (*str1 && *str2 && maxlen) {
967 if (*str1 != *str2)
968 break;
969 ++str1;
970 ++str2;
971 --maxlen;
972 }
973 if (!maxlen) {
974 return 0;
975 }
976 return (int) ((unsigned char) *str1 - (unsigned char) *str2);
977#endif /* HAVE_STRNCMP */
978}
979
980int
981SDL_strcasecmp(const char *str1, const char *str2)
982{
983#ifdef HAVE_STRCASECMP
984 return strcasecmp(str1, str2);
985#elif defined(HAVE__STRICMP)
986 return _stricmp(str1, str2);
987#else
988 char a = 0;
989 char b = 0;
990 while (*str1 && *str2) {
991 a = SDL_toupper((unsigned char) *str1);
992 b = SDL_toupper((unsigned char) *str2);
993 if (a != b)
994 break;
995 ++str1;
996 ++str2;
997 }
998 a = SDL_toupper(*str1);
999 b = SDL_toupper(*str2);
1000 return (int) ((unsigned char) a - (unsigned char) b);
1001#endif /* HAVE_STRCASECMP */
1002}
1003
1004int
1005SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
1006{
1007#ifdef HAVE_STRNCASECMP
1008 return strncasecmp(str1, str2, maxlen);
1009#elif defined(HAVE__STRNICMP)
1010 return _strnicmp(str1, str2, maxlen);
1011#else
1012 char a = 0;
1013 char b = 0;
1014 while (*str1 && *str2 && maxlen) {
1015 a = SDL_tolower((unsigned char) *str1);
1016 b = SDL_tolower((unsigned char) *str2);
1017 if (a != b)
1018 break;
1019 ++str1;
1020 ++str2;
1021 --maxlen;
1022 }
1023 if (maxlen == 0) {
1024 return 0;
1025 } else {
1026 a = SDL_tolower((unsigned char) *str1);
1027 b = SDL_tolower((unsigned char) *str2);
1028 return (int) ((unsigned char) a - (unsigned char) b);
1029 }
1030#endif /* HAVE_STRNCASECMP */
1031}
1032
1033int
1034SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...)
1035{
1036 int rc;
1037 va_list ap;
1038 va_start(ap, fmt);
1039 rc = SDL_vsscanf(text, fmt, ap);
1040 va_end(ap);
1041 return rc;
1042}
1043
1044#ifdef HAVE_VSSCANF
1045int
1046SDL_vsscanf(const char *text, const char *fmt, va_list ap)
1047{
1048 return vsscanf(text, fmt, ap);
1049}
1050#else
1051int
1052SDL_vsscanf(const char *text, const char *fmt, va_list ap)
1053{
1054 int retval = 0;
1055
1056 if (!text || !*text) {
1057 return -1;
1058 }
1059
1060 while (*fmt) {
1061 if (*fmt == ' ') {
1062 while (SDL_isspace((unsigned char) *text)) {
1063 ++text;
1064 }
1065 ++fmt;
1066 continue;
1067 }
1068 if (*fmt == '%') {
1070 long count = 0;
1071 int radix = 10;
1072 enum
1073 {
1074 DO_SHORT,
1075 DO_INT,
1076 DO_LONG,
1077 DO_LONGLONG
1078 } inttype = DO_INT;
1079 size_t advance;
1080 SDL_bool suppress = SDL_FALSE;
1081
1082 ++fmt;
1083 if (*fmt == '%') {
1084 if (*text == '%') {
1085 ++text;
1086 ++fmt;
1087 continue;
1088 }
1089 break;
1090 }
1091 if (*fmt == '*') {
1092 suppress = SDL_TRUE;
1093 ++fmt;
1094 }
1095 fmt += SDL_ScanLong(fmt, 10, &count);
1096
1097 if (*fmt == 'c') {
1098 if (!count) {
1099 count = 1;
1100 }
1101 if (suppress) {
1102 while (count--) {
1103 ++text;
1104 }
1105 } else {
1106 char *valuep = va_arg(ap, char *);
1107 while (count--) {
1108 *valuep++ = *text++;
1109 }
1110 ++retval;
1111 }
1112 continue;
1113 }
1114
1115 while (SDL_isspace((unsigned char) *text)) {
1116 ++text;
1117 }
1118
1119 /* FIXME: implement more of the format specifiers */
1120 while (!done) {
1121 switch (*fmt) {
1122 case '*':
1123 suppress = SDL_TRUE;
1124 break;
1125 case 'h':
1126 if (inttype > DO_SHORT) {
1127 ++inttype;
1128 }
1129 break;
1130 case 'l':
1131 if (inttype < DO_LONGLONG) {
1132 ++inttype;
1133 }
1134 break;
1135 case 'I':
1136 if (SDL_strncmp(fmt, "I64", 3) == 0) {
1137 fmt += 2;
1138 inttype = DO_LONGLONG;
1139 }
1140 break;
1141 case 'i':
1142 {
1143 int index = 0;
1144 if (text[index] == '-') {
1145 ++index;
1146 }
1147 if (text[index] == '0') {
1148 if (SDL_tolower((unsigned char) text[index + 1]) == 'x') {
1149 radix = 16;
1150 } else {
1151 radix = 8;
1152 }
1153 }
1154 }
1155 /* Fall through to %d handling */
1156 case 'd':
1157 if (inttype == DO_LONGLONG) {
1158 Sint64 value;
1159 advance = SDL_ScanLongLong(text, radix, &value);
1160 text += advance;
1161 if (advance && !suppress) {
1162 Sint64 *valuep = va_arg(ap, Sint64 *);
1163 *valuep = value;
1164 ++retval;
1165 }
1166 } else {
1167 long value;
1168 advance = SDL_ScanLong(text, radix, &value);
1169 text += advance;
1170 if (advance && !suppress) {
1171 switch (inttype) {
1172 case DO_SHORT:
1173 {
1174 short *valuep = va_arg(ap, short *);
1175 *valuep = (short) value;
1176 }
1177 break;
1178 case DO_INT:
1179 {
1180 int *valuep = va_arg(ap, int *);
1181 *valuep = (int) value;
1182 }
1183 break;
1184 case DO_LONG:
1185 {
1186 long *valuep = va_arg(ap, long *);
1187 *valuep = value;
1188 }
1189 break;
1190 case DO_LONGLONG:
1191 /* Handled above */
1192 break;
1193 }
1194 ++retval;
1195 }
1196 }
1197 done = SDL_TRUE;
1198 break;
1199 case 'o':
1200 if (radix == 10) {
1201 radix = 8;
1202 }
1203 /* Fall through to unsigned handling */
1204 case 'x':
1205 case 'X':
1206 if (radix == 10) {
1207 radix = 16;
1208 }
1209 /* Fall through to unsigned handling */
1210 case 'u':
1211 if (inttype == DO_LONGLONG) {
1212 Uint64 value = 0;
1213 advance = SDL_ScanUnsignedLongLong(text, radix, &value);
1214 text += advance;
1215 if (advance && !suppress) {
1216 Uint64 *valuep = va_arg(ap, Uint64 *);
1217 *valuep = value;
1218 ++retval;
1219 }
1220 } else {
1221 unsigned long value = 0;
1222 advance = SDL_ScanUnsignedLong(text, radix, &value);
1223 text += advance;
1224 if (advance && !suppress) {
1225 switch (inttype) {
1226 case DO_SHORT:
1227 {
1228 short *valuep = va_arg(ap, short *);
1229 *valuep = (short) value;
1230 }
1231 break;
1232 case DO_INT:
1233 {
1234 int *valuep = va_arg(ap, int *);
1235 *valuep = (int) value;
1236 }
1237 break;
1238 case DO_LONG:
1239 {
1240 long *valuep = va_arg(ap, long *);
1241 *valuep = value;
1242 }
1243 break;
1244 case DO_LONGLONG:
1245 /* Handled above */
1246 break;
1247 }
1248 ++retval;
1249 }
1250 }
1251 done = SDL_TRUE;
1252 break;
1253 case 'p':
1254 {
1255 uintptr_t value = 0;
1256 advance = SDL_ScanUintPtrT(text, 16, &value);
1257 text += advance;
1258 if (advance && !suppress) {
1259 void **valuep = va_arg(ap, void **);
1260 *valuep = (void *) value;
1261 ++retval;
1262 }
1263 }
1264 done = SDL_TRUE;
1265 break;
1266 case 'f':
1267 {
1268 double value;
1269 advance = SDL_ScanFloat(text, &value);
1270 text += advance;
1271 if (advance && !suppress) {
1272 float *valuep = va_arg(ap, float *);
1273 *valuep = (float) value;
1274 ++retval;
1275 }
1276 }
1277 done = SDL_TRUE;
1278 break;
1279 case 's':
1280 if (suppress) {
1281 while (!SDL_isspace((unsigned char) *text)) {
1282 ++text;
1283 if (count) {
1284 if (--count == 0) {
1285 break;
1286 }
1287 }
1288 }
1289 } else {
1290 char *valuep = va_arg(ap, char *);
1291 while (!SDL_isspace((unsigned char) *text)) {
1292 *valuep++ = *text++;
1293 if (count) {
1294 if (--count == 0) {
1295 break;
1296 }
1297 }
1298 }
1299 *valuep = '\0';
1300 ++retval;
1301 }
1302 done = SDL_TRUE;
1303 break;
1304 default:
1305 done = SDL_TRUE;
1306 break;
1307 }
1308 ++fmt;
1309 }
1310 continue;
1311 }
1312 if (*text == *fmt) {
1313 ++text;
1314 ++fmt;
1315 continue;
1316 }
1317 /* Text didn't match format specifier */
1318 break;
1319 }
1320
1321 return retval;
1322}
1323#endif /* HAVE_VSSCANF */
1324
1325int
1326SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
1327{
1328 va_list ap;
1329 int retval;
1330
1331 va_start(ap, fmt);
1332 retval = SDL_vsnprintf(text, maxlen, fmt, ap);
1333 va_end(ap);
1334
1335 return retval;
1336}
1337
1338#if defined(HAVE_LIBC) && defined(__WATCOMC__)
1339/* _vsnprintf() doesn't ensure nul termination */
1340int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
1341{
1342 int retval;
1343 if (!fmt) fmt = "";
1344 retval = _vsnprintf(text, maxlen, fmt, ap);
1345 if (maxlen > 0) text[maxlen-1] = '\0';
1346 if (retval < 0) retval = (int) maxlen;
1347 return retval;
1348}
1349#elif defined(HAVE_VSNPRINTF)
1350int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
1351{
1352 if (!fmt) {
1353 fmt = "";
1354 }
1355 return vsnprintf(text, maxlen, fmt, ap);
1356}
1357#else
1358 /* FIXME: implement more of the format specifiers */
1359typedef enum
1360{
1365
1366typedef struct
1367{
1368 SDL_bool left_justify; /* for now: ignored. */
1370 SDL_bool force_type; /* for now: used only by float printer, ignored otherwise. */
1377
1378static size_t
1379SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *string)
1380{
1381 size_t length = 0;
1382 size_t slen, sz;
1383
1384 if (string == NULL) {
1385 string = "(null)";
1386 }
1387
1388 sz = SDL_strlen(string);
1389 if (info && info->width > 0 && (size_t)info->width > sz) {
1390 char fill = info->pad_zeroes ? '0' : ' ';
1391 size_t width = info->width - sz;
1392 if (info->precision >= 0 && (size_t)info->precision < sz)
1393 width += sz - (size_t)info->precision;
1394 while (width-- > 0 && maxlen > 0) {
1395 *text++ = fill;
1396 ++length;
1397 --maxlen;
1398 }
1399 }
1400
1401 slen = SDL_strlcpy(text, string, maxlen);
1402 length += SDL_min(slen, maxlen);
1403
1404 if (info) {
1405 if (info->precision >= 0 && (size_t)info->precision < sz) {
1406 slen = (size_t)info->precision;
1407 if (slen < maxlen) {
1408 text[slen] = 0;
1409 length -= (sz - slen);
1410 }
1411 }
1412 if (info->force_case == SDL_CASE_LOWER) {
1414 } else if (info->force_case == SDL_CASE_UPPER) {
1416 }
1417 }
1418 return length;
1419}
1420
1421static void
1422SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info)
1423{/* left-pad num with zeroes. */
1424 size_t sz, pad, have_sign;
1425
1426 if (!info)
1427 return;
1428
1429 have_sign = 0;
1430 if (*num == '-' || *num == '+') {
1431 have_sign = 1;
1432 ++num;
1433 --maxlen;
1434 }
1435 sz = SDL_strlen(num);
1436 if (info->precision > 0 && sz < (size_t)info->precision) {
1437 pad = (size_t)info->precision - sz;
1438 if (pad + sz + 1 <= maxlen) { /* otherwise ignore the precision */
1439 SDL_memmove(num + pad, num, sz + 1);
1440 SDL_memset(num, '0', pad);
1441 }
1442 }
1443 info->precision = -1;/* so that SDL_PrintString() doesn't make a mess. */
1444
1445 if (info->pad_zeroes && info->width > 0 && (size_t)info->width > sz + have_sign) {
1446 /* handle here: spaces are added before the sign
1447 but zeroes must be placed _after_ the sign. */
1448 /* sz hasn't changed: we ignore pad_zeroes if a precision is given. */
1449 pad = (size_t)info->width - sz - have_sign;
1450 if (pad + sz + 1 <= maxlen) {
1451 SDL_memmove(num + pad, num, sz + 1);
1452 SDL_memset(num, '0', pad);
1453 }
1454 info->width = 0; /* so that SDL_PrintString() doesn't make a mess. */
1455 }
1456}
1457
1458static size_t
1459SDL_PrintLong(char *text, size_t maxlen, SDL_FormatInfo *info, long value)
1460{
1461 char num[130], *p = num;
1462
1463 if (info->force_sign && value >= 0L) {
1464 *p++ = '+';
1465 }
1466
1467 SDL_ltoa(value, p, info ? info->radix : 10);
1468 SDL_IntPrecisionAdjust(num, maxlen, info);
1469 return SDL_PrintString(text, maxlen, info, num);
1470}
1471
1472static size_t
1473SDL_PrintUnsignedLong(char *text, size_t maxlen, SDL_FormatInfo *info, unsigned long value)
1474{
1475 char num[130];
1476
1477 SDL_ultoa(value, num, info ? info->radix : 10);
1478 SDL_IntPrecisionAdjust(num, maxlen, info);
1479 return SDL_PrintString(text, maxlen, info, num);
1480}
1481
1482static size_t
1483SDL_PrintLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Sint64 value)
1484{
1485 char num[130], *p = num;
1486
1487 if (info->force_sign && value >= (Sint64)0) {
1488 *p++ = '+';
1489 }
1490
1491 SDL_lltoa(value, p, info ? info->radix : 10);
1492 SDL_IntPrecisionAdjust(num, maxlen, info);
1493 return SDL_PrintString(text, maxlen, info, num);
1494}
1495
1496static size_t
1498{
1499 char num[130];
1500
1501 SDL_ulltoa(value, num, info ? info->radix : 10);
1502 SDL_IntPrecisionAdjust(num, maxlen, info);
1503 return SDL_PrintString(text, maxlen, info, num);
1504}
1505
1506static size_t
1507SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
1508{
1509 int width;
1510 size_t len;
1511 size_t left = maxlen;
1512 char *textstart = text;
1513
1514 if (arg) {
1515 /* This isn't especially accurate, but hey, it's easy. :) */
1516 unsigned long value;
1517
1518 if (arg < 0) {
1519 if (left > 1) {
1520 *text = '-';
1521 --left;
1522 }
1523 ++text;
1524 arg = -arg;
1525 } else if (info->force_sign) {
1526 if (left > 1) {
1527 *text = '+';
1528 --left;
1529 }
1530 ++text;
1531 }
1532 value = (unsigned long) arg;
1534 if (len >= left) {
1535 text += (left > 1) ? left - 1 : 0;
1536 left = SDL_min(left, 1);
1537 } else {
1538 text += len;
1539 left -= len;
1540 }
1541 arg -= value;
1542 if (info->precision < 0) {
1543 info->precision = 6;
1544 }
1545 if (info->force_type || info->precision > 0) {
1546 int mult = 10;
1547 if (left > 1) {
1548 *text = '.';
1549 --left;
1550 }
1551 ++text;
1552 while (info->precision-- > 0) {
1553 value = (unsigned long) (arg * mult);
1555 if (len >= left) {
1556 text += (left > 1) ? left - 1 : 0;
1557 left = SDL_min(left, 1);
1558 } else {
1559 text += len;
1560 left -= len;
1561 }
1562 arg -= (double) value / mult;
1563 mult *= 10;
1564 }
1565 }
1566 } else {
1567 if (left > 1) {
1568 *text = '0';
1569 --left;
1570 }
1571 ++text;
1572 if (info->force_type) {
1573 if (left > 1) {
1574 *text = '.';
1575 --left;
1576 }
1577 ++text;
1578 }
1579 }
1580
1581 width = info->width - (int)(text - textstart);
1582 if (width > 0) {
1583 char fill = info->pad_zeroes ? '0' : ' ';
1584 char *end = text+left-1;
1585 len = (text - textstart);
1586 for (len = (text - textstart); len--; ) {
1587 if ((textstart+len+width) < end) {
1588 *(textstart+len+width) = *(textstart+len);
1589 }
1590 }
1591 len = (size_t)width;
1592 if (len >= left) {
1593 text += (left > 1) ? left - 1 : 0;
1594 left = SDL_min(left, 1);
1595 } else {
1596 text += len;
1597 left -= len;
1598 }
1599 while (len--) {
1600 if (textstart+len < end) {
1601 textstart[len] = fill;
1602 }
1603 }
1604 }
1605
1606 return (text - textstart);
1607}
1608
1609int
1610SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
1611{
1612 size_t left = maxlen;
1613 char *textstart = text;
1614
1615 if (!fmt) {
1616 fmt = "";
1617 }
1618 while (*fmt && left > 1) {
1619 if (*fmt == '%') {
1621 size_t len = 0;
1622 SDL_bool check_flag;
1623 SDL_FormatInfo info;
1624 enum
1625 {
1626 DO_INT,
1627 DO_LONG,
1628 DO_LONGLONG
1629 } inttype = DO_INT;
1630
1631 SDL_zero(info);
1632 info.radix = 10;
1633 info.precision = -1;
1634
1635 check_flag = SDL_TRUE;
1636 while (check_flag) {
1637 ++fmt;
1638 switch (*fmt) {
1639 case '-':
1640 info.left_justify = SDL_TRUE;
1641 break;
1642 case '+':
1643 info.force_sign = SDL_TRUE;
1644 break;
1645 case '#':
1646 info.force_type = SDL_TRUE;
1647 break;
1648 case '0':
1649 info.pad_zeroes = SDL_TRUE;
1650 break;
1651 default:
1652 check_flag = SDL_FALSE;
1653 break;
1654 }
1655 }
1656
1657 if (*fmt >= '0' && *fmt <= '9') {
1658 info.width = SDL_strtol(fmt, (char **)&fmt, 0);
1659 }
1660 else if (*fmt == '*') {
1661 ++fmt;
1662 info.width = va_arg(ap, int);
1663 }
1664
1665 if (*fmt == '.') {
1666 ++fmt;
1667 if (*fmt >= '0' && *fmt <= '9') {
1668 info.precision = SDL_strtol(fmt, (char **)&fmt, 0);
1669 } else if (*fmt == '*') {
1670 ++fmt;
1671 info.precision = va_arg(ap, int);
1672 } else {
1673 info.precision = 0;
1674 }
1675 if (info.precision < 0) {
1676 info.precision = 0;
1677 }
1678 }
1679
1680 while (!done) {
1681 switch (*fmt) {
1682 case '%':
1683 if (left > 1) {
1684 *text = '%';
1685 }
1686 len = 1;
1687 done = SDL_TRUE;
1688 break;
1689 case 'c':
1690 /* char is promoted to int when passed through (...) */
1691 if (left > 1) {
1692 *text = (char) va_arg(ap, int);
1693 }
1694 len = 1;
1695 done = SDL_TRUE;
1696 break;
1697 case 'h':
1698 /* short is promoted to int when passed through (...) */
1699 break;
1700 case 'l':
1701 if (inttype < DO_LONGLONG) {
1702 ++inttype;
1703 }
1704 break;
1705 case 'I':
1706 if (SDL_strncmp(fmt, "I64", 3) == 0) {
1707 fmt += 2;
1708 inttype = DO_LONGLONG;
1709 }
1710 break;
1711 case 'i':
1712 case 'd':
1713 if (info.precision >= 0) {
1714 info.pad_zeroes = SDL_FALSE;
1715 }
1716 switch (inttype) {
1717 case DO_INT:
1718 len = SDL_PrintLong(text, left, &info,
1719 (long) va_arg(ap, int));
1720 break;
1721 case DO_LONG:
1722 len = SDL_PrintLong(text, left, &info,
1723 va_arg(ap, long));
1724 break;
1725 case DO_LONGLONG:
1726 len = SDL_PrintLongLong(text, left, &info,
1727 va_arg(ap, Sint64));
1728 break;
1729 }
1730 done = SDL_TRUE;
1731 break;
1732 case 'p':
1733 case 'x':
1735 /* Fall through to 'X' handling */
1736 case 'X':
1737 if (info.force_case == SDL_CASE_NOCHANGE) {
1739 }
1740 if (info.radix == 10) {
1741 info.radix = 16;
1742 }
1743 if (*fmt == 'p') {
1744 inttype = DO_LONG;
1745 }
1746 /* Fall through to unsigned handling */
1747 case 'o':
1748 if (info.radix == 10) {
1749 info.radix = 8;
1750 }
1751 /* Fall through to unsigned handling */
1752 case 'u':
1753 info.force_sign = SDL_FALSE;
1754 if (info.precision >= 0) {
1755 info.pad_zeroes = SDL_FALSE;
1756 }
1757 switch (inttype) {
1758 case DO_INT:
1760 (unsigned long)
1761 va_arg(ap, unsigned int));
1762 break;
1763 case DO_LONG:
1765 va_arg(ap, unsigned long));
1766 break;
1767 case DO_LONGLONG:
1769 va_arg(ap, Uint64));
1770 break;
1771 }
1772 done = SDL_TRUE;
1773 break;
1774 case 'f':
1775 len = SDL_PrintFloat(text, left, &info, va_arg(ap, double));
1776 done = SDL_TRUE;
1777 break;
1778 case 'S':
1779 {
1780 /* In practice this is used on Windows for WCHAR strings */
1781 wchar_t *wide_arg = va_arg(ap, wchar_t *);
1782 char *arg = SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(wide_arg), (SDL_wcslen(wide_arg)+1)*sizeof(*wide_arg));
1783 info.pad_zeroes = SDL_FALSE;
1784 len = SDL_PrintString(text, left, &info, arg);
1785 SDL_free(arg);
1786 done = SDL_TRUE;
1787 }
1788 break;
1789 case 's':
1790 info.pad_zeroes = SDL_FALSE;
1791 len = SDL_PrintString(text, left, &info, va_arg(ap, char *));
1792 done = SDL_TRUE;
1793 break;
1794 default:
1795 done = SDL_TRUE;
1796 break;
1797 }
1798 ++fmt;
1799 }
1800 if (len >= left) {
1801 text += (left > 1) ? left - 1 : 0;
1802 left = SDL_min(left, 1);
1803 } else {
1804 text += len;
1805 left -= len;
1806 }
1807 } else {
1808 *text++ = *fmt++;
1809 --left;
1810 }
1811 }
1812 if (left > 0) {
1813 *text = '\0';
1814 }
1815 return (int)(text - textstart);
1816}
1817#endif /* HAVE_VSNPRINTF */
1818
1819/* vi: set ts=4 sw=4 expandtab: */
unsigned int uintptr_t
unsigned int size_t
#define SDL_isdigit
#define SDL_toupper
#define SDL_malloc
#define SDL_free
#define SDL_iconv_string
#define SDL_isspace
#define SDL_tolower
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 Uint32 return SDL_AudioCVT SDL_AudioFormat Uint8 int SDL_AudioFormat Uint8 int return Uint8 const Uint8 Uint32 int const char return return return return return return return return Uint32 return Uint32 SDL_Event return SDL_Event int return SDL_EventFilter void SDL_EventFilter void SDL_EventFilter void int return const char const char return SDL_JoystickGUID return int return int return SDL_GameController return int return const char return SDL_GameController SDL_GameControllerAxis return const char return SDL_GameController SDL_GameControllerButton return SDL_GameController SDL_RWops return SDL_TouchID SDL_RWops return int return int return return SDL_Joystick return SDL_Haptic SDL_Haptic return SDL_Haptic return SDL_Haptic SDL_HapticEffect return SDL_Haptic int Uint32 return SDL_Haptic int SDL_Haptic int return SDL_Haptic return SDL_Haptic return SDL_Haptic return SDL_Haptic return const char const char return const char SDL_HintCallback void int return SDL_Joystick return SDL_Joystick return const char return SDL_Joystick return SDL_Joystick return SDL_Joystick return int return SDL_Joystick int return SDL_Joystick int return return return SDL_Scancode return SDL_Scancode return SDL_Keycode return return const char return void int SDL_LogPriority SDL_LogOutputFunction void Uint32 const char const char SDL_Window return int int return SDL_Window int int return SDL_Surface int int return SDL_Cursor return int return SDL_mutex return SDL_mutex return Uint32 return SDL_sem return SDL_sem Uint32 return SDL_sem return SDL_cond SDL_cond return SDL_cond SDL_mutex Uint32 return Uint32 int Uint32 Uint32 Uint32 Uint32 return Uint32 return int return SDL_Palette const SDL_Color int int return const SDL_PixelFormat Uint8 Uint8 Uint8 return Uint32 const SDL_PixelFormat Uint8 Uint8 Uint8 float Uint16 int int return const SDL_Rect const SDL_Rect SDL_Rect return const SDL_Point int const SDL_Rect SDL_Rect return return int int Uint32 SDL_Window SDL_Renderer return SDL_Surface return SDL_Renderer SDL_RendererInfo return SDL_Renderer Uint32 int int int return SDL_Texture Uint32 int int int return SDL_Texture Uint8 Uint8 Uint8 return SDL_Texture Uint8 return SDL_Texture SDL_BlendMode return SDL_Texture const SDL_Rect const Uint8 int const Uint8 int const Uint8 int return SDL_Texture SDL_Renderer SDL_Texture return SDL_Renderer int int return SDL_Renderer const SDL_Rect return SDL_Renderer const SDL_Rect return SDL_Renderer float float return SDL_Renderer Uint8 Uint8 Uint8 Uint8 return SDL_Renderer SDL_BlendMode return SDL_Renderer return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Rect int return SDL_Renderer const SDL_Rect int return SDL_Renderer SDL_Texture const SDL_Rect const SDL_Rect const double const SDL_Point const SDL_RendererFlip return SDL_Renderer SDL_Renderer SDL_Texture return void int return return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops Uint16 return SDL_RWops Uint32 return SDL_RWops Uint64 return const char unsigned int unsigned int unsigned int unsigned int Uint32 return SDL_Window SDL_Surface SDL_WindowShapeMode return size_t return void size_t return const char return void size_t size_t int(*) int return int return int size_t retur SDL_IN_BYTECAP)(c) const void *b
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 Uint32 return SDL_AudioCVT SDL_AudioFormat Uint8 int SDL_AudioFormat Uint8 int return Uint8 const Uint8 Uint32 int const char return return return return return return return return Uint32 return Uint32 SDL_Event return SDL_Event int return SDL_EventFilter void SDL_EventFilter void SDL_EventFilter void int return const char const char return SDL_JoystickGUID return int return int return SDL_GameController return int return const char return SDL_GameController SDL_GameControllerAxis return const char return SDL_GameController SDL_GameControllerButton return SDL_GameController SDL_RWops return SDL_TouchID SDL_RWops return int return int return return SDL_Joystick return SDL_Haptic SDL_Haptic return SDL_Haptic return SDL_Haptic SDL_HapticEffect return SDL_Haptic int Uint32 return SDL_Haptic int SDL_Haptic int return SDL_Haptic return SDL_Haptic return SDL_Haptic return SDL_Haptic return const char const char return const char SDL_HintCallback void int return SDL_Joystick return SDL_Joystick return const char return SDL_Joystick return SDL_Joystick return SDL_Joystick return int return SDL_Joystick int return SDL_Joystick int return return return SDL_Scancode return SDL_Scancode return SDL_Keycode return return const char return void int SDL_LogPriority SDL_LogOutputFunction void Uint32 const char const char SDL_Window return int int return SDL_Window int int return SDL_Surface int int return SDL_Cursor return int return SDL_mutex return SDL_mutex return Uint32 return SDL_sem return SDL_sem Uint32 return SDL_sem return SDL_cond SDL_cond return SDL_cond SDL_mutex Uint32 return Uint32 int Uint32 Uint32 Uint32 Uint32 return Uint32 return int return SDL_Palette const SDL_Color int int return const SDL_PixelFormat Uint8 Uint8 Uint8 return Uint32 const SDL_PixelFormat Uint8 Uint8 Uint8 float Uint16 int int return const SDL_Rect const SDL_Rect SDL_Rect return const SDL_Point int const SDL_Rect SDL_Rect return return int int Uint32 SDL_Window SDL_Renderer return SDL_Surface return SDL_Renderer SDL_RendererInfo return SDL_Renderer Uint32 int int int return SDL_Texture Uint32 int int int return SDL_Texture Uint8 Uint8 Uint8 return SDL_Texture Uint8 return SDL_Texture SDL_BlendMode return SDL_Texture const SDL_Rect const Uint8 int const Uint8 int const Uint8 int return SDL_Texture SDL_Renderer SDL_Texture return SDL_Renderer int int return SDL_Renderer const SDL_Rect return SDL_Renderer const SDL_Rect return SDL_Renderer float float return SDL_Renderer Uint8 Uint8 Uint8 Uint8 return SDL_Renderer SDL_BlendMode return SDL_Renderer return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Rect int return SDL_Renderer const SDL_Rect int return SDL_Renderer SDL_Texture const SDL_Rect const SDL_Rect const double const SDL_Point const SDL_RendererFlip return SDL_Renderer SDL_Renderer SDL_Texture return void int return return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops Uint16 return SDL_RWops Uint32 return SDL_RWops Uint64 return const char unsigned int unsigned int unsigned int unsigned int Uint32 return SDL_Window SDL_Surface SDL_WindowShapeMode return size_t return void size_t return const char return void size_t size_t int(*) int return int return int size_t return size_t return const wchar_t retur SDL_INOUT_Z_CAP)(c) wchar_t *a
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 Uint32 return SDL_AudioCVT SDL_AudioFormat Uint8 int SDL_AudioFormat Uint8 int return Uint8 const Uint8 Uint32 int const char return return return return return return return return Uint32 return Uint32 SDL_Event return SDL_Event int return SDL_EventFilter void SDL_EventFilter void SDL_EventFilter void int return const char const char return SDL_JoystickGUID return int return int return SDL_GameController return int return const char return SDL_GameController SDL_GameControllerAxis return const char return SDL_GameController SDL_GameControllerButton return SDL_GameController SDL_RWops return SDL_TouchID SDL_RWops return int return int return return SDL_Joystick return SDL_Haptic SDL_Haptic return SDL_Haptic return SDL_Haptic SDL_HapticEffect return SDL_Haptic int Uint32 return SDL_Haptic int SDL_Haptic int return SDL_Haptic return SDL_Haptic return SDL_Haptic return SDL_Haptic return const char const char return const char SDL_HintCallback void int return SDL_Joystick return SDL_Joystick return const char return SDL_Joystick return SDL_Joystick return SDL_Joystick return int return SDL_Joystick int return SDL_Joystick int return return return SDL_Scancode return SDL_Scancode return SDL_Keycode return return const char return void int SDL_LogPriority SDL_LogOutputFunction void Uint32 const char const char SDL_Window return int int return SDL_Window int int return SDL_Surface int int return SDL_Cursor return int return SDL_mutex return SDL_mutex return Uint32 return SDL_sem return SDL_sem Uint32 return SDL_sem return SDL_cond SDL_cond return SDL_cond SDL_mutex Uint32 return Uint32 int Uint32 Uint32 Uint32 Uint32 return Uint32 return int return SDL_Palette const SDL_Color int int return const SDL_PixelFormat Uint8 Uint8 Uint8 return Uint32 const SDL_PixelFormat Uint8 Uint8 Uint8 float Uint16 int int return const SDL_Rect const SDL_Rect SDL_Rect return const SDL_Point int const SDL_Rect SDL_Rect return return int int Uint32 SDL_Window SDL_Renderer return SDL_Surface return SDL_Renderer SDL_RendererInfo return SDL_Renderer Uint32 int int int return SDL_Texture Uint32 int int int return SDL_Texture Uint8 Uint8 Uint8 return SDL_Texture Uint8 return SDL_Texture SDL_BlendMode return SDL_Texture const SDL_Rect const Uint8 int const Uint8 int const Uint8 int return SDL_Texture SDL_Renderer SDL_Texture return SDL_Renderer int int return SDL_Renderer const SDL_Rect return SDL_Renderer const SDL_Rect return SDL_Renderer float float return SDL_Renderer Uint8 Uint8 Uint8 Uint8 return SDL_Renderer SDL_BlendMode return SDL_Renderer return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Rect int return SDL_Renderer const SDL_Rect int return SDL_Renderer SDL_Texture const SDL_Rect const SDL_Rect const double const SDL_Point const SDL_RendererFlip return SDL_Renderer SDL_Renderer SDL_Texture return void int return return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops Uint16 return SDL_RWops Uint32 return SDL_RWops Uint64 return const char unsigned int unsigned int unsigned int unsigned int Uint32 return SDL_Window SDL_Surface SDL_WindowShapeMode return size_t return void size_t return const char return void size_t size_t int(*) int return int retur SDL_OUT_BYTECAP)(c) void *a
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 Uint32 return SDL_AudioCVT SDL_AudioFormat Uint8 int SDL_AudioFormat Uint8 int return Uint8 const Uint8 Uint32 int const char return return return return return return return return Uint32 return Uint32 SDL_Event return SDL_Event int return SDL_EventFilter void SDL_EventFilter void SDL_EventFilter void int return const char const char return SDL_JoystickGUID return int return int return SDL_GameController return int return const char return SDL_GameController SDL_GameControllerAxis return const char return SDL_GameController SDL_GameControllerButton return SDL_GameController SDL_RWops return SDL_TouchID SDL_RWops return int return int return return SDL_Joystick return SDL_Haptic SDL_Haptic return SDL_Haptic return SDL_Haptic SDL_HapticEffect return SDL_Haptic int Uint32 return SDL_Haptic int SDL_Haptic int return SDL_Haptic return SDL_Haptic return SDL_Haptic return SDL_Haptic return const char const char return const char SDL_HintCallback void int return SDL_Joystick return SDL_Joystick return const char return SDL_Joystick return SDL_Joystick return SDL_Joystick return int return SDL_Joystick int return SDL_Joystick int return return return SDL_Scancode return SDL_Scancode return SDL_Keycode return return const char return void int SDL_LogPriority SDL_LogOutputFunction void Uint32 const char const char SDL_Window return int int return SDL_Window int int return SDL_Surface int int return SDL_Cursor return int return SDL_mutex return SDL_mutex return Uint32 return SDL_sem return SDL_sem Uint32 return SDL_sem return SDL_cond SDL_cond return SDL_cond SDL_mutex Uint32 return Uint32 int Uint32 Uint32 Uint32 Uint32 return Uint32 return int return SDL_Palette const SDL_Color int int return const SDL_PixelFormat Uint8 Uint8 Uint8 return Uint32 const SDL_PixelFormat Uint8 Uint8 Uint8 float Uint16 int int return const SDL_Rect const SDL_Rect SDL_Rect return const SDL_Point int const SDL_Rect SDL_Rect return return int int Uint32 SDL_Window SDL_Renderer return SDL_Surface return SDL_Renderer SDL_RendererInfo return SDL_Renderer Uint32 int int int return SDL_Texture Uint32 int int int return SDL_Texture Uint8 Uint8 Uint8 return SDL_Texture Uint8 return SDL_Texture SDL_BlendMode return SDL_Texture const SDL_Rect const Uint8 int const Uint8 int const Uint8 int return SDL_Texture SDL_Renderer SDL_Texture return SDL_Renderer int int return SDL_Renderer const SDL_Rect return SDL_Renderer const SDL_Rect return SDL_Renderer float float return SDL_Renderer Uint8 Uint8 Uint8 Uint8 return SDL_Renderer SDL_BlendMode return SDL_Renderer return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Point int return SDL_Renderer const SDL_Rect int return SDL_Renderer const SDL_Rect int return SDL_Renderer SDL_Texture const SDL_Rect const SDL_Rect const double const SDL_Point const SDL_RendererFlip return SDL_Renderer SDL_Renderer SDL_Texture return void int return return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops return SDL_RWops Uint16 return SDL_RWops Uint32 return SDL_RWops Uint64 return const char unsigned int unsigned int unsigned int unsigned int Uint32 return SDL_Window SDL_Surface SDL_WindowShapeMode return size_t return void size_t return const char return void size_t size_t int(*) int return int return int size_t return size_t return const wchar_t return const wchar_t size_t retur SDL_OUT_Z_CAP)(c) char *a
#define memcpy
Definition: SDL_malloc.c:630
#define memset
Definition: SDL_malloc.c:627
GLuint GLuint end
Definition: SDL_opengl.h:1571
const GLdouble * v
Definition: SDL_opengl.h:2064
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
GLboolean GLboolean GLboolean b
GLenum src
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
GLuint index
GLint left
GLenum GLsizei len
GLboolean GLboolean GLboolean GLboolean a
const GLubyte * c
GLenum GLenum dst
GLfloat GLfloat p
GLuint GLsizei GLsizei * length
GLuint num
GLsizei const GLfloat * value
GLsizei const GLchar *const * string
#define memmove
Definition: SDL_qsort.c:59
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
SDL_bool
Definition: SDL_stdinc.h:162
@ SDL_TRUE
Definition: SDL_stdinc.h:164
@ SDL_FALSE
Definition: SDL_stdinc.h:163
#define SDL_SCANF_FORMAT_STRING
Definition: SDL_stdinc.h:301
uint32_t Uint32
Definition: SDL_stdinc.h:203
#define SDL_const_cast(type, expression)
Definition: SDL_stdinc.h:139
#define SDL_PRINTF_FORMAT_STRING
Definition: SDL_stdinc.h:300
uint64_t Uint64
Definition: SDL_stdinc.h:216
#define SDL_min(x, y)
Definition: SDL_stdinc.h:406
uint8_t Uint8
Definition: SDL_stdinc.h:179
int64_t Sint64
Definition: SDL_stdinc.h:210
static int UTF8_TrailingBytes(unsigned char c)
Definition: SDL_string.c:39
char * SDL_strlwr(char *string)
Definition: SDL_string.c:623
double SDL_strtod(const char *string, char **endp)
Definition: SDL_string.c:928
static size_t SDL_ScanLong(const char *text, int radix, long *valuep)
Definition: SDL_string.c:53
static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t *valuep)
Definition: SDL_string.c:126
SDL_letter_case
Definition: SDL_string.c:1360
@ SDL_CASE_LOWER
Definition: SDL_string.c:1362
@ SDL_CASE_UPPER
Definition: SDL_string.c:1363
@ SDL_CASE_NOCHANGE
Definition: SDL_string.c:1361
static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 *valuep)
Definition: SDL_string.c:158
static size_t SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *string)
Definition: SDL_string.c:1379
int SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Definition: SDL_string.c:1326
int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
Definition: SDL_string.c:1610
size_t SDL_strlen(const char *string)
Definition: SDL_string.c:411
static size_t SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 *valuep)
Definition: SDL_string.c:199
size_t SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
Definition: SDL_string.c:466
char * SDL_strrchr(const char *string, int c)
Definition: SDL_string.c:656
int SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
Definition: SDL_string.c:961
static const char ntoa_table[]
Definition: SDL_string.c:693
#define UTF8_IsTrailingByte(c)
Definition: SDL_string.c:37
static size_t SDL_PrintUnsignedLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Uint64 value)
Definition: SDL_string.c:1497
void * SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
Definition: SDL_string.c:315
size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
Definition: SDL_string.c:513
char * SDL_strdup(const char *string)
Definition: SDL_string.c:578
#define SDL_isupperhex(X)
Definition: SDL_string.c:32
void * SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
Definition: SDL_string.c:266
unsigned long SDL_strtoul(const char *string, char **endp, int base)
Definition: SDL_string.c:853
int SDL_strcasecmp(const char *str1, const char *str2)
Definition: SDL_string.c:981
static size_t SDL_PrintLong(char *text, size_t maxlen, SDL_FormatInfo *info, long value)
Definition: SDL_string.c:1459
char * SDL_strstr(const char *haystack, const char *needle)
Definition: SDL_string.c:675
size_t SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
Definition: SDL_string.c:450
size_t SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
Definition: SDL_string.c:497
char * SDL_strchr(const char *string, int c)
Definition: SDL_string.c:638
long SDL_strtol(const char *string, char **endp, int base)
Definition: SDL_string.c:828
int SDL_wcscmp(const wchar_t *str1, const wchar_t *str2)
Definition: SDL_string.c:481
static size_t SDL_PrintLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Sint64 value)
Definition: SDL_string.c:1483
static size_t SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
Definition: SDL_string.c:1507
void * SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
Definition: SDL_string.c:368
int SDL_memcmp(const void *s1, const void *s2, size_t len)
Definition: SDL_string.c:392
Uint64 SDL_strtoull(const char *string, char **endp, int base)
Definition: SDL_string.c:903
int SDL_vsscanf(const char *text, const char *fmt, va_list ap)
Definition: SDL_string.c:1052
char * SDL_itoa(int value, char *string, int radix)
Definition: SDL_string.c:702
char * SDL_ulltoa(Uint64 value, char *string, int radix)
Definition: SDL_string.c:785
int SDL_strcmp(const char *str1, const char *str2)
Definition: SDL_string.c:945
double SDL_atof(const char *string)
Definition: SDL_string.c:818
static void SDL_IntPrecisionAdjust(char *num, size_t maxlen, SDL_FormatInfo *info)
Definition: SDL_string.c:1422
char * SDL_strrev(char *string)
Definition: SDL_string.c:589
size_t SDL_wcslen(const wchar_t *string)
Definition: SDL_string.c:436
char * SDL_uitoa(unsigned int value, char *string, int radix)
Definition: SDL_string.c:712
wchar_t * SDL_wcsdup(const wchar_t *string)
Definition: SDL_string.c:425
char * SDL_ltoa(long value, char *string, int radix)
Definition: SDL_string.c:722
#define SDL_islowerhex(X)
Definition: SDL_string.c:33
char * SDL_lltoa(Sint64 value, char *string, int radix)
Definition: SDL_string.c:766
#define UTF8_IsLeadByte(c)
Definition: SDL_string.c:36
int SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt,...)
Definition: SDL_string.c:1034
static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
Definition: SDL_string.c:94
char * SDL_ultoa(unsigned long value, char *string, int radix)
Definition: SDL_string.c:741
Sint64 SDL_strtoll(const char *string, char **endp, int base)
Definition: SDL_string.c:878
int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
Definition: SDL_string.c:1005
size_t SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
Definition: SDL_string.c:563
int SDL_atoi(const char *string)
Definition: SDL_string.c:809
char * SDL_strupr(char *string)
Definition: SDL_string.c:608
static size_t SDL_PrintUnsignedLong(char *text, size_t maxlen, SDL_FormatInfo *info, unsigned long value)
Definition: SDL_string.c:1473
size_t SDL_utf8strlen(const char *str)
Definition: SDL_string.c:546
static size_t SDL_ScanFloat(const char *text, double *valuep)
Definition: SDL_string.c:231
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:167
int done
Definition: checkkeys.c:28
SDL_bool pad_zeroes
Definition: SDL_string.c:1371
SDL_bool left_justify
Definition: SDL_string.c:1368
SDL_bool force_sign
Definition: SDL_string.c:1369
SDL_bool force_type
Definition: SDL_string.c:1370
SDL_letter_case force_case
Definition: SDL_string.c:1372
SDL_bool retval
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47