]> git.ipfire.org Git - thirdparty/glibc.git/blob - stdlib/strtol.c
* include/stdlib.h: Add libc_hidden_proto for strto*, __strto*_l.
[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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21 #include <stdlib.h>
22 #include <wchar.h>
23 #include <locale/localeinfo.h>
24
25 #ifndef UNSIGNED
26 # define UNSIGNED 0
27 # define INT LONG int
28 #else
29 # define INT unsigned LONG int
30 #endif
31
32 #if UNSIGNED
33 # ifdef USE_WIDE_CHAR
34 # ifdef QUAD
35 # define strtol wcstoull
36 # define __strtol_l __wcstoull_l
37 # else
38 # define strtol wcstoul
39 # define __strtol_l __wcstoul_l
40 # endif
41 # else
42 # ifdef QUAD
43 # define strtol strtoull
44 # define __strtol_l __strtoull_l
45 # else
46 # define strtol strtoul
47 # define __strtol_l __strtoul_l
48 # endif
49 # endif
50 #else
51 # ifdef USE_WIDE_CHAR
52 # ifdef QUAD
53 # define strtol wcstoll
54 # define __strtol_l __wcstoll_l
55 # else
56 # define strtol wcstol
57 # define __strtol_l __wcstol_l
58 # endif
59 # else
60 # ifdef QUAD
61 # define strtol strtoll
62 # define __strtol_l __strtoll_l
63 # endif
64 # endif
65 #endif
66
67
68 /* If QUAD is defined, we are defining `strtoll' or `strtoull',
69 operating on `long long int's. */
70 #ifdef QUAD
71 # define LONG long long
72 #else
73 # define LONG long
74 #endif
75
76
77 #ifdef USE_WIDE_CHAR
78 # define STRING_TYPE wchar_t
79 #else
80 # define STRING_TYPE char
81 #endif
82
83
84 #define INTERNAL(X) INTERNAL1(X)
85 #define INTERNAL1(X) __##X##_internal
86
87
88 extern INT INTERNAL (__strtol_l) (const STRING_TYPE *, STRING_TYPE **, int,
89 int, __locale_t);
90
91
92 INT
93 INTERNAL (strtol) (nptr, endptr, base, group)
94 const STRING_TYPE *nptr;
95 STRING_TYPE **endptr;
96 int base;
97 int group;
98 {
99 return INTERNAL (__strtol_l) (nptr, endptr, base, group, _NL_CURRENT_LOCALE);
100 }
101 libc_hidden_def (INTERNAL (strtol))
102
103
104 INT
105 strtol (nptr, endptr, base)
106 const STRING_TYPE *nptr;
107 STRING_TYPE **endptr;
108 int base;
109 {
110 return INTERNAL (__strtol_l) (nptr, endptr, base, 0, _NL_CURRENT_LOCALE);
111 }
112 libc_hidden_def (strtol)