Back to index

glibc  2.9
strtol.c
Go to the documentation of this file.
00001 /* Convert string representation of a number into an integer value.
00002    Copyright (C) 1991,92,94,95,96,97,98,99,2000,2001,2002,2003,2004,2007
00003        Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <stdlib.h>
00022 #include <wchar.h>
00023 #include <locale/localeinfo.h>
00024 
00025 #ifndef UNSIGNED
00026 # define UNSIGNED 0
00027 # define INT LONG int
00028 #else
00029 # define INT unsigned LONG int
00030 #endif
00031 
00032 #if UNSIGNED
00033 # ifdef USE_WIDE_CHAR
00034 #  ifdef QUAD
00035 #   define strtol wcstoull
00036 #   define __strtol_l __wcstoull_l
00037 #  else
00038 #   define strtol wcstoul
00039 #   define __strtol_l __wcstoul_l
00040 #  endif
00041 # else
00042 #  ifdef QUAD
00043 #   define strtol strtoull
00044 #   define __strtol_l __strtoull_l
00045 #  else
00046 #   define strtol strtoul
00047 #   define __strtol_l __strtoul_l
00048 #  endif
00049 # endif
00050 #else
00051 # ifdef USE_WIDE_CHAR
00052 #  ifdef QUAD
00053 #   define strtol wcstoll
00054 #   define __strtol_l __wcstoll_l
00055 #  else
00056 #   define strtol wcstol
00057 #   define __strtol_l __wcstol_l
00058 #  endif
00059 # else
00060 #  ifdef QUAD
00061 #   define strtol strtoll
00062 #   define __strtol_l __strtoll_l
00063 #  endif
00064 # endif
00065 #endif
00066 
00067 
00068 /* If QUAD is defined, we are defining `strtoll' or `strtoull',
00069    operating on `long long int's.  */
00070 #ifdef QUAD
00071 # define LONG long long
00072 #else
00073 # define LONG long
00074 #endif
00075 
00076 
00077 #ifdef USE_WIDE_CHAR
00078 # define STRING_TYPE wchar_t
00079 #else
00080 # define STRING_TYPE char
00081 #endif
00082 
00083 
00084 #define INTERNAL(X) INTERNAL1(X)
00085 #define INTERNAL1(X) __##X##_internal
00086 
00087 
00088 extern INT INTERNAL (__strtol_l) (const STRING_TYPE *, STRING_TYPE **, int,
00089                               int, __locale_t);
00090 
00091 
00092 INT
00093 INTERNAL (strtol) (nptr, endptr, base, group)
00094      const STRING_TYPE *nptr;
00095      STRING_TYPE **endptr;
00096      int base;
00097      int group;
00098 {
00099   return INTERNAL (__strtol_l) (nptr, endptr, base, group, _NL_CURRENT_LOCALE);
00100 }
00101 libc_hidden_def (INTERNAL (strtol))
00102 
00103 
00104 INT
00105 strtol (nptr, endptr, base)
00106      const STRING_TYPE *nptr;
00107      STRING_TYPE **endptr;
00108      int base;
00109 {
00110   return INTERNAL (__strtol_l) (nptr, endptr, base, 0, _NL_CURRENT_LOCALE);
00111 }
00112 libc_hidden_def (strtol)