Deleted Added
sdiff udiff text old ( 225736 ) new ( 235785 )
full compact
1/*
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.

--- 10 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: stable/9/lib/libc/locale/wcstoul.c 165903 2007-01-09 00:28:16Z imp $");
32
33#include <ctype.h>
34#include <errno.h>
35#include <limits.h>
36#include <wchar.h>
37#include <wctype.h>
38
39/*
40 * Convert a wide character string to an unsigned long integer.
41 */
42unsigned long
43wcstoul(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int base)
44{
45 const wchar_t *s;
46 unsigned long acc;
47 wchar_t c;
48 unsigned long cutoff;
49 int neg, any, cutlim;
50
51 /*
52 * See strtol for comments as to the logic used.
53 */
54 s = nptr;
55 do {
56 c = *s++;
57 } while (iswspace(c));
58 if (c == L'-') {
59 neg = 1;
60 c = *s++;
61 } else {
62 neg = 0;
63 if (c == L'+')
64 c = *s++;
65 }

--- 8 unchanged lines hidden (view full) ---

74 acc = any = 0;
75 if (base < 2 || base > 36)
76 goto noconv;
77
78 cutoff = ULONG_MAX / base;
79 cutlim = ULONG_MAX % base;
80 for ( ; ; c = *s++) {
81#ifdef notyet
82 if (iswdigit(c))
83 c = digittoint(c);
84 else
85#endif
86 if (c >= L'0' && c <= L'9')
87 c -= L'0';
88 else if (c >= L'A' && c <= L'Z')
89 c -= L'A' - 10;
90 else if (c >= L'a' && c <= L'z')
91 c -= L'a' - 10;

--- 16 unchanged lines hidden (view full) ---

108noconv:
109 errno = EINVAL;
110 } else if (neg)
111 acc = -acc;
112 if (endptr != NULL)
113 *endptr = (wchar_t *)(any ? s - 1 : nptr);
114 return (acc);
115}