parseint.h revision 290001
1/*
2 * Copyright (C) 2004-2007  Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2001, 2002  Internet Software Consortium.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
16 */
17
18/* $Id: parseint.h,v 1.9 2007/06/19 23:47:18 tbox Exp $ */
19
20#ifndef ISC_PARSEINT_H
21#define ISC_PARSEINT_H 1
22
23#include <isc/lang.h>
24#include <isc/types.h>
25
26/*! \file isc/parseint.h
27 * \brief Parse integers, in a saner way than atoi() or strtoul() do.
28 */
29
30/***
31 ***	Functions
32 ***/
33
34ISC_LANG_BEGINDECLS
35
36isc_result_t
37isc_parse_uint32(isc_uint32_t *uip, const char *string, int base);
38
39isc_result_t
40isc_parse_uint16(isc_uint16_t *uip, const char *string, int base);
41
42isc_result_t
43isc_parse_uint8(isc_uint8_t *uip, const char *string, int base);
44/*%<
45 * Parse the null-terminated string 'string' containing a base 'base'
46 * integer, storing the result in '*uip'.
47 * The base is interpreted
48 * as in strtoul().  Unlike strtoul(), leading whitespace, minus or
49 * plus signs are not accepted, and all errors (including overflow)
50 * are reported uniformly through the return value.
51 *
52 * Requires:
53 *\li	'string' points to a null-terminated string
54 *\li	0 <= 'base' <= 36
55 *
56 * Returns:
57 *\li	#ISC_R_SUCCESS
58 *\li	#ISC_R_BADNUMBER   The string is not numeric (in the given base)
59 *\li	#ISC_R_RANGE	  The number is not representable as the requested type.
60 */
61
62ISC_LANG_ENDDECLS
63
64#endif /* ISC_PARSEINT_H */
65