Blame libnfs4acl/strtoul_reals.c

Packit b0b924
/*  Copyright (c) 2006 The Regents of the University of Michigan.
Packit b0b924
 *  All rights reserved.
Packit b0b924
 *
Packit b0b924
 *  David M. Richter <richterd@citi.umich.edu>
Packit b0b924
 *
Packit b0b924
 *  Redistribution and use in source and binary forms, with or without
Packit b0b924
 *  modification, are permitted provided that the following conditions
Packit b0b924
 *  are met:
Packit b0b924
 *
Packit b0b924
 *  1. Redistributions of source code must retain the above copyright
Packit b0b924
 *     notice, this list of conditions and the following disclaimer.
Packit b0b924
 *  2. Redistributions in binary form must reproduce the above copyright
Packit b0b924
 *     notice, this list of conditions and the following disclaimer in the
Packit b0b924
 *     documentation and/or other materials provided with the distribution.
Packit b0b924
 *  3. Neither the name of the University nor the names of its
Packit b0b924
 *     contributors may be used to endorse or promote products derived
Packit b0b924
 *     from this software without specific prior written permission.
Packit b0b924
 *
Packit b0b924
 *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
Packit b0b924
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
Packit b0b924
 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Packit b0b924
 *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit b0b924
 *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Packit b0b924
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Packit b0b924
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
Packit b0b924
 *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Packit b0b924
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Packit b0b924
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Packit b0b924
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit b0b924
 */
Packit b0b924
Packit b0b924
#include <stdlib.h>
Packit b0b924
#include <string.h>
Packit b0b924
#include <limits.h>
Packit b0b924
#include <ctype.h>
Packit b0b924
Packit b0b924
Packit b0b924
/* strtoul() returns '0' for a lot of letters/crap/etc, but we need numbers.
Packit b0b924
 * return the right answer, or ULONG_MAX for any errors.
Packit b0b924
 */
Packit b0b924
unsigned long strtoul_reals(char *s, int base)
Packit b0b924
{
Packit b0b924
	int i, len;
Packit b0b924
Packit b0b924
	if (s == NULL)
Packit b0b924
		return ULONG_MAX;
Packit b0b924
Packit b0b924
	len = strlen(s);
Packit b0b924
	for (i = 0; i < len; i++)
Packit b0b924
		if (!isdigit(*(s + i)))
Packit b0b924
			break;
Packit b0b924
Packit b0b924
	/* if it wasn't a number .. */
Packit b0b924
	if (i != len)
Packit b0b924
		return ULONG_MAX;
Packit b0b924
Packit b0b924
	return strtoul(s, NULL, base);
Packit b0b924
}