3 <<wcstoull>>, <<wcstoull_l>>---wide string to unsigned long long
16 unsigned long long wcstoull(const wchar_t *__restrict <[s]>,
17 wchar_t **__restrict <[ptr]>,
21 unsigned long long wcstoull_l(const wchar_t *__restrict <[s]>,
22 wchar_t **__restrict <[ptr]>,
26 unsigned long long _wcstoull_r(void *<[reent]>, const wchar_t *<[s]>,
27 wchar_t **<[ptr]>, int <[base]>);
30 The function <<wcstoull>> converts the wide string <<*<[s]>>> to
31 an <<unsigned long long>>. First, it breaks down the string into three parts:
32 leading whitespace, which is ignored; a subject string consisting
33 of the digits meaningful in the radix specified by <[base]>
34 (for example, <<0>> through <<7>> if the value of <[base]> is 8);
35 and a trailing portion consisting of one or more unparseable characters,
36 which always includes the terminating null character. Then, it attempts
37 to convert the subject string into an unsigned long long integer, and returns the
40 If the value of <[base]> is zero, the subject string is expected to look
41 like a normal C integer constant: an optional sign (<<+>> or <<->>),
42 a possible <<0x>> indicating hexadecimal radix or a possible <0> indicating
43 octal radix, and a number.
44 If <[base]> is between 2 and 36, the expected form of the subject is a
45 sequence of digits (which may include letters, depending on the
46 base) representing an integer in the radix specified by <[base]>.
47 The letters <<a>>--<<z>> (or <<A>>--<<Z>>) are used as digits valued from
48 10 to 35. If <[base]> is 16, a leading <<0x>> is permitted.
50 The subject sequence is the longest initial sequence of the input
51 string that has the expected form, starting with the first
52 non-whitespace character. If the string is empty or consists entirely
53 of whitespace, or if the first non-whitespace character is not a
54 permissible digit, the subject string is empty.
56 If the subject string is acceptable, and the value of <[base]> is zero,
57 <<wcstoull>> attempts to determine the radix from the input string. A
58 string with a leading <<0x>> is treated as a hexadecimal value; a string with
59 a leading <<0>> and no <<x>> is treated as octal; all other strings are
60 treated as decimal. If <[base]> is between 2 and 36, it is used as the
61 conversion radix, as described above. Finally, a pointer to the first
62 character past the converted subject string is stored in <[ptr]>, if
63 <[ptr]> is not <<NULL>>.
65 If the subject string is empty (that is, if <<*>><[s]> does not start
66 with a substring in acceptable form), no conversion
67 is performed and the value of <[s]> is stored in <[ptr]> (if <[ptr]> is
70 The alternate function <<_wcstoull_r>> is a reentrant version. The
71 extra argument <[reent]> is a pointer to a reentrancy structure.
74 <<wcstoull_l>> is like <<wcstoull>> but performs the conversion based on the
75 locale specified by the locale object locale. If <[locale]> is
76 LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined.
79 <<wcstoull>>, <<wcstoull_l>> return <<0>> and sets <<errno>> to <<EINVAL>>
80 if the value of <[base]> is not supported.
82 <<wcstoull>>, <<wcstoull_l>> return the converted value, if any. If no
83 conversion was made, <<0>> is returned.
85 <<wcstoull>>, <<wcstoull_l>> return <<ULLONG_MAX>> if the magnitude of
86 the converted value is too large, and sets <<errno>> to <<ERANGE>>.
90 <<wcstoull_l>> is a GNU extension.
92 <<wcstoull>> requires no supporting OS subroutines.
96 * Copyright (c) 1990 Regents of the University of California.
97 * All rights reserved.
99 * Redistribution and use in source and binary forms, with or without
100 * modification, are permitted provided that the following conditions
102 * 1. Redistributions of source code must retain the above copyright
103 * notice, this list of conditions and the following disclaimer.
104 * 2. Redistributions in binary form must reproduce the above copyright
105 * notice, this list of conditions and the following disclaimer in the
106 * documentation and/or other materials provided with the distribution.
107 * 3. Neither the name of the University nor the names of its contributors
108 * may be used to endorse or promote products derived from this software
109 * without specific prior written permission.
111 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
112 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
113 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
114 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
115 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
116 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
117 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
118 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
119 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
120 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
131 #include "../locale/setlocale.h"
133 /* Make up for older non-compliant limits.h. (This is a C99/POSIX function,
134 * and both require ULLONG_MAX in limits.h.) */
135 #if !defined(ULLONG_MAX)
136 # define ULLONG_MAX ULONG_LONG_MAX
140 * Convert a wide string to an unsigned long long integer.
143 _wcstoull_l (struct _reent
*rptr
, const wchar_t *nptr
, wchar_t **endptr
,
144 int base
, locale_t loc
)
146 register const wchar_t *s
= nptr
;
147 register unsigned long long acc
;
149 register unsigned long long cutoff
;
150 register int neg
= 0, any
, cutlim
;
152 if(base
< 0 || base
== 1 || base
> 36) {
153 _REENT_ERRNO(rptr
) = EINVAL
;
157 * See strtol for comments as to the logic used.
161 } while (iswspace_l(c
, loc
));
165 } else if (c
== L
'+')
167 if ((base
== 0 || base
== 16) &&
168 c
== L
'0' && (*s
== L
'x' || *s
== L
'X')) {
174 base
= c
== L
'0' ? 8 : 10;
175 cutoff
= (unsigned long long)ULLONG_MAX
/ (unsigned long long)base
;
176 cutlim
= (unsigned long long)ULLONG_MAX
% (unsigned long long)base
;
177 for (acc
= 0, any
= 0;; c
= *s
++) {
178 if (c
>= L
'0' && c
<= L
'9')
180 else if (c
>= L
'A' && c
<= L
'Z')
182 else if (c
>= L
'a' && c
<= L
'z')
188 if (any
< 0 || acc
> cutoff
|| (acc
== cutoff
&& c
> cutlim
))
198 _REENT_ERRNO(rptr
) = ERANGE
;
202 *endptr
= (wchar_t *) (any
? s
- 1 : nptr
);
207 _wcstoull_r (struct _reent
*rptr
,
212 return _wcstoull_l (rptr
, nptr
, endptr
, base
, __get_current_locale ());
218 wcstoull_l (const wchar_t *__restrict s
, wchar_t **__restrict ptr
, int base
,
221 return _wcstoull_l (_REENT
, s
, ptr
, base
, loc
);
225 wcstoull (const wchar_t *__restrict s
,
226 wchar_t **__restrict ptr
,
229 return _wcstoull_l (_REENT
, s
, ptr
, base
, __get_current_locale ());