4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/* $NetBSD: strtoumax.c,v 1.1 2006/04/22 15:33:33 thorpej Exp $ */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Copyright (c) 1990, 1993
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * The Regents of the University of California. All rights reserved.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Redistribution and use in source and binary forms, with or without
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * modification, are permitted provided that the following conditions
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * 1. Redistributions of source code must retain the above copyright
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * notice, this list of conditions and the following disclaimer.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * 2. Redistributions in binary form must reproduce the above copyright
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * notice, this list of conditions and the following disclaimer in the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * documentation and/or other materials provided with the distribution.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * 3. Neither the name of the University nor the names of its contributors
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * may be used to endorse or promote products derived from this software
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * without specific prior written permission.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * SUCH DAMAGE.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncstatic char sccsid[] = "from: @(#)strtoul.c 8.1 (Berkeley) 6/4/93";
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync__RCSID("$NetBSD: strtoumax.c,v 1.1 2006/04/22 15:33:33 thorpej Exp $");
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#endif /* LIBC_SCCS and not lint */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#else /* !_KERNEL && !_STANDALONE */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#endif /* !_KERNEL && !_STANDALONE */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Convert a string to an uintmax_t.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Ignores `locale' stuff. Assumes that the upper and lower case
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * alphabets and digits are each contiguous.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncstrtoumax(const char *nptr, char **endptr, int base)
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync const char *s;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /* endptr may be NULL */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * See strtol for comments as to the logic used.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync c = (unsigned char) *s++;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync } while (isspace(c));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (c == '-') {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (c == '+')
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync cutoff = DivU64x32 ((UINT64) UINTMAX_MAX, (UINT32) base);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync cutlim = (int) ModU64x32 ((UINT64) UINTMAX_MAX, (UINT32) base);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync for (acc = 0, any = 0;; c = (unsigned char) *s++) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync else if (isalpha(c)) {