* 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
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
* 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
* 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 <config.h>
*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);
+}