4 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2001-2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: parseint.c,v 1.8 2007/06/19 23:47:17 tbox Exp */
30 #include <isc/parseint.h>
31 #include <isc/result.h>
32 #include <isc/stdlib.h>
35 isc_parse_uint32(isc_uint32_t
*uip
, const char *string
, int base
) {
38 if (! isalnum((unsigned char)(string
[0])))
39 return (ISC_R_BADNUMBER
);
41 n
= strtoul(string
, &e
, base
);
43 return (ISC_R_BADNUMBER
);
44 if (n
== ULONG_MAX
&& errno
== ERANGE
)
47 return (ISC_R_SUCCESS
);
51 isc_parse_uint16(isc_uint16_t
*uip
, const char *string
, int base
) {
54 result
= isc_parse_uint32(&val
, string
, base
);
55 if (result
!= ISC_R_SUCCESS
)
59 *uip
= (isc_uint16_t
) val
;
60 return (ISC_R_SUCCESS
);
64 isc_parse_uint8(isc_uint8_t
*uip
, const char *string
, int base
) {
67 result
= isc_parse_uint32(&val
, string
, base
);
68 if (result
!= ISC_R_SUCCESS
)
72 *uip
= (isc_uint8_t
) val
;
73 return (ISC_R_SUCCESS
);