From: Daniel Stenberg Date: Mon, 10 Mar 2025 07:12:05 +0000 (+0100) Subject: lib: rename curlx_strtoofft to Curl_str_numblanks() X-Git-Tag: curl-8_13_0~196 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=09a5b2f2de91e2628cde469514d7c04133988b1b;p=thirdparty%2Fcurl.git lib: rename curlx_strtoofft to Curl_str_numblanks() The function is no longer used via the curlx shortcut. Remove the strtoofft.[ch] files. Closes #16642 --- diff --git a/lib/Makefile.inc b/lib/Makefile.inc index 58ce220e7b..c7a03f31d2 100644 --- a/lib/Makefile.inc +++ b/lib/Makefile.inc @@ -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 \ diff --git a/lib/cf-h1-proxy.c b/lib/cf-h1-proxy.c index 4698f014a7..3be85cd253 100644 --- a/lib/cf-h1-proxy.c +++ b/lib/cf-h1-proxy.c @@ -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; } diff --git a/lib/curlx.h b/lib/curlx.h index f0e4e6470b..6db9620986 100644 --- a/lib/curlx.h +++ b/lib/curlx.h @@ -37,11 +37,6 @@ #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 */ diff --git a/lib/ftplistparser.c b/lib/ftplistparser.c index 9f60cf931c..b5739bd3f0 100644 --- a/lib/ftplistparser.c +++ b/lib/ftplistparser.c @@ -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; } diff --git a/lib/http.c b/lib/http.c index 466080cb79..5a5636c017 100644 --- a/lib/http.c +++ b/lib/http.c @@ -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"); diff --git a/lib/strparse.c b/lib/strparse.c index db31cd7125..1d53ba6757 100644 --- a/lib/strparse.c +++ b/lib/strparse.c @@ -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) diff --git a/lib/strparse.h b/lib/strparse.h index a3f9d8b082..739ea31a17 100644 --- a/lib/strparse.h +++ b/lib/strparse.h @@ -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 index 6da60cd5e5..0000000000 --- a/lib/strtoofft.c +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , 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 index 05b89fee69..0000000000 --- a/lib/strtoofft.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef HEADER_CURL_STRTOOFFT_H -#define HEADER_CURL_STRTOOFFT_H -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) Daniel Stenberg, , 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 */ diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index f4d1e2a985..d0480576b5 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -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 (%" diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c index 1bc7a5e14d..06a6d94b59 100644 --- a/lib/vssh/libssh2.c +++ b/lib/vssh/libssh2.c @@ -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; } diff --git a/packages/vms/gnv_link_curl.com b/packages/vms/gnv_link_curl.com index 7ce9fb9340..d7b29f5283 100644 --- a/packages/vms/gnv_link_curl.com +++ b/packages/vms/gnv_link_curl.com @@ -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 diff --git a/projects/generate.bat b/projects/generate.bat index d73b4f0a24..89e2389ec1 100644 --- a/projects/generate.bat +++ b/projects/generate.bat @@ -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 diff --git a/src/Makefile.inc b/src/Makefile.inc index b2d0d22cb3..06a3fd30aa 100644 --- a/src/Makefile.inc +++ b/src/Makefile.inc @@ -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 \ diff --git a/src/terminal.c b/src/terminal.c index de9ecb6e19..30d902e95a 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -28,7 +28,7 @@ #endif #include "terminal.h" -#include "strtoofft.h" +#include "curlx.h" #include "memdebug.h" /* keep this as LAST include */ diff --git a/tests/server/Makefile.inc b/tests/server/Makefile.inc index 46ca041846..7ecbe487b3 100644 --- a/tests/server/Makefile.inc +++ b/tests/server/Makefile.inc @@ -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 \ diff --git a/winbuild/MakefileBuild.vc b/winbuild/MakefileBuild.vc index cb3d0fef43..63440d6859 100644 --- a/winbuild/MakefileBuild.vc +++ b/winbuild/MakefileBuild.vc @@ -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