]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
add isc_parse_uint16() and isc_parse_uint8()
authorBrian Wellington <source@isc.org>
Thu, 28 Feb 2002 20:08:06 +0000 (20:08 +0000)
committerBrian Wellington <source@isc.org>
Thu, 28 Feb 2002 20:08:06 +0000 (20:08 +0000)
lib/isc/include/isc/parseint.h
lib/isc/parseint.c

index c51413691f51efcace5df540a07f4da758ac2d28..4f16bb181071d3d632e171b722bfb891cce122ac 100644 (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
index d672b2d225a7c2199aa7076c80a61deeed6844d2..8450f0fdcb712119af7db014acd91b069ed75ac9 100644 (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);
+}