src/stdlib/SDL_string.c
changeset 8059 e70f5749f692
parent 7728 800313a3533d
child 8089 de8b6fdf6544
equal deleted inserted replaced
8058:8e4512b74223 8059:e70f5749f692
   663 #else
   663 #else
   664     char *bufp = string;
   664     char *bufp = string;
   665 
   665 
   666     if (value < 0) {
   666     if (value < 0) {
   667         *bufp++ = '-';
   667         *bufp++ = '-';
   668         value = -value;
   668         SDL_ultoa(-value, bufp, radix);
   669     }
   669     } else {
       
   670         SDL_ultoa(value, bufp, radix);
       
   671     }
       
   672 
       
   673     return string;
       
   674 #endif /* HAVE__LTOA */
       
   675 }
       
   676 
       
   677 char *
       
   678 SDL_ultoa(unsigned long value, char *string, int radix)
       
   679 {
       
   680 #if defined(HAVE__ULTOA)
       
   681     return _ultoa(value, string, radix);
       
   682 #else
       
   683     char *bufp = string;
       
   684 
   670     if (value) {
   685     if (value) {
   671         while (value > 0) {
   686         while (value > 0) {
   672             *bufp++ = ntoa_table[value % radix];
   687             *bufp++ = ntoa_table[value % radix];
   673             value /= radix;
   688             value /= radix;
   674         }
   689         }
   676         *bufp++ = '0';
   691         *bufp++ = '0';
   677     }
   692     }
   678     *bufp = '\0';
   693     *bufp = '\0';
   679 
   694 
   680     /* The numbers went into the string backwards. :) */
   695     /* The numbers went into the string backwards. :) */
   681     if (*string == '-') {
       
   682         SDL_strrev(string + 1);
       
   683     } else {
       
   684         SDL_strrev(string);
       
   685     }
       
   686 
       
   687     return string;
       
   688 #endif /* HAVE__LTOA */
       
   689 }
       
   690 
       
   691 char *
       
   692 SDL_ultoa(unsigned long value, char *string, int radix)
       
   693 {
       
   694 #if defined(HAVE__ULTOA)
       
   695     return _ultoa(value, string, radix);
       
   696 #else
       
   697     char *bufp = string;
       
   698 
       
   699     if (value) {
       
   700         while (value > 0) {
       
   701             *bufp++ = ntoa_table[value % radix];
       
   702             value /= radix;
       
   703         }
       
   704     } else {
       
   705         *bufp++ = '0';
       
   706     }
       
   707     *bufp = '\0';
       
   708 
       
   709     /* The numbers went into the string backwards. :) */
       
   710     SDL_strrev(string);
   696     SDL_strrev(string);
   711 
   697 
   712     return string;
   698     return string;
   713 #endif /* HAVE__ULTOA */
   699 #endif /* HAVE__ULTOA */
   714 }
   700 }
   721 #else
   707 #else
   722     char *bufp = string;
   708     char *bufp = string;
   723 
   709 
   724     if (value < 0) {
   710     if (value < 0) {
   725         *bufp++ = '-';
   711         *bufp++ = '-';
   726         value = -value;
   712         SDL_ulltoa(-value, bufp, radix);
   727     }
       
   728     if (value) {
       
   729         while (value > 0) {
       
   730             *bufp++ = ntoa_table[value % radix];
       
   731             value /= radix;
       
   732         }
       
   733     } else {
   713     } else {
   734         *bufp++ = '0';
   714         SDL_ulltoa(value, bufp, radix);
   735     }
       
   736     *bufp = '\0';
       
   737 
       
   738     /* The numbers went into the string backwards. :) */
       
   739     if (*string == '-') {
       
   740         SDL_strrev(string + 1);
       
   741     } else {
       
   742         SDL_strrev(string);
       
   743     }
   715     }
   744 
   716 
   745     return string;
   717     return string;
   746 #endif /* HAVE__I64TOA */
   718 #endif /* HAVE__I64TOA */
   747 }
   719 }