]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: rename curlx_strtoofft to Curl_str_numblanks()
authorDaniel Stenberg <daniel@haxx.se>
Mon, 10 Mar 2025 07:12:05 +0000 (08:12 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 10 Mar 2025 09:39:20 +0000 (10:39 +0100)
The function is no longer used via the curlx shortcut.

Remove the strtoofft.[ch] files.

Closes #16642

17 files changed:
lib/Makefile.inc
lib/cf-h1-proxy.c
lib/curlx.h
lib/ftplistparser.c
lib/http.c
lib/strparse.c
lib/strparse.h
lib/strtoofft.c [deleted file]
lib/strtoofft.h [deleted file]
lib/vssh/libssh.c
lib/vssh/libssh2.c
packages/vms/gnv_link_curl.com
projects/generate.bat
src/Makefile.inc
src/terminal.c
tests/server/Makefile.inc
winbuild/MakefileBuild.vc

index 58ce220e7b27c3371095d72fdb2aa5eb64c43770..c7a03f31d24a1e5070cb91a50d32d86196c77ce3 100644 (file)
@@ -233,7 +233,6 @@ LIB_CFILES =         \
   strequal.c         \
   strerror.c         \
   strparse.c         \
-  strtoofft.c        \
   system_win32.c     \
   telnet.c           \
   tftp.c             \
@@ -374,7 +373,6 @@ LIB_HFILES =         \
   strdup.h           \
   strerror.h         \
   strparse.h         \
-  strtoofft.h        \
   system_win32.h     \
   telnet.h           \
   tftp.h             \
index 4698f014a71709ceeb93514539cc646d382cbacb..3be85cd253bf029d63769247cf8c58be9a56f9f8 100644 (file)
@@ -44,7 +44,7 @@
 #include "vtls/vtls.h"
 #include "transfer.h"
 #include "multiif.h"
-#include "strtoofft.h"
+#include "strparse.h"
 
 /* The last 3 #include files should be in this order */
 #include "curl_printf.h"
@@ -315,8 +315,8 @@ static CURLcode on_resp_header(struct Curl_cfilter *cf,
             k->httpcode);
     }
     else {
-      if(curlx_strtoofft(header + strlen("Content-Length:"),
-                         NULL, 10, &ts->cl)) {
+      const char *p = header + strlen("Content-Length:");
+      if(Curl_str_numblanks(&p, &ts->cl)) {
         failf(data, "Unsupported Content-Length value");
         return CURLE_WEIRD_SERVER_REPLY;
       }
index f0e4e6470b188fec8838e506dea285cfdf107717..6db9620986788e5bf6889ac7e5933a5bcf0b2123 100644 (file)
 #include "strcase.h"
 /* "strcase.h" provides the strcasecompare protos */
 
-#include "strtoofft.h"
-/* "strtoofft.h" provides this function: curlx_strtoofft(), returns a
-   curl_off_t number from a given string.
-*/
-
 #include "nonblock.h"
 /* "nonblock.h" provides curlx_nonblock() */
 
@@ -66,4 +61,7 @@
 #include "version_win32.h"
 /* "version_win32.h" provides curlx_verify_windows_version() */
 
+#include "strparse.h"
+/* The curlx_str_* parsing functions */
+
 #endif /* HEADER_CURL_CURLX_H */
index 9f60cf931ca4af473b6d7c60d3664671b83d1153..b5739bd3f01a5e8abb856cfeec261ba3dd0608f2 100644 (file)
@@ -46,7 +46,6 @@
 #include "urldata.h"
 #include "fileinfo.h"
 #include "llist.h"
-#include "strtoofft.h"
 #include "ftp.h"
 #include "ftplistparser.h"
 #include "curl_fnmatch.h"
@@ -627,13 +626,11 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
         case PL_UNIX_SIZE_NUMBER:
           parser->item_length++;
           if(c == ' ') {
-            char *p;
+            const char *p = mem + parser->item_offset;
             curl_off_t fsize;
             mem[parser->item_offset + parser->item_length - 1] = 0;
-            if(!curlx_strtoofft(mem + parser->item_offset,
-                                &p, 10, &fsize)) {
-              if(p[0] == '\0' && fsize != CURL_OFF_T_MAX &&
-                 fsize != CURL_OFF_T_MIN) {
+            if(!Curl_str_numblanks(&p, &fsize)) {
+              if(p[0] == '\0' && fsize != CURL_OFF_T_MAX) {
                 parser->file_data->info.flags |= CURLFINFOFLAG_KNOWN_SIZE;
                 parser->file_data->info.size = fsize;
               }
@@ -954,10 +951,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
               finfo->size = 0;
             }
             else {
-              char *endptr;
-              if(curlx_strtoofft(mem +
-                                 parser->item_offset,
-                                 &endptr, 10, &finfo->size)) {
+              const char *p = mem + parser->item_offset;
+              if(Curl_str_numblanks(&p, &finfo->size)) {
                 parser->error = CURLE_FTP_BAD_FILE_LIST;
                 goto fail;
               }
index 466080cb797b6279b23a24d79454d0b2ca1251a1..5a5636c017941050b33c49afa00e2e74ab93985b 100644 (file)
@@ -72,7 +72,6 @@
 #include "headers.h"
 #include "select.h"
 #include "parsedate.h" /* for the week day and month names */
-#include "strtoofft.h"
 #include "multiif.h"
 #include "strcase.h"
 #include "content_encoding.h"
@@ -3027,13 +3026,13 @@ static CURLcode http_header(struct Curl_easy *data,
       HD_VAL(hd, hdlen, "Content-Length:") : NULL;
     if(v) {
       curl_off_t contentlength;
-      CURLofft offt = curlx_strtoofft(v, NULL, 10, &contentlength);
+      int offt = Curl_str_numblanks(&v, &contentlength);
 
-      if(offt == CURL_OFFT_OK) {
+      if(offt == STRE_OK) {
         k->size = contentlength;
         k->maxdownload = k->size;
       }
-      else if(offt == CURL_OFFT_FLOW) {
+      else if(offt == STRE_OVERFLOW) {
         /* out of range */
         if(data->set.max_filesize) {
           failf(data, "Maximum file size exceeded");
index db31cd71254a427e317954c1c8aaa8a30eaef2a8..1d53ba6757c58b80b5bb479201884c031a832503 100644 (file)
@@ -212,6 +212,16 @@ int Curl_str_octal(const char **linep, curl_off_t *nump, curl_off_t max)
   return str_num_base(linep, nump, max, 8);
 }
 
+/*
+ * Parse a positive number up to 63-bit number written in ASCII. Skip leading
+ * blanks. No support for prefixes.
+ */
+int Curl_str_numblanks(const char **str, curl_off_t *num)
+{
+  Curl_str_passblanks(str);
+  return Curl_str_number(str, num, CURL_OFF_T_MAX);
+}
+
 /* CR or LF
    return non-zero on error */
 int Curl_str_newline(const char **linep)
index a3f9d8b0827c0643b34df3cfbf15607b3f9451a5..739ea31a17442f31b723a2ff58945cb8b0e5bae7 100644 (file)
@@ -78,6 +78,9 @@ int Curl_str_singlespace(const char **linep);
 /* Get an unsigned decimal number. Return non-zero on error */
 int Curl_str_number(const char **linep, curl_off_t *nump, curl_off_t max);
 
+/* As above with CURL_OFF_T_MAX but also pass leading blanks */
+int Curl_str_numblanks(const char **str, curl_off_t *num);
+
 /* Get an unsigned hexadecimal number. Return non-zero on error */
 int Curl_str_hex(const char **linep, curl_off_t *nump, curl_off_t max);
 
diff --git a/lib/strtoofft.c b/lib/strtoofft.c
deleted file mode 100644 (file)
index 6da60cd..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/***************************************************************************
- *                                  _   _ ____  _
- *  Project                     ___| | | |  _ \| |
- *                             / __| | | | |_) | |
- *                            | (__| |_| |  _ <| |___
- *                             \___|\___/|_| \_\_____|
- *
- * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
- *
- * This software is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at https://curl.se/docs/copyright.html.
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so, under the terms of the COPYING file.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- * SPDX-License-Identifier: curl
- *
- ***************************************************************************/
-
-#include "curl_setup.h"
-
-#include "strtoofft.h"
-#include "strparse.h"
-
-/*
- * Parse a positive number up to 63-bit number written in ASCII. Skip leading
- * blanks. No support for prefixes.
- */
-CURLofft curlx_strtoofft(const char *str, char **endp, int base,
-                         curl_off_t *num)
-{
-  curl_off_t number;
-  int rc;
-  *num = 0; /* clear by default */
-  DEBUGASSERT((base == 10) || (base == 16));
-
-  Curl_str_passblanks(&str);
-  rc = base == 10 ?
-    Curl_str_number(&str, &number, CURL_OFF_T_MAX) :
-    Curl_str_hex(&str, &number, CURL_OFF_T_MAX);
-
-  if(endp)
-    *endp = (char *)str;
-  if(rc == STRE_OVERFLOW)
-    /* overflow */
-    return CURL_OFFT_FLOW;
-  else if(rc)
-    /* nothing parsed */
-    return CURL_OFFT_INVAL;
-
-  *num = number;
-  return CURL_OFFT_OK;
-}
diff --git a/lib/strtoofft.h b/lib/strtoofft.h
deleted file mode 100644 (file)
index 05b89fe..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef HEADER_CURL_STRTOOFFT_H
-#define HEADER_CURL_STRTOOFFT_H
-/***************************************************************************
- *                                  _   _ ____  _
- *  Project                     ___| | | |  _ \| |
- *                             / __| | | | |_) | |
- *                            | (__| |_| |  _ <| |___
- *                             \___|\___/|_| \_\_____|
- *
- * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
- *
- * This software is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at https://curl.se/docs/copyright.html.
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so, under the terms of the COPYING file.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- * SPDX-License-Identifier: curl
- *
- ***************************************************************************/
-
-#include "curl_setup.h"
-#include "strparse.h"
-
-typedef enum {
-  CURL_OFFT_OK,    /* parsed fine */
-  CURL_OFFT_FLOW,  /* over or underflow */
-  CURL_OFFT_INVAL  /* nothing was parsed */
-} CURLofft;
-
-CURLofft curlx_strtoofft(const char *str, char **endp, int base,
-                         curl_off_t *num);
-
-#endif /* HEADER_CURL_STRTOOFFT_H */
index f4d1e2a985a80e5972dbd6d093350a400aaf7589..d0480576b53fc6bb7037a059c58a435b52395886 100644 (file)
@@ -65,7 +65,6 @@
 #include "inet_ntop.h"
 #include "parsedate.h"          /* for the week day and month names */
 #include "sockaddr.h"           /* required for Curl_sockaddr_storage */
-#include "strtoofft.h"
 #include "strparse.h"
 #include "multiif.h"
 #include "select.h"
@@ -1603,29 +1602,29 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
         }
         if(data->state.use_range) {
           curl_off_t from, to;
-          char *ptr;
-          char *ptr2;
-          CURLofft to_t;
-          CURLofft from_t;
+          const char *p = data->state.range;
+          int from_t, to_t;
 
-          from_t = curlx_strtoofft(data->state.range, &ptr, 10, &from);
-          if(from_t == CURL_OFFT_FLOW) {
+          from_t = Curl_str_number(&p, &from, CURL_OFF_T_MAX);
+          if(from_t == STRE_OVERFLOW)
             return CURLE_RANGE_ERROR;
-          }
-          while(*ptr && (ISBLANK(*ptr) || (*ptr == '-')))
-            ptr++;
-          to_t = curlx_strtoofft(ptr, &ptr2, 10, &to);
-          if(to_t == CURL_OFFT_FLOW) {
+          Curl_str_passblanks(&p);
+          (void)Curl_str_single(&p, '-');
+
+          to_t = Curl_str_numblanks(&p, &to);
+          if(to_t == STRE_OVERFLOW)
             return CURLE_RANGE_ERROR;
-          }
-          if((to_t == CURL_OFFT_INVAL) /* no "to" value given */
-             || (to >= size)) {
+
+          if((to_t == STRE_NO_NUM) || (to >= size)) {
             to = size - 1;
+            to_t = STRE_OK;
           }
-          if(from_t) {
+
+          if(from_t == STRE_NO_NUM) {
             /* from is relative to end of file */
             from = size - to;
             to = size - 1;
+            from_t = STRE_OK;
           }
           if(from > size) {
             failf(data, "Offset (%" FMT_OFF_T ") was beyond file size (%"
index 1bc7a5e14d10952be6984ccb2e175d9fd0982894..06a6d94b594b17441c8d00cf27826b254aa73a7c 100644 (file)
@@ -68,7 +68,6 @@
 #include "inet_ntop.h"
 #include "parsedate.h" /* for the week day and month names */
 #include "sockaddr.h" /* required for Curl_sockaddr_storage */
-#include "strtoofft.h"
 #include "multiif.h"
 #include "select.h"
 #include "warnless.h"
@@ -1474,20 +1473,19 @@ sftp_download_stat(struct Curl_easy *data,
     }
     if(data->state.use_range) {
       curl_off_t from, to;
-      char *ptr;
-      char *ptr2;
-      CURLofft to_t;
-      CURLofft from_t;
+      const char *p = data->state.range;
+      int to_t, from_t;
 
-      from_t = curlx_strtoofft(data->state.range, &ptr, 10, &from);
-      if(from_t == CURL_OFFT_FLOW)
+      from_t = Curl_str_number(&p, &from, CURL_OFF_T_MAX);
+      if(from_t == STRE_OVERFLOW)
         return CURLE_RANGE_ERROR;
-      while(*ptr && (ISBLANK(*ptr) || (*ptr == '-')))
-        ptr++;
-      to_t = curlx_strtoofft(ptr, &ptr2, 10, &to);
-      if(to_t == CURL_OFFT_FLOW)
+      Curl_str_passblanks(&p);
+      (void)Curl_str_single(&p, '-');
+
+      to_t = Curl_str_numblanks(&p, &to);
+      if(to_t == STRE_OVERFLOW)
         return CURLE_RANGE_ERROR;
-      if((to_t == CURL_OFFT_INVAL) /* no "to" value given */
+      if((to_t == STRE_NO_NUM) /* no "to" value given */
          || (to >= size)) {
         to = size - 1;
       }
index 7ce9fb934024e615dec899d4d7633dbc47694c1e..d7b29f5283147bd06b54a83fe7a435993f16e524 100644 (file)
@@ -416,7 +416,6 @@ $       link'ldebug'/exe=[.src]curl.exe/dsf=[.src]curl.dsf -
            [.src]curl-tool_urlglob.o, [.src]curl-tool_util.o, -
            [.src]curl-tool_vms.o, [.src]curl-tool_writeenv.o, -
            [.src]curl-tool_writeout.o, [.src]curl-tool_xattr.o, -
-           [.src]curl-strtoofft.o, [.src]curl-strdup.o, [.src]curl-strcase.o, -
            [.src]curl-nonblock.o, gnv_packages_vms:curlmsg.obj,-
            sys$input:/opt
 gnv$libcurl/share
index d73b4f0a24c2c5cb057aa62109a2de12d53320a3..89e2389ec1294db5d0e39e7fd89af20be9df9d52 100644 (file)
@@ -151,7 +151,6 @@ rem
     ) else if "!var!" == "CURL_SRC_RC_FILES" (
       for /f "delims=" %%r in ('dir /b ..\src\*.rc') do call :element %1 src "%%r" %3
     ) else if "!var!" == "CURL_SRC_X_C_FILES" (
-      call :element %1 lib "strtoofft.c" %3
       call :element %1 lib "strparse.c" %3
       call :element %1 lib "strcase.c" %3
       call :element %1 lib "timediff.c" %3
@@ -164,7 +163,6 @@ rem
     ) else if "!var!" == "CURL_SRC_X_H_FILES" (
       call :element %1 lib "config-win32.h" %3
       call :element %1 lib "curl_setup.h" %3
-      call :element %1 lib "strtoofft.h" %3
       call :element %1 lib "strparse.h" %3
       call :element %1 lib "strcase.h" %3
       call :element %1 lib "timediff.h" %3
index b2d0d22cb3e3f3dbaea6e473e322a1ea613ebafd..06a3fd30aaf255ba6b5e7c913b62798c30f1d37a 100644 (file)
@@ -41,7 +41,6 @@ CURLX_CFILES = \
   ../lib/curl_multibyte.c \
   ../lib/dynbuf.c \
   ../lib/nonblock.c \
-  ../lib/strtoofft.c \
   ../lib/strparse.c \
   ../lib/strcase.c \
   ../lib/timediff.c \
@@ -54,7 +53,6 @@ CURLX_HFILES = \
   ../lib/curl_setup.h \
   ../lib/dynbuf.h \
   ../lib/nonblock.h \
-  ../lib/strtoofft.h \
   ../lib/strparse.h \
   ../lib/strcase.h \
   ../lib/timediff.h \
index de9ecb6e19c839e7d3a903854dbd357cad1e5135..30d902e95ace90ad36a6c3dc89acf11d32fc448f 100644 (file)
@@ -28,7 +28,7 @@
 #endif
 
 #include "terminal.h"
-#include "strtoofft.h"
+#include "curlx.h"
 
 #include "memdebug.h" /* keep this as LAST include */
 
index 46ca04184697701e2a778b744df99a469300d30c..7ecbe487b3dae216e6f94346e8c19b0b5f993a66 100644 (file)
@@ -27,7 +27,6 @@ noinst_PROGRAMS = resolve rtspd sockfilt sws tftpd socksd disabled mqttd
 CURLX_SRCS = \
  ../../lib/mprintf.c \
  ../../lib/nonblock.c \
- ../../lib/strtoofft.c \
  ../../lib/strparse.c \
  ../../lib/strequal.c \
  ../../lib/warnless.c \
@@ -41,7 +40,6 @@ CURLX_SRCS = \
 CURLX_HDRS = \
  ../../lib/curlx.h \
  ../../lib/nonblock.h \
- ../../lib/strtoofft.h \
  ../../lib/strcase.h \
  ../../lib/warnless.h \
  ../../lib/timediff.h \
index cb3d0fef4372716ee1a7a840351b04c2a8a19e5a..63440d6859bd58de96b7132baba313546096774a 100644 (file)
@@ -689,7 +689,6 @@ CURL_LIBCURL_LIBNAME=$(LIB_NAME_IMP)
 
 CURL_FROM_LIBCURL=\
  $(CURL_DIROBJ)\nonblock.obj \
- $(CURL_DIROBJ)\strtoofft.obj \
  $(CURL_DIROBJ)\strparse.obj \
  $(CURL_DIROBJ)\strcase.obj \
  $(CURL_DIROBJ)\warnless.obj \
@@ -716,8 +715,6 @@ $(CURL_DIROBJ)\tool_hugehelp.obj: $(CURL_SRC_DIR)\tool_hugehelp.c
 !ENDIF
 $(CURL_DIROBJ)\nonblock.obj: ../lib/nonblock.c
        $(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/nonblock.c
-$(CURL_DIROBJ)\strtoofft.obj: ../lib/strtoofft.c
-       $(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/strtoofft.c
 $(CURL_DIROBJ)\strparse.obj: ../lib/strparse.c
        $(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/strparse.c
 $(CURL_DIROBJ)\strcase.obj: ../lib/strcase.c