0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2003-2005, 2007, 2014, 2016 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
21f1794606dce19928cf455029e173321f166380Mark Andrews * Copyright (c) 1990, 1993
21f1794606dce19928cf455029e173321f166380Mark Andrews * The Regents of the University of California. All rights reserved.
21f1794606dce19928cf455029e173321f166380Mark Andrews * Redistribution and use in source and binary forms, with or without
21f1794606dce19928cf455029e173321f166380Mark Andrews * modification, are permitted provided that the following conditions
21f1794606dce19928cf455029e173321f166380Mark Andrews * 1. Redistributions of source code must retain the above copyright
21f1794606dce19928cf455029e173321f166380Mark Andrews * notice, this list of conditions and the following disclaimer.
21f1794606dce19928cf455029e173321f166380Mark Andrews * 2. Redistributions in binary form must reproduce the above copyright
21f1794606dce19928cf455029e173321f166380Mark Andrews * notice, this list of conditions and the following disclaimer in the
21f1794606dce19928cf455029e173321f166380Mark Andrews * documentation and/or other materials provided with the distribution.
bff64bf12b58a6f80e740e94f2e42a32df18113aEvan Hunt * 3. Neither the name of the University nor the names of its contributors
21f1794606dce19928cf455029e173321f166380Mark Andrews * may be used to endorse or promote products derived from this software
21f1794606dce19928cf455029e173321f166380Mark Andrews * without specific prior written permission.
21f1794606dce19928cf455029e173321f166380Mark Andrews * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21f1794606dce19928cf455029e173321f166380Mark Andrews * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21f1794606dce19928cf455029e173321f166380Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21f1794606dce19928cf455029e173321f166380Mark Andrews * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21f1794606dce19928cf455029e173321f166380Mark Andrews * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21f1794606dce19928cf455029e173321f166380Mark Andrews * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21f1794606dce19928cf455029e173321f166380Mark Andrews * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21f1794606dce19928cf455029e173321f166380Mark Andrews * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21f1794606dce19928cf455029e173321f166380Mark Andrews * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21f1794606dce19928cf455029e173321f166380Mark Andrews * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
21f1794606dce19928cf455029e173321f166380Mark Andrews * SUCH DAMAGE.
21f1794606dce19928cf455029e173321f166380Mark Andrewsstatic char sccsid[] = "@(#)strtoul.c 8.1 (Berkeley) 6/4/93";
21f1794606dce19928cf455029e173321f166380Mark Andrews#endif /* LIBC_SCCS and not lint */
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater/* $Id: strtoul.c,v 1.7 2007/06/19 23:47:17 tbox Exp $ */
21f1794606dce19928cf455029e173321f166380Mark Andrews * Convert a string to an unsigned long integer.
21f1794606dce19928cf455029e173321f166380Mark Andrews * Ignores `locale' stuff. Assumes that the upper and lower case
21f1794606dce19928cf455029e173321f166380Mark Andrews * alphabets and digits are each contiguous.
21f1794606dce19928cf455029e173321f166380Mark Andrewsunsigned long
21f1794606dce19928cf455029e173321f166380Mark Andrewsisc_strtoul(const char *nptr, char **endptr, int base) {
21f1794606dce19928cf455029e173321f166380Mark Andrews const char *s = nptr;
21f1794606dce19928cf455029e173321f166380Mark Andrews unsigned char c;
21f1794606dce19928cf455029e173321f166380Mark Andrews * See strtol for comments as to the logic used.
21f1794606dce19928cf455029e173321f166380Mark Andrews } while (isspace(c));
21f1794606dce19928cf455029e173321f166380Mark Andrews if (c == '-') {
21f1794606dce19928cf455029e173321f166380Mark Andrews } else if (c == '+')
21f1794606dce19928cf455029e173321f166380Mark Andrews cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
21f1794606dce19928cf455029e173321f166380Mark Andrews cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;
21f1794606dce19928cf455029e173321f166380Mark Andrews if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))