1 /*	$NetBSD: parseint.h,v 1.4 2014/12/10 04:38:00 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2004-2007  Internet Systems Consortium, Inc. ("ISC")
5  * Copyright (C) 2001, 2002  Internet Software Consortium.
6  *
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.
10  *
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.
18  */
19 
20 /* Id: parseint.h,v 1.9 2007/06/19 23:47:18 tbox Exp  */
21 
22 #ifndef ISC_PARSEINT_H
23 #define ISC_PARSEINT_H 1
24 
25 #include <isc/lang.h>
26 #include <isc/types.h>
27 
28 /*! \file isc/parseint.h
29  * \brief Parse integers, in a saner way than atoi() or strtoul() do.
30  */
31 
32 /***
33  ***	Functions
34  ***/
35 
36 ISC_LANG_BEGINDECLS
37 
38 isc_result_t
39 isc_parse_uint32(isc_uint32_t *uip, const char *string, int base);
40 
41 isc_result_t
42 isc_parse_uint16(isc_uint16_t *uip, const char *string, int base);
43 
44 isc_result_t
45 isc_parse_uint8(isc_uint8_t *uip, const char *string, int base);
46 /*%<
47  * Parse the null-terminated string 'string' containing a base 'base'
48  * integer, storing the result in '*uip'.
49  * The base is interpreted
50  * as in strtoul().  Unlike strtoul(), leading whitespace, minus or
51  * plus signs are not accepted, and all errors (including overflow)
52  * are reported uniformly through the return value.
53  *
54  * Requires:
55  *\li	'string' points to a null-terminated string
56  *\li	0 <= 'base' <= 36
57  *
58  * Returns:
59  *\li	#ISC_R_SUCCESS
60  *\li	#ISC_R_BADNUMBER   The string is not numeric (in the given base)
61  *\li	#ISC_R_RANGE	  The number is not representable as the requested type.
62  */
63 
64 ISC_LANG_ENDDECLS
65 
66 #endif /* ISC_PARSEINT_H */
67