comparison src/stdlib/SDL_string.c @ 1336:3692456e7b0f

Use SDL_ prefixed versions of C library functions. FIXME: Change #include <stdlib.h> to #include "SDL_stdlib.h" Change #include <string.h> to #include "SDL_string.h" Make sure nothing else broke because of this...
author Sam Lantinga <slouken@libsdl.org>
date Tue, 07 Feb 2006 06:59:48 +0000
parents 450721ad5436
children 604d73db6802
comparison
equal deleted inserted replaced
1335:c39265384763 1336:3692456e7b0f
373 #endif 373 #endif
374 374
375 #ifndef HAVE_STRRCHR 375 #ifndef HAVE_STRRCHR
376 char *SDL_strrchr(const char *string, int c) 376 char *SDL_strrchr(const char *string, int c)
377 { 377 {
378 const char *bufp = string + strlen(string) - 1; 378 const char *bufp = string + SDL_strlen(string) - 1;
379 while ( bufp >= string ) { 379 while ( bufp >= string ) {
380 if ( *bufp == c ) { 380 if ( *bufp == c ) {
381 return (char *)bufp; 381 return (char *)bufp;
382 } 382 }
383 } 383 }
386 #endif 386 #endif
387 387
388 #ifndef HAVE_STRSTR 388 #ifndef HAVE_STRSTR
389 char *SDL_strstr(const char *haystack, const char *needle) 389 char *SDL_strstr(const char *haystack, const char *needle)
390 { 390 {
391 size_t length = strlen(needle); 391 size_t length = SDL_strlen(needle);
392 while ( *haystack ) { 392 while ( *haystack ) {
393 if ( strncmp(haystack, needle, length) == 0 ) { 393 if ( SDL_strncmp(haystack, needle, length) == 0 ) {
394 return (char *)haystack; 394 return (char *)haystack;
395 } 395 }
396 } 396 }
397 return NULL; 397 return NULL;
398 } 398 }
427 } 427 }
428 *bufp = '\0'; 428 *bufp = '\0';
429 429
430 /* The numbers went into the string backwards. :) */ 430 /* The numbers went into the string backwards. :) */
431 if ( *string == '-' ) { 431 if ( *string == '-' ) {
432 _strrev(string+1); 432 SDL_strrev(string+1);
433 } else { 433 } else {
434 _strrev(string); 434 SDL_strrev(string);
435 } 435 }
436 436
437 return string; 437 return string;
438 } 438 }
439 #endif 439 #endif
452 *bufp++ = '0'; 452 *bufp++ = '0';
453 } 453 }
454 *bufp = '\0'; 454 *bufp = '\0';
455 455
456 /* The numbers went into the string backwards. :) */ 456 /* The numbers went into the string backwards. :) */
457 _strrev(string); 457 SDL_strrev(string);
458 458
459 return string; 459 return string;
460 } 460 }
461 #endif 461 #endif
462 462
495 } 495 }
496 *bufp = '\0'; 496 *bufp = '\0';
497 497
498 /* The numbers went into the string backwards. :) */ 498 /* The numbers went into the string backwards. :) */
499 if ( *string == '-' ) { 499 if ( *string == '-' ) {
500 _strrev(string+1); 500 SDL_strrev(string+1);
501 } else { 501 } else {
502 _strrev(string); 502 SDL_strrev(string);
503 } 503 }
504 504
505 return string; 505 return string;
506 } 506 }
507 #endif 507 #endif
520 *bufp++ = '0'; 520 *bufp++ = '0';
521 } 521 }
522 *bufp = '\0'; 522 *bufp = '\0';
523 523
524 /* The numbers went into the string backwards. :) */ 524 /* The numbers went into the string backwards. :) */
525 _strrev(string); 525 SDL_strrev(string);
526 526
527 return string; 527 return string;
528 } 528 }
529 #endif 529 #endif
530 530
876 static size_t SDL_PrintLong(char *text, long value, int radix, size_t maxlen) 876 static size_t SDL_PrintLong(char *text, long value, int radix, size_t maxlen)
877 { 877 {
878 char num[130]; 878 char num[130];
879 size_t size; 879 size_t size;
880 880
881 _ltoa(value, num, radix); 881 SDL_ltoa(value, num, radix);
882 size = SDL_strlen(num); 882 size = SDL_strlen(num);
883 if ( size > maxlen ) { 883 if ( size > maxlen ) {
884 size = maxlen; 884 size = maxlen;
885 } 885 }
886 strncpy(text, num, size); 886 SDL_strncpy(text, num, size);
887 887
888 return size; 888 return size;
889 } 889 }
890 static size_t SDL_PrintUnsignedLong(char *text, unsigned long value, int radix, size_t maxlen) 890 static size_t SDL_PrintUnsignedLong(char *text, unsigned long value, int radix, size_t maxlen)
891 { 891 {
892 char num[130]; 892 char num[130];
893 size_t size; 893 size_t size;
894 894
895 _ultoa(value, num, radix); 895 SDL_ultoa(value, num, radix);
896 size = SDL_strlen(num); 896 size = SDL_strlen(num);
897 if ( size > maxlen ) { 897 if ( size > maxlen ) {
898 size = maxlen; 898 size = maxlen;
899 } 899 }
900 strncpy(text, num, size); 900 SDL_strncpy(text, num, size);
901 901
902 return size; 902 return size;
903 } 903 }
904 #ifdef SDL_HAS_64BIT_TYPE 904 #ifdef SDL_HAS_64BIT_TYPE
905 static size_t SDL_PrintLongLong(char *text, Sint64 value, int radix, size_t maxlen) 905 static size_t SDL_PrintLongLong(char *text, Sint64 value, int radix, size_t maxlen)
906 { 906 {
907 char num[130]; 907 char num[130];
908 size_t size; 908 size_t size;
909 909
910 _i64toa(value, num, radix); 910 SDL_lltoa(value, num, radix);
911 size = SDL_strlen(num); 911 size = SDL_strlen(num);
912 if ( size > maxlen ) { 912 if ( size > maxlen ) {
913 size = maxlen; 913 size = maxlen;
914 } 914 }
915 strncpy(text, num, size); 915 SDL_strncpy(text, num, size);
916 916
917 return size; 917 return size;
918 } 918 }
919 static size_t SDL_PrintUnsignedLongLong(char *text, Uint64 value, int radix, size_t maxlen) 919 static size_t SDL_PrintUnsignedLongLong(char *text, Uint64 value, int radix, size_t maxlen)
920 { 920 {
921 char num[130]; 921 char num[130];
922 size_t size; 922 size_t size;
923 923
924 _ui64toa(value, num, radix); 924 SDL_ulltoa(value, num, radix);
925 size = SDL_strlen(num); 925 size = SDL_strlen(num);
926 if ( size > maxlen ) { 926 if ( size > maxlen ) {
927 size = maxlen; 927 size = maxlen;
928 } 928 }
929 strncpy(text, num, size); 929 SDL_strncpy(text, num, size);
930 930
931 return size; 931 return size;
932 } 932 }
933 #endif /* SDL_HAS_64BIT_TYPE */ 933 #endif /* SDL_HAS_64BIT_TYPE */
934 static size_t SDL_PrintFloat(char *text, double arg, size_t maxlen) 934 static size_t SDL_PrintFloat(char *text, double arg, size_t maxlen)
1074 len = SDL_PrintUnsignedLong(text, va_arg(ap, unsigned long), radix, maxlen); 1074 len = SDL_PrintUnsignedLong(text, va_arg(ap, unsigned long), radix, maxlen);
1075 #endif 1075 #endif
1076 break; 1076 break;
1077 } 1077 }
1078 if ( do_lowercase ) { 1078 if ( do_lowercase ) {
1079 _strlwr(text); 1079 SDL_strlwr(text);
1080 } 1080 }
1081 done = SDL_TRUE; 1081 done = SDL_TRUE;
1082 break; 1082 break;
1083 case 'f': 1083 case 'f':
1084 len = SDL_PrintFloat(text, va_arg(ap, double), maxlen); 1084 len = SDL_PrintFloat(text, va_arg(ap, double), maxlen);