diff --git a/lib/isc/include/isc/parseint.h b/lib/isc/include/isc/parseint.h index c51413691f..4f16bb1810 100644 --- a/lib/isc/include/isc/parseint.h +++ b/lib/isc/include/isc/parseint.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: parseint.h,v 1.1 2001/11/30 01:02:17 gson Exp $ */ +/* $Id: parseint.h,v 1.2 2002/02/28 20:08:06 bwelling Exp $ */ #ifndef ISC_PARSEINT_H #define ISC_PARSEINT_H 1 @@ -35,6 +35,12 @@ ISC_LANG_BEGINDECLS isc_result_t isc_parse_uint32(isc_uint32_t *uip, const char *string, int base); + +isc_result_t +isc_parse_uint16(isc_uint16_t *uip, const char *string, int base); + +isc_result_t +isc_parse_uint8(isc_uint8_t *uip, const char *string, int base); /* * Parse the null-terminated string 'string' containing a base 'base' * integer, storing the result in '*uip'. The base is interpreted @@ -49,7 +55,7 @@ isc_parse_uint32(isc_uint32_t *uip, const char *string, int base); * Returns: * ISC_R_SUCCESS * ISC_R_BADNUMBER The string is not numeric (in the given base) - * ISC_R_RANGE The number is not representable as an isc_uint32_t + * ISC_R_RANGE The number is not representable as the requested type. */ ISC_LANG_ENDDECLS diff --git a/lib/isc/parseint.c b/lib/isc/parseint.c index d672b2d225..8450f0fdcb 100644 --- a/lib/isc/parseint.c +++ b/lib/isc/parseint.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: parseint.c,v 1.1 2001/11/30 01:02:14 gson Exp $ */ +/* $Id: parseint.c,v 1.2 2002/02/28 20:08:05 bwelling Exp $ */ #include @@ -42,3 +42,29 @@ isc_parse_uint32(isc_uint32_t *uip, const char *string, int base) { *uip = n; return (ISC_R_SUCCESS); } + +isc_result_t +isc_parse_uint16(isc_uint16_t *uip, const char *string, int base) { + isc_uint32_t val; + isc_result_t result; + result = isc_parse_uint32(&val, string, base); + if (result != ISC_R_SUCCESS) + return (result); + if (val > 0xFFFF) + return (ISC_R_RANGE); + *uip = (isc_uint16_t) val; + return (ISC_R_SUCCESS); +} + +isc_result_t +isc_parse_uint8(isc_uint8_t *uip, const char *string, int base) { + isc_uint32_t val; + isc_result_t result; + result = isc_parse_uint32(&val, string, base); + if (result != ISC_R_SUCCESS) + return (result); + if (val > 0xFF) + return (ISC_R_RANGE); + *uip = (isc_uint8_t) val; + return (ISC_R_SUCCESS); +}