/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "libuutil_common.h"
#include <limits.h>
#include <ctype.h>
((x) >= 'a' && (x) <= 'z') ? (x) + 10 - 'a' : (x) + 10 - 'A')
static int
{
const unsigned char *s = (const unsigned char *)s_arg;
unsigned c, i;
int neg = 0;
int bad_digit = 0;
int bad_char = 0;
int overflow = 0;
return (-1);
}
while ((c = *s) != 0 && isspace(c))
s++;
switch (c) {
case '-':
if (!sign)
neg = 1;
/*FALLTHRU*/
case '+':
c = *++s;
break;
default:
break;
}
if (c == '\0') {
return (-1);
}
if (base == 0) {
if (c != '0')
base = 10;
else if (s[1] == 'x' || s[1] == 'X')
base = 16;
else
base = 8;
}
c = *(s += 2);
if (IS_DIGIT(c))
bad_digit = 1;
else
bad_char = 1;
val = 0;
}
for (c = *++s; c != '\0'; c = *++s) {
if (isspace(c))
break;
if (IS_DIGIT(c))
bad_digit = 1;
else
bad_char = 1;
i = 0;
}
overflow = 1;
overflow = 1;
val += i;
}
while ((c = *s) != 0) {
if (!isspace(c))
bad_char = 1;
s++;
}
if (sign) {
if (neg) {
overflow = 1;
} else {
overflow = 1;
}
}
if (neg)
if (bad_char)
else if (bad_digit)
else if (overflow) {
if (neg)
else
}
return (-1);
}
return (0);
}
int
{
goto bad_argument;
switch (sz) {
case 1:
goto bad_argument;
break;
case 2:
goto bad_argument;
break;
case 4:
goto bad_argument;
break;
case 8:
goto bad_argument;
break;
default:
goto bad_argument;
}
}
return (-1);
return (-1);
return (-1);
}
switch (sz) {
case 1:
return (0);
case 2:
return (0);
case 4:
return (0);
case 8:
return (0);
default:
break; /* fall through to bad_argument */
}
return (-1);
}
int
{
goto bad_argument;
switch (sz) {
case 1:
goto bad_argument;
break;
case 2:
if (max > UINT16_MAX)
goto bad_argument;
break;
case 4:
if (max > UINT32_MAX)
goto bad_argument;
break;
case 8:
if (max > UINT64_MAX)
goto bad_argument;
break;
default:
goto bad_argument;
}
/* we have to be careful, since << can overflow */
}
return (-1);
return (-1);
return (-1);
}
switch (sz) {
case 1:
return (0);
case 2:
return (0);
case 4:
return (0);
case 8:
return (0);
default:
break; /* shouldn't happen, fall through */
}
return (-1);
}