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
This commit is contained in:
Daniel Stenberg 2025-03-10 08:12:05 +01:00
parent fc04eca8f8
commit 09a5b2f2de
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
17 changed files with 53 additions and 160 deletions

View 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 \

View 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;
}

View file

@ -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 */

View 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;
}

View 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");

View 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)

View 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);

View file

@ -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;
}

View file

@ -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 */

View 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 (%"

View 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;
}

View 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

View 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

View 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 \

View file

@ -28,7 +28,7 @@
#endif
#include "terminal.h"
#include "strtoofft.h"
#include "curlx.h"
#include "memdebug.h" /* keep this as LAST include */

View 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 \

View 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