]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curlx: promote `Curl_fseeko()` to `curlx_fseek()`, use it in `src`
authorViktor Szakats <commit@vsz.me>
Fri, 17 Oct 2025 16:31:52 +0000 (18:31 +0200)
committerViktor Szakats <commit@vsz.me>
Sat, 18 Oct 2025 00:25:10 +0000 (02:25 +0200)
- 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 4fb12f289189e8113967e9c9da09958fd8bfa4cb #19100

Closes #19107

lib/curlx/fopen.c
lib/curlx/fopen.h
lib/formdata.c
lib/mime.c
lib/mime.h
src/tool_formparse.c
src/tool_operate.c
src/tool_paramhlp.c

index 22c7259c70dd1e3b8b2bb2a2c0cc98b67d0302e9..cc164c8c29b4dd62a8fe0bf292af791a0ec825cc 100644 (file)
 
 #include "../curl_setup.h"
 
+#include "fopen.h"
+
+int curlx_fseek(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
+}
+
 #if defined(_WIN32) && !defined(UNDER_CE)
 
-#include "fopen.h"
 #include "multibyte.h"
 
 /* declare GetFullPathNameW for mingw-w64 UWP builds targeting old windows */
index b44cbbdfced2fdba5182b705eee2995e057e3ec9..51f4dbca173b5323637263a947e236698f716105 100644 (file)
@@ -32,6 +32,8 @@
 #include <fcntl.h>  /* for open() and attributes */
 #endif
 
+int curlx_fseek(void *stream, curl_off_t offset, int whence);
+
 #if defined(_WIN32) && !defined(UNDER_CE)
 FILE *curlx_win32_fopen(const char *filename, const char *mode);
 int curlx_win32_stat(const char *path, struct_stat *buffer);
index 382fd221dce63d6fa03d784ac05d08b6849974dc..74a73028cd8c72fe5d05ae3e0972a2e4604fc274 100644 (file)
@@ -37,6 +37,7 @@ struct Curl_easy;
 #include "sendf.h"
 #include "strdup.h"
 #include "rand.h"
+#include "curlx/fopen.h"
 #include "curlx/warnless.h"
 
 /* The last 2 #include files should be in this order */
@@ -860,7 +861,7 @@ CURLcode Curl_getformdata(CURL *data,
 #endif
             result = curl_mime_data_cb(part, (curl_off_t) -1,
                                        (curl_read_callback) fread,
-                                       Curl_fseeko,
+                                       curlx_fseek,
                                        NULL, (void *) stdin);
 #if defined(__clang__) && __clang_major__ >= 16
 #pragma clang diagnostic pop
index baca30049f73bb9f13d6866823c7c52275eadf55..0a56b07bc51b1110b8c60181f241cfc7348621ac 100644 (file)
@@ -271,19 +271,6 @@ static char *Curl_basename(char *path)
 #define basename(x)  Curl_basename((x))
 #endif
 
-int Curl_fseeko(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
-}
-
 
 /* Set readback state. */
 static void mimesetstate(struct mime_state *state,
@@ -750,7 +737,7 @@ static int mime_file_seek(void *instream, curl_off_t offset, int whence)
   if(mime_open_file(part))
     return CURL_SEEKFUNC_FAIL;
 
-  return Curl_fseeko(part->fp, offset, whence) ?
+  return curlx_fseek(part->fp, offset, whence) ?
     CURL_SEEKFUNC_CANTSEEK : CURL_SEEKFUNC_OK;
 }
 
index dc6f0d4af176d8dc713380fd74f86c40f8cf758d..5073a38f709a03b8c910a477303f44a13d973c23 100644 (file)
@@ -138,7 +138,6 @@ CURLcode Curl_mime_add_header(struct curl_slist **slp, const char *fmt, ...)
                                     !defined(CURL_DISABLE_IMAP))
 
 /* Prototypes. */
-int Curl_fseeko(void *stream, curl_off_t offset, int whence);
 void Curl_mime_initpart(struct curl_mimepart *part);
 void Curl_mime_cleanpart(struct curl_mimepart *part);
 CURLcode Curl_mime_duppart(struct Curl_easy *data,
index cd3cf52e3ebd270422c40783add02768a933c03a..0f0962ce0d1f6255a57a7f22f1ed5d18828f1aac 100644 (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;
index c7d01bb59af22930205b657f61c7001a0066b99c..00a98b360ba04413fafaafb4a70a4483908a074e 100644 (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");
index 85c24f2ea355a090248fe0d5e0be58240357e71d..fda05398783e368c88ac74d31de76b0a66168ce0 100644 (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;
       }