add isc_parse_uint16() and isc_parse_uint8()

This commit is contained in:
Brian Wellington 2002-02-28 20:08:06 +00:00
parent ce24330566
commit 65c709f4de
2 changed files with 35 additions and 3 deletions

View file

@ -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

View file

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