1135446Strhodes/*
2193149Sdougb * Copyright (C) 2004-2007  Internet Systems Consortium, Inc. ("ISC")
3135446Strhodes * Copyright (C) 2001, 2002  Internet Software Consortium.
4135446Strhodes *
5193149Sdougb * Permission to use, copy, modify, and/or distribute this software for any
6135446Strhodes * purpose with or without fee is hereby granted, provided that the above
7135446Strhodes * copyright notice and this permission notice appear in all copies.
8135446Strhodes *
9135446Strhodes * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10135446Strhodes * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11135446Strhodes * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12135446Strhodes * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13135446Strhodes * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14135446Strhodes * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15135446Strhodes * PERFORMANCE OF THIS SOFTWARE.
16135446Strhodes */
17135446Strhodes
18234010Sdougb/* $Id: parseint.h,v 1.9 2007/06/19 23:47:18 tbox Exp $ */
19135446Strhodes
20135446Strhodes#ifndef ISC_PARSEINT_H
21135446Strhodes#define ISC_PARSEINT_H 1
22135446Strhodes
23135446Strhodes#include <isc/lang.h>
24135446Strhodes#include <isc/types.h>
25135446Strhodes
26193149Sdougb/*! \file isc/parseint.h
27170222Sdougb * \brief Parse integers, in a saner way than atoi() or strtoul() do.
28135446Strhodes */
29135446Strhodes
30135446Strhodes/***
31135446Strhodes ***	Functions
32135446Strhodes ***/
33135446Strhodes
34135446StrhodesISC_LANG_BEGINDECLS
35135446Strhodes
36135446Strhodesisc_result_t
37135446Strhodesisc_parse_uint32(isc_uint32_t *uip, const char *string, int base);
38135446Strhodes
39135446Strhodesisc_result_t
40135446Strhodesisc_parse_uint16(isc_uint16_t *uip, const char *string, int base);
41135446Strhodes
42135446Strhodesisc_result_t
43135446Strhodesisc_parse_uint8(isc_uint8_t *uip, const char *string, int base);
44170222Sdougb/*%<
45135446Strhodes * Parse the null-terminated string 'string' containing a base 'base'
46170222Sdougb * integer, storing the result in '*uip'.
47170222Sdougb * The base is interpreted
48135446Strhodes * as in strtoul().  Unlike strtoul(), leading whitespace, minus or
49135446Strhodes * plus signs are not accepted, and all errors (including overflow)
50135446Strhodes * are reported uniformly through the return value.
51135446Strhodes *
52135446Strhodes * Requires:
53170222Sdougb *\li	'string' points to a null-terminated string
54170222Sdougb *\li	0 <= 'base' <= 36
55135446Strhodes *
56135446Strhodes * Returns:
57170222Sdougb *\li	#ISC_R_SUCCESS
58170222Sdougb *\li	#ISC_R_BADNUMBER   The string is not numeric (in the given base)
59170222Sdougb *\li	#ISC_R_RANGE	  The number is not representable as the requested type.
60135446Strhodes */
61135446Strhodes
62135446StrhodesISC_LANG_ENDDECLS
63135446Strhodes
64135446Strhodes#endif /* ISC_PARSEINT_H */
65