]> git.ipfire.org Git - thirdparty/glibc.git/blob - stdlib/strtol.c
Replace FSF snail mail address with URLs.
[thirdparty/glibc.git] / stdlib / strtol.c
1 /* Convert string representation of a number into an integer value.
2 Copyright (C) 1991,92,94,95,96,97,98,99,2000,2001,2002,2003,2004,2007
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 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
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
19
20 #include <stdlib.h>
21 #include <wchar.h>
22 #include <locale/localeinfo.h>
23
24 #ifndef UNSIGNED
25 # define UNSIGNED 0
26 # define INT LONG int
27 #else
28 # define INT unsigned LONG int
29 #endif
30
31 #if UNSIGNED
32 # ifdef USE_WIDE_CHAR
33 # ifdef QUAD
34 # define strtol wcstoull
35 # define __strtol_l __wcstoull_l
36 # else
37 # define strtol wcstoul
38 # define __strtol_l __wcstoul_l
39 # endif
40 # else
41 # ifdef QUAD
42 # define strtol strtoull
43 # define __strtol_l __strtoull_l
44 # else
45 # define strtol strtoul
46 # define __strtol_l __strtoul_l
47 # endif
48 # endif
49 #else
50 # ifdef USE_WIDE_CHAR
51 # ifdef QUAD
52 # define strtol wcstoll
53 # define __strtol_l __wcstoll_l
54 # else
55 # define strtol wcstol
56 # define __strtol_l __wcstol_l
57 # endif
58 # else
59 # ifdef QUAD
60 # define strtol strtoll
61 # define __strtol_l __strtoll_l
62 # endif
63 # endif
64 #endif
65
66
67 /* If QUAD is defined, we are defining `strtoll' or `strtoull',
68 operating on `long long int's. */
69 #ifdef QUAD
70 # define LONG long long
71 #else
72 # define LONG long
73 #endif
74
75
76 #ifdef USE_WIDE_CHAR
77 # define STRING_TYPE wchar_t
78 #else
79 # define STRING_TYPE char
80 #endif
81
82
83 #define INTERNAL(X) INTERNAL1(X)
84 #define INTERNAL1(X) __##X##_internal
85
86
87 extern INT INTERNAL (__strtol_l) (const STRING_TYPE *, STRING_TYPE **, int,
88 int, __locale_t);
89
90
91 INT
92 INTERNAL (strtol) (nptr, endptr, base, group)
93 const STRING_TYPE *nptr;
94 STRING_TYPE **endptr;
95 int base;
96 int group;
97 {
98 return INTERNAL (__strtol_l) (nptr, endptr, base, group, _NL_CURRENT_LOCALE);
99 }
100 libc_hidden_def (INTERNAL (strtol))
101
102
103 INT
104 strtol (nptr, endptr, base)
105 const STRING_TYPE *nptr;
106 STRING_TYPE **endptr;
107 int base;
108 {
109 return INTERNAL (__strtol_l) (nptr, endptr, base, 0, _NL_CURRENT_LOCALE);
110 }
111 libc_hidden_def (strtol)