/[m4]/m4/gnulib/m4/strtol.c
ViewVC logotype

Diff of /m4/gnulib/m4/strtol.c

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

revision 1.1 by gary, Fri Sep 5 18:32:26 2003 UTC revision 1.2 by gary, Fri Sep 12 15:29:57 2003 UTC
# Line 1  Line 1 
1  /* Convert string representation of a number into an integer value.  /* Convert string representation of a number into an integer value.
2     Copyright (C) 1991,92,94,95,96,97,98,99 Free Software Foundation, Inc.     Copyright (C) 1991, 92, 94, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
3     This file is part of the GNU C Library.     NOTE: The canonical source of this file is maintained with the GNU C
4       Library.  Bugs can be reported to bug-glibc@gnu.org.
5    
6       This program is free software; you can redistribute it and/or modify it
7       under the terms of the GNU General Public License as published by the
8       Free Software Foundation; either version 2, or (at your option) any
9       later version.
10    
11     The GNU C Library is free software; you can redistribute it and/or     This program is distributed in the hope that it will be useful,
    modify it under the terms of the GNU Library General Public License as  
    published by the Free Software Foundation; either version 2 of the  
    License, or (at your option) any later version.  
   
    The GNU C Library is distributed in the hope that it will be useful,  
12     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     Library General Public License for more details.     GNU General Public License for more details.
15    
16     You should have received a copy of the GNU Library General Public     You should have received a copy of the GNU General Public License
17     License along with the GNU C Library; see the file COPYING.LIB.  If not,     along with this program; if not, write to the Free Software Foundation,
18     write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,     Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    Boston, MA 02111-1307, USA.  */  
19    
20  #if HAVE_CONFIG_H  #if HAVE_CONFIG_H
21  # include <config.h>  # include <config.h>
# Line 131  extern int errno; Line 131  extern int errno;
131  # define STRTOL_LONG_MIN LONG_LONG_MIN  # define STRTOL_LONG_MIN LONG_LONG_MIN
132  # define STRTOL_LONG_MAX LONG_LONG_MAX  # define STRTOL_LONG_MAX LONG_LONG_MAX
133  # define STRTOL_ULONG_MAX ULONG_LONG_MAX  # define STRTOL_ULONG_MAX ULONG_LONG_MAX
134    
135    /* The extra casts work around common compiler bugs,
136       e.g. Cray C 5.0.3.0 when t == time_t.  */
137    # ifndef TYPE_SIGNED
138    #  define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
139    # endif
140    # ifndef TYPE_MINIMUM
141    #  define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
142                                    ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \
143                                    : (t) 0))
144    # endif
145    # ifndef TYPE_MAXIMUM
146    #  define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
147    # endif
148    
149    # ifndef ULONG_LONG_MAX
150    #  define ULONG_LONG_MAX TYPE_MAXIMUM (unsigned long long)
151    # endif
152    # ifndef LONG_LONG_MAX
153    #  define LONG_LONG_MAX TYPE_MAXIMUM (long long int)
154    # endif
155    # ifndef LONG_LONG_MIN
156    #  define LONG_LONG_MIN TYPE_MINIMUM (long long int)
157    # endif
158    
159  # if __GNUC__ == 2 && __GNUC_MINOR__ < 7  # if __GNUC__ == 2 && __GNUC_MINOR__ < 7
160     /* Work around gcc bug with using this constant.  */     /* Work around gcc bug with using this constant.  */
161     static const unsigned long long int maxquad = ULONG_LONG_MAX;     static const unsigned long long int maxquad = ULONG_LONG_MAX;
# Line 185  extern int errno; Line 210  extern int errno;
210  #  define ISALPHA(Ch) iswalpha (Ch)  #  define ISALPHA(Ch) iswalpha (Ch)
211  #  define TOUPPER(Ch) towupper (Ch)  #  define TOUPPER(Ch) towupper (Ch)
212  # endif  # endif
213    #else
214    # if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII)
215    #  define IN_CTYPE_DOMAIN(c) 1
216  # else  # else
217  #  if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII)  #  define IN_CTYPE_DOMAIN(c) isascii(c)
218  #   define IN_CTYPE_DOMAIN(c) 1  # endif
219  #  else  # define L_(Ch) Ch
220  #   define IN_CTYPE_DOMAIN(c) isascii(c)  # define UCHAR_TYPE unsigned char
221  #  endif  # define STRING_TYPE char
 #  define L_(Ch) Ch  
 #  define UCHAR_TYPE unsigned char  
 #  define STRING_TYPE char  
222  # ifdef USE_IN_EXTENDED_LOCALE_MODEL  # ifdef USE_IN_EXTENDED_LOCALE_MODEL
223  #  define ISSPACE(Ch) __isspace_l ((Ch), loc)  #  define ISSPACE(Ch) __isspace_l ((Ch), loc)
224  #  define ISALPHA(Ch) __isalpha_l ((Ch), loc)  #  define ISALPHA(Ch) __isalpha_l ((Ch), loc)
# Line 205  extern int errno; Line 230  extern int errno;
230  # endif  # endif
231  #endif  #endif
232    
233  #ifdef __STDC__  /* For compilers which are ansi but don't define __STDC__, like SGI
234       Irix-4.0.5 cc, also check whether PROTOTYPES is defined. */
235    #if defined (__STDC__) || defined (PROTOTYPES)
236  # define INTERNAL(X) INTERNAL1(X)  # define INTERNAL(X) INTERNAL1(X)
237  # define INTERNAL1(X) __##X##_internal  # define INTERNAL1(X) __##X##_internal
238  # define WEAKNAME(X) WEAKNAME1(X)  # define WEAKNAME(X) WEAKNAME1(X)
# Line 344  INTERNAL (strtol) (nptr, endptr, base, g Line 371  INTERNAL (strtol) (nptr, endptr, base, g
371    
372    overflow = 0;    overflow = 0;
373    i = 0;    i = 0;
374    c = *s;    for (c = *s; c != L_('\0'); c = *++s)
   if (sizeof (long int) != sizeof (LONG int))  
375      {      {
376        unsigned long int j = 0;        if (s == end)
377        unsigned long int jmax = ULONG_MAX / base;          break;
378          if (c >= L_('0') && c <= L_('9'))
379        for (;c != L_('\0'); c = *++s)          c -= L_('0');
380          else if (ISALPHA (c))
381            c = TOUPPER (c) - L_('A') + 10;
382          else
383            break;
384          if ((int) c >= base)
385            break;
386          /* Check for overflow.  */
387          if (i > cutoff || (i == cutoff && c > cutlim))
388            overflow = 1;
389          else
390          {          {
391            if (s == end)            i *= (unsigned LONG int) base;
392              break;            i += c;
           if (c >= L_('0') && c <= L_('9'))  
             c -= L_('0');  
           else if (ISALPHA (c))  
             c = TOUPPER (c) - L_('A') + 10;  
           else  
             break;  
           if ((int) c >= base)  
             break;  
           /* Note that we never can have an overflow.  */  
           else if (j >= jmax)  
             {  
               /* We have an overflow.  Now use the long representation.  */  
               i = (unsigned LONG int) j;  
               goto use_long;  
             }  
           else  
             j = j * (unsigned long int) base + c;  
393          }          }
   
       i = (unsigned LONG int) j;  
394      }      }
   else  
     for (;c != L_('\0'); c = *++s)  
       {  
         if (s == end)  
           break;  
         if (c >= L_('0') && c <= L_('9'))  
           c -= L_('0');  
         else if (ISALPHA (c))  
           c = TOUPPER (c) - L_('A') + 10;  
         else  
           break;  
         if ((int) c >= base)  
           break;  
         /* Check for overflow.  */  
         if (i > cutoff || (i == cutoff && c > cutlim))  
           overflow = 1;  
         else  
           {  
           use_long:  
             i *= (unsigned LONG int) base;  
             i += c;  
           }  
       }  
395    
396    /* Check if anything actually happened.  */    /* Check if anything actually happened.  */
397    if (s == save)    if (s == save)

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

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