curlx: promote Curl_fseeko() to curlx_fseek(), use it in src

- tool_formparse: replace truncated `fseek` with `curlx_fseek`.
- tool_operate: replace truncated `fseek` with `curlx_fseek`.
- tool_paramhlp: replace local duplicate `myfseek`, with `curlx_fseek`.

Follow-up to 4fb12f2891 #19100

Closes #19107
This commit is contained in:
Viktor Szakats 2025-10-17 18:31:52 +02:00
parent b9b8a7a5df
commit f32451c12b
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
8 changed files with 24 additions and 36 deletions

View file

@ -248,7 +248,7 @@ int tool_mime_stdin_seek(void *instream, curl_off_t offset, int whence)
if(offset < 0)
return CURL_SEEKFUNC_CANTSEEK;
if(!sip->data) {
if(fseek(stdin, (long) (offset + sip->origin), SEEK_SET))
if(curlx_fseek(stdin, offset + sip->origin, SEEK_SET))
return CURL_SEEKFUNC_CANTSEEK;
}
sip->curpos = offset;

View file

@ -584,10 +584,8 @@ static CURLcode retrycheck(struct OperationConfig *config,
rc = fseek(outs->stream, 0, SEEK_END);
#else
/* ftruncate is not available, so just reposition the file
to the location we would have truncated it. This will not
work properly with large files on 32-bit systems, but
most of those will have ftruncate. */
rc = fseek(outs->stream, (long)outs->init, SEEK_SET);
to the location we would have truncated it. */
rc = curlx_fseek(outs->stream, outs->init, SEEK_SET);
#endif
if(rc) {
errorf("Failed seeking to end of file");

View file

@ -119,19 +119,6 @@ ParameterError file2string(char **bufp, FILE *file)
return PARAM_OK;
}
static int myfseek(void *stream, curl_off_t offset, int whence)
{
#if defined(_WIN32) && defined(USE_WIN32_LARGE_FILES)
return _fseeki64(stream, (__int64)offset, whence);
#elif defined(HAVE_FSEEKO) && defined(HAVE_DECL_FSEEKO)
return fseeko(stream, (off_t)offset, whence);
#else
if(offset > LONG_MAX)
return -1;
return fseek(stream, (long)offset, whence);
#endif
}
ParameterError file2memory_range(char **bufp, size_t *size, FILE *file,
curl_off_t starto, curl_off_t endo)
{
@ -143,7 +130,7 @@ ParameterError file2memory_range(char **bufp, size_t *size, FILE *file,
if(starto) {
if(file != stdin) {
if(myfseek(file, starto, SEEK_SET))
if(curlx_fseek(file, starto, SEEK_SET))
return PARAM_READ_ERROR;
offset = starto;
}