/[gnats]/gnats/libiberty/strtoul.c
ViewVC logotype

Diff of /gnats/libiberty/strtoul.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by jsm, Tue Oct 26 07:10:16 1999 UTC revision 1.3 by pdm, Mon Dec 10 23:03:26 2001 UTC
# Line 10  Line 10 
10   * 2. Redistributions in binary form must reproduce the above copyright   * 2. Redistributions in binary form must reproduce the above copyright
11   *    notice, this list of conditions and the following disclaimer in the   *    notice, this list of conditions and the following disclaimer in the
12   *    documentation and/or other materials provided with the distribution.   *    documentation and/or other materials provided with the distribution.
13   * 3. All advertising materials mentioning features or use of this software   * 3. [rescinded 22 July 1999]
  *    must display the following acknowledgement:  
  *      This product includes software developed by the University of  
  *      California, Berkeley and its contributors.  
14   * 4. Neither the name of the University nor the names of its contributors   * 4. Neither the name of the University nor the names of its contributors
15   *    may be used to endorse or promote products derived from this software   *    may be used to endorse or promote products derived from this software
16   *    without specific prior written permission.   *    without specific prior written permission.
# Line 31  Line 28 
28   * SUCH DAMAGE.   * SUCH DAMAGE.
29   */   */
30    
31    #ifdef HAVE_CONFIG_H
32    #include "config.h"
33    #endif
34    #ifdef HAVE_LIMITS_H
35  #include <limits.h>  #include <limits.h>
36  #include <ctype.h>  #endif
37    #ifdef HAVE_SYS_PARAM_H
38    #include <sys/param.h>
39    #endif
40  #include <errno.h>  #include <errno.h>
41    #ifdef NEED_DECLARATION_ERRNO
42    extern int errno;
43    #endif
44  #if 0  #if 0
45  #include <stdlib.h>  #include <stdlib.h>
46  #endif  #endif
47  #include "ansidecl.h"  #include "ansidecl.h"
48    #include "safe-ctype.h"
49    
50  #ifndef ULONG_MAX  #ifndef ULONG_MAX
51  #define ULONG_MAX       ((unsigned long)(~0L))          /* 0xFFFFFFFF */  #define ULONG_MAX       ((unsigned long)(~0L))          /* 0xFFFFFFFF */
# Line 66  strtoul(nptr, endptr, base) Line 74  strtoul(nptr, endptr, base)
74           */           */
75          do {          do {
76                  c = *s++;                  c = *s++;
77          } while (isspace(c));          } while (ISSPACE(c));
78          if (c == '-') {          if (c == '-') {
79                  neg = 1;                  neg = 1;
80                  c = *s++;                  c = *s++;
# Line 83  strtoul(nptr, endptr, base) Line 91  strtoul(nptr, endptr, base)
91          cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;          cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
92          cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;          cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;
93          for (acc = 0, any = 0;; c = *s++) {          for (acc = 0, any = 0;; c = *s++) {
94                  if (isdigit(c))                  if (ISDIGIT(c))
95                          c -= '0';                          c -= '0';
96                  else if (isalpha(c))                  else if (ISALPHA(c))
97                          c -= isupper(c) ? 'A' - 10 : 'a' - 10;                          c -= ISUPPER(c) ? 'A' - 10 : 'a' - 10;
98                  else                  else
99                          break;                          break;
100                  if (c >= base)                  if (c >= base)
101                          break;                          break;
102                  if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)                  if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
103                          any = -1;                          any = -1;
104                  else {                  else {
105                          any = 1;                          any = 1;

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26