X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=libiberty%2Fstrtol.c;h=acc7882192bb4e8bd114a0b34ef3ffe7645b03d9;hb=945e498ce8c441de3526643197e89fcba36b5d16;hp=db27ee0a8759ad020ad396ac499c406c444320d3;hpb=28e9041cc224267271fbcd8db22bea115912365b;p=pf3gnuchains%2Fgcc-fork.git diff --git a/libiberty/strtol.c b/libiberty/strtol.c index db27ee0a875..acc7882192b 100644 --- a/libiberty/strtol.c +++ b/libiberty/strtol.c @@ -10,10 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * 3. [rescinded 22 July 1999] * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -31,13 +28,39 @@ * SUCH DAMAGE. */ +/* + +@deftypefn Supplemental {long int} strtol (const char *@var{string}, char **@var{endptr}, int @var{base}) +@deftypefnx Supplemental {unsigned long int} strtoul (const char *@var{string}, char **@var{endptr}, int @var{base}) + +The @code{strtol} function converts the string in @var{string} to a +long integer value according to the given @var{base}, which must be +between 2 and 36 inclusive, or be the special value 0. If @var{base} +is 0, @code{strtol} will look for the prefixes @code{0} and @code{0x} +to indicate bases 8 and 16, respectively, else default to base 10. +When the base is 16 (either explicitly or implicitly), a prefix of +@code{0x} is allowed. The handling of @var{endptr} is as that of +@code{strtod} above. The @code{strtoul} function is the same, except +that the converted value is unsigned. + +@end deftypefn + +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#ifdef HAVE_LIMITS_H #include -#include +#endif +#ifdef HAVE_SYS_PARAM_H +#include +#endif #include -#if 0 -#include +#ifdef NEED_DECLARATION_ERRNO +extern int errno; #endif -#include "ansidecl.h" +#include "safe-ctype.h" /* FIXME: It'd be nice to configure around these, but the include files are too painful. These macros should at least be more portable than hardwired hex @@ -62,12 +85,9 @@ * alphabets and digits are each contiguous. */ long -strtol(nptr, endptr, base) - CONST char *nptr; - char **endptr; - register int base; +strtol(const char *nptr, char **endptr, register int base) { - register CONST char *s = nptr; + register const char *s = nptr; register unsigned long acc; register int c; register unsigned long cutoff; @@ -80,7 +100,7 @@ strtol(nptr, endptr, base) */ do { c = *s++; - } while (isspace(c)); + } while (ISSPACE(c)); if (c == '-') { neg = 1; c = *s++; @@ -116,15 +136,15 @@ strtol(nptr, endptr, base) cutlim = cutoff % (unsigned long)base; cutoff /= (unsigned long)base; for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) + if (ISDIGIT(c)) c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else if (ISALPHA(c)) + c -= ISUPPER(c) ? 'A' - 10 : 'a' - 10; else break; if (c >= base) break; - if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) any = -1; else { any = 1;