diff options
author | Florian Obser <florian@cvs.openbsd.org> | 2020-09-13 09:33:40 +0000 |
---|---|---|
committer | Florian Obser <florian@cvs.openbsd.org> | 2020-09-13 09:33:40 +0000 |
commit | cb353c2e238251ba8e2e5a0f35eac4d117254c3d (patch) | |
tree | 07df3c3d6bb8a5dda30aabfc0fd851d36ee59b02 /usr.bin/dig/lib | |
parent | f7034f3b899784eb0446d942568f6f9e18dc6787 (diff) |
Get rid of isc_parse_uint32() and replace it with strtonum.
While here use the standard strtonum error messages.
input & OK beck, OK kn
Diffstat (limited to 'usr.bin/dig/lib')
-rw-r--r-- | usr.bin/dig/lib/isc/Makefile.inc | 4 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/include/isc/parseint.h | 53 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/lex.c | 4 | ||||
-rw-r--r-- | usr.bin/dig/lib/isc/parseint.c | 50 |
4 files changed, 3 insertions, 108 deletions
diff --git a/usr.bin/dig/lib/isc/Makefile.inc b/usr.bin/dig/lib/isc/Makefile.inc index 41240e1a80d..568a648f9ab 100644 --- a/usr.bin/dig/lib/isc/Makefile.inc +++ b/usr.bin/dig/lib/isc/Makefile.inc @@ -1,11 +1,11 @@ -# $OpenBSD: Makefile.inc,v 1.6 2020/02/25 18:10:17 florian Exp $ +# $OpenBSD: Makefile.inc,v 1.7 2020/09/13 09:33:39 florian Exp $ .PATH: ${.CURDIR}/lib/isc SRCS+= assertions.c base32.c base64.c netaddr.c buffer.c bufferlist.c SRCS+= error.c event.c hash.c heap.c hex.c hmacsha.c SRCS+= lex.c log.c regex.c sockaddr.c -SRCS+= task.c result.c parseint.c refcount.c timer.c +SRCS+= task.c result.c refcount.c timer.c SRCS+= serial.c sha1.c sha2.c symtab.c diff --git a/usr.bin/dig/lib/isc/include/isc/parseint.h b/usr.bin/dig/lib/isc/include/isc/parseint.h deleted file mode 100644 index f6651cbcb12..00000000000 --- a/usr.bin/dig/lib/isc/include/isc/parseint.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/* $Id: parseint.h,v 1.4 2020/02/22 19:47:07 jung Exp $ */ - -#ifndef ISC_PARSEINT_H -#define ISC_PARSEINT_H 1 - -#include <isc/types.h> - -/*! \file isc/parseint.h - * \brief Parse integers, in a saner way than atoi() or strtoul() do. - */ - -/*** - *** Functions - ***/ - -isc_result_t -isc_parse_uint32(uint32_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 - * as in strtoul(). Unlike strtoul(), leading whitespace, minus or - * plus signs are not accepted, and all errors (including overflow) - * are reported uniformly through the return value. - * - * Requires: - *\li 'string' points to a null-terminated string - *\li 0 <= 'base' <= 36 - * - * Returns: - *\li #ISC_R_SUCCESS - *\li #ISC_R_BADNUMBER The string is not numeric (in the given base) - *\li #ISC_R_RANGE The number is not representable as the requested type. - */ - -#endif /* ISC_PARSEINT_H */ diff --git a/usr.bin/dig/lib/isc/lex.c b/usr.bin/dig/lib/isc/lex.c index 86371ddbd24..4fc0e3f8422 100644 --- a/usr.bin/dig/lib/isc/lex.c +++ b/usr.bin/dig/lib/isc/lex.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: lex.c,v 1.10 2020/09/13 09:32:02 florian Exp $ */ +/* $Id: lex.c,v 1.11 2020/09/13 09:33:39 florian Exp $ */ /*! \file */ @@ -25,8 +25,6 @@ #include <isc/lex.h> -#include <isc/parseint.h> - #include <errno.h> #include <string.h> #include <isc/util.h> diff --git a/usr.bin/dig/lib/isc/parseint.c b/usr.bin/dig/lib/isc/parseint.c deleted file mode 100644 index dd00f7289cf..00000000000 --- a/usr.bin/dig/lib/isc/parseint.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/* $Id: parseint.c,v 1.4 2020/02/25 05:00:43 jsg Exp $ */ - -/*! \file */ - -#include <ctype.h> -#include <errno.h> -#include <limits.h> -#include <stdlib.h> - -#include <isc/parseint.h> -#include <isc/result.h> - -isc_result_t -isc_parse_uint32(uint32_t *uip, const char *string, int base) { - unsigned long n; - uint32_t r; - char *e; - if (! isalnum((unsigned char)(string[0]))) - return (ISC_R_BADNUMBER); - errno = 0; - n = strtoul(string, &e, base); - if (*e != '\0') - return (ISC_R_BADNUMBER); - /* - * Where long is 64 bits we need to convert to 32 bits then test for - * equality. This is a no-op on 32 bit machines and a good compiler - * will optimise it away. - */ - r = (uint32_t)n; - if ((n == ULONG_MAX && errno == ERANGE) || (n != (unsigned long)r)) - return (ISC_R_RANGE); - *uip = r; - return (ISC_R_SUCCESS); -} |