]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Replace isc_string_touint64 with strtoull (C99)
authorOndřej Surý <ondrej@sury.org>
Wed, 21 Mar 2018 16:09:08 +0000 (16:09 +0000)
committerOndřej Surý <ondrej@sury.org>
Thu, 12 Apr 2018 08:37:33 +0000 (10:37 +0200)
lib/dns/rdata/any_255/tsig_250.c
lib/isc/include/isc/string.h
lib/isc/log.c
lib/isc/netscope.c
lib/isc/string.c
lib/isc/win32/include/isc/platform.h.in
lib/isc/win32/libisc.def.in
lib/isccfg/namedconf.c
lib/isccfg/parser.c

index 9282c073f1bba8ad4bf0a8b24bd1725349f68d89..ed68b24919ef6174aa8ca579fa6fcf725eb66e55 100644 (file)
@@ -52,7 +52,7 @@ fromtext_any_tsig(ARGS_FROMTEXT) {
         */
        RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
                                      ISC_FALSE));
-       sigtime = isc_string_touint64(DNS_AS_STR(token), &e, 10);
+       sigtime = strtoull(DNS_AS_STR(token), &e, 10);
        if (*e != 0)
                RETTOK(DNS_R_SYNTAX);
        if ((sigtime >> 48) != 0)
index 43e6af63e135b22e4080fd0fc9b279cc37032658..0c77f87b37f8e24cf10a4e96d8ff7debcb586429 100644 (file)
 
 ISC_LANG_BEGINDECLS
 
-isc_uint64_t
-isc_string_touint64(char *source, char **endp, int base);
-/*%<
- * Convert the string pointed to by 'source' to isc_uint64_t.
- *
- * On successful conversion 'endp' points to the first character
- * after conversion is complete.
- *
- * 'base': 0 or 2..36
- *
- * If base is 0 the base is computed from the string type.
- *
- * On error 'endp' points to 'source'.
- */
-
 isc_result_t
 isc_string_copy(char *target, size_t size, const char *source);
 /*
@@ -114,23 +99,6 @@ isc_string_append(char *target, size_t size, const char *source);
  *                       is too small.
  */
 
-void
-isc_string_append_truncate(char *target, size_t size, const char *source);
-/*
- * Append the string pointed to by 'source' to 'target' which is a
- * pointer to a NUL terminated string of at least 'size' bytes.
- *
- * Requires:
- *     'target' is a pointer to a NUL terminated char[] of at
- *     least 'size' bytes.
- *     'size' an integer > 0.
- *     'source' == NULL or points to a NUL terminated string.
- *
- * Ensures:
- *     'target' will be a NUL terminated string of no more
- *     than 'size' bytes (including NUL).
- */
-
 isc_result_t
 isc_string_printf(char *target, size_t size, const char *format, ...)
        ISC_FORMAT_PRINTF(3, 4);
index 224e6653ce1e1fe2fe368f8e8efa2a73eefcf188..98c0ed45ddec86c84dba0032dbb4387feb12ddc2 100644 (file)
@@ -1280,8 +1280,7 @@ remove_old_tsversions(isc_logfile_t *file, int versions) {
                            dir.entry.name[bnamelen] == '.')
                        {
                                char *ename = &dir.entry.name[bnamelen + 1];
-                               version = isc_string_touint64(ename,
-                                                             &digit_end, 10);
+                               version = strtoull(ename, &digit_end, 10);
                                if (*digit_end == '\0') {
                                        int i = 0;
                                        while (i < versions &&
@@ -1316,7 +1315,7 @@ remove_old_tsversions(isc_logfile_t *file, int versions) {
                    dir.entry.name[bnamelen] == '.')
                {
                        char *ename = &dir.entry.name[bnamelen + 1];
-                       version = isc_string_touint64(ename, &digit_end, 10);
+                       version = strtoull(ename, &digit_end, 10);
                        /*
                         * Remove any backup files that exceed versions.
                         */
index 85a25b6f136b24f7f06ed299811bdfd29ca6eff4..859d05ff68a284dba15b1fea399bf4a668f6e641 100644 (file)
@@ -13,6 +13,8 @@
 
 #include <config.h>
 
+#include <stdlib.h>
+
 #include <isc/string.h>
 #include <isc/net.h>
 #include <isc/netscope.h>
@@ -47,7 +49,7 @@ isc_netscope_pton(int af, char *scopename, void *addr, isc_uint32_t *zoneid) {
                zone = (isc_uint32_t)ifid;
        else {
 #endif
-               llz = isc_string_touint64(scopename, &ep, 10);
+               llz = strtoull(scopename, &ep, 10);
                if (ep == scopename)
                        return (ISC_R_FAILURE);
 
index eab78c20b03583a0427341cf346faf26b719c209..a9e5d40aa6489d79ab57109d3f499e72cd106bb2 100644 (file)
 #include <isc/string.h>
 #include <isc/util.h>
 
-static const char digits[] = "0123456789abcdefghijklmnoprstuvwxyz";
-
-isc_uint64_t
-isc_string_touint64(char *source, char **end, int base) {
-       isc_uint64_t tmp;
-       isc_uint64_t overflow;
-       char *s = source;
-       const char *o;
-       char c;
-
-       if ((base < 0) || (base == 1) || (base > 36)) {
-               *end = source;
-               return (0);
-       }
-
-       while (*s != 0 && isascii(*s&0xff) && isspace(*s&0xff))
-               s++;
-       if (*s == '+' /* || *s == '-' */)
-               s++;
-       if (base == 0) {
-               if (*s == '0' && (*(s+1) == 'X' || *(s+1) == 'x')) {
-                       s += 2;
-                       base = 16;
-               } else if (*s == '0')
-                       base = 8;
-               else
-                       base = 10;
-       }
-       if (*s == 0) {
-               *end = source;
-               return (0);
-       }
-       overflow = ~0;
-       overflow /= base;
-       tmp = 0;
-
-       while ((c = *s) != 0) {
-               c = tolower(c&0xff);
-               /* end ? */
-               if ((o = strchr(digits, c)) == NULL) {
-                       *end = s;
-                       return (tmp);
-               }
-               /* end ? */
-               if ((o - digits) >= base) {
-                       *end = s;
-                       return (tmp);
-               }
-               /* overflow ? */
-               if (tmp > overflow) {
-                       *end = source;
-                       return (0);
-               }
-               tmp *= base;
-               /* overflow ? */
-               if ((tmp + (o - digits)) < tmp) {
-                       *end = source;
-                       return (0);
-               }
-               tmp += o - digits;
-               s++;
-       }
-       *end = s;
-       return (tmp);
-}
-
 isc_result_t
 isc_string_copy(char *target, size_t size, const char *source) {
        REQUIRE(size > 0U);
@@ -154,16 +88,6 @@ isc_string_append(char *target, size_t size, const char *source) {
        return (ISC_R_SUCCESS);
 }
 
-void
-isc_string_append_truncate(char *target, size_t size, const char *source) {
-       REQUIRE(size > 0U);
-       REQUIRE(strlen(target) < size);
-
-       strlcat(target, source, size);
-
-       ENSURE(strlen(target) < size);
-}
-
 isc_result_t
 isc_string_printf(char *target, size_t size, const char *format, ...) {
        va_list args;
index 3da8f37c33ccfc8308d90ec783b9627dd82a81dd..e3f534f7b8e37489876f72cf2508d44b2d4066d6 100644 (file)
 
 #define ISC_PLATFORM_USETHREADS 1
 
+/*
+ * Some compatibility cludges
+ */
+
+#if defined(_WIN32) || defined(_WIN64)
+
+#ifndef strtoull
+#define strtoull _strtoui64
+#endif
+
+#endif
+
 /***
  *** Network.
  ***/
index 66a44a54bee5a2b98577ea3505f6174f7ea908ec..85beac7e69597f5ededf79a89561fb4f60e7ceed 100644 (file)
@@ -646,7 +646,6 @@ isc_stdio_tell
 isc_stdio_write
 isc_stdtime_get
 isc_string_append
-isc_string_append_truncate
 isc_string_copy
 isc_string_copy_truncate
 isc_string_printf
@@ -656,7 +655,6 @@ isc_string_separate
 isc_string_strcasestr
 isc_string_strlcat
 isc_string_strlcpy
-isc_string_touint64
 isc_symtab_count
 isc_symtab_create
 isc_symtab_define
index c3cab304e918fadcb9aa3d8904456dcf05bb1c02..7bd6fce625e2c83d7780e30a6dd0ca0875811f3f 100644 (file)
@@ -2552,7 +2552,7 @@ parse_unitstring(char *str, isc_resourcevalue_t *valuep) {
        isc_uint64_t value;
        isc_uint64_t unit;
 
-       value = isc_string_touint64(str, &endp, 10);
+       value = strtoull(str, &endp, 10);
        if (*endp == 0) {
                *valuep = value;
                return (ISC_R_SUCCESS);
@@ -2628,7 +2628,7 @@ parse_sizeval_percent(cfg_parser_t *pctx, const cfg_type_t *type,
                goto cleanup;
        }
 
-       percent = isc_string_touint64(TOKEN_STRING(pctx), &endp, 10);
+       percent = strtoull(TOKEN_STRING(pctx), &endp, 10);
 
        if (*endp == '%' && *(endp+1) == 0) {
                CHECK(cfg_create_obj(pctx, &cfg_type_percentage, &obj));
index ef6a92da480bfaae5ba2f6d953b9672acf111cda..6e840161fb16c088e0dc0422fd6ceda975bf2ef5 100644 (file)
@@ -752,7 +752,7 @@ cfg_parse_percentage(cfg_parser_t *pctx, const cfg_type_t *type,
                return (ISC_R_UNEXPECTEDTOKEN);
        }
 
-       percent = isc_string_touint64(TOKEN_STRING(pctx), &endp, 10);
+       percent = strtoull(TOKEN_STRING(pctx), &endp, 10);
        if (*endp != '%' || *(endp+1) != 0) {
                cfg_parser_error(pctx, CFG_LOG_NEAR,
                                 "expected percentage");