]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
build: tidy up local `lseek()` mappings
authorViktor Szakats <commit@vsz.me>
Sun, 1 Feb 2026 00:04:58 +0000 (01:04 +0100)
committerViktor Szakats <commit@vsz.me>
Sun, 1 Feb 2026 16:29:39 +0000 (17:29 +0100)
- stop redefining system symbol `lseek`, by introducing `curl_lseek()`.
- handle AmigaOS quirk within the macro mapping.
- add missing parenthesis to `LSEEK_ERROR` values.
- tool_util: use curl `lseek` macros in `tool_ftruncate64()`.
- move `LSEEK_ERROR` to right-hand side of if expressions.
- checksrc: disallow direct uses of `_lseeki64`, `llseek`, `lseek`.

Closes #20488

docs/internals/CODE_STYLE.md
lib/curl_setup.h
lib/file.c
scripts/checksrc.pl
src/tool_cb_see.c
src/tool_util.c
tests/server/tftpd.c

index 6167eaad001f6c1dd88a6110bb7b267536d638b1..08a5ebef333d109bafe18f71b1421721fc6ca0c4 100644 (file)
@@ -332,6 +332,7 @@ makes us write better code.
 This is the full list of functions generally banned.
 
     _access
+    _lseeki64
     _mbscat
     _mbsncat
     _open
@@ -367,6 +368,7 @@ This is the full list of functions generally banned.
     getaddrinfo
     gets
     gmtime
+    llseek
     LoadLibrary
     LoadLibraryA
     LoadLibraryEx
@@ -374,6 +376,7 @@ This is the full list of functions generally banned.
     LoadLibraryExW
     LoadLibraryW
     localtime
+    lseek
     malloc
     mbstowcs
     MoveFileEx
index 432d85018349906ee6e7695f8d78b87de01d0f04..dcfa712e61cba4804a3c3a039d52692488d7a860 100644 (file)
 #  include <sys/types.h>
 #  include <sys/stat.h>
    /* Large file (>2Gb) support using Win32 functions. */
-#  undef  lseek
-#  define lseek(fdes, offset, whence)  _lseeki64(fdes, offset, whence)
 #  undef  fstat
-#  define fstat(fdes, stp)             _fstati64(fdes, stp)
-#  define struct_stat                  struct _stati64
-#  define LSEEK_ERROR                  (__int64)-1
+#  define fstat(fdes, stp)                _fstati64(fdes, stp)
+#  define struct_stat                     struct _stati64
+#  define curl_lseek                      _lseeki64
+#  define LSEEK_ERROR                     ((__int64)-1)
 #elif defined(__DJGPP__)
    /* Requires DJGPP 2.04 */
 #  include <unistd.h>
-#  undef  lseek
-#  define lseek(fdes, offset, whence)  llseek(fdes, offset, whence)
-#  define LSEEK_ERROR                  (offset_t)-1
+#  define curl_lseek                      llseek
+#  define LSEEK_ERROR                     ((offset_t)-1)
+#elif defined(__AMIGA__)
+#  define curl_lseek(fd, offset, whence)  lseek(fd, (off_t)(offset), whence)
+#  define LSEEK_ERROR                     ((off_t)-1)
+#else
+#  define curl_lseek                      lseek
+#  define LSEEK_ERROR                     ((off_t)-1)
 #endif
 
 #ifndef struct_stat
 #define struct_stat struct stat
 #endif
 
-#ifndef LSEEK_ERROR
-#define LSEEK_ERROR (off_t)-1
-#endif
-
 #ifndef SIZEOF_TIME_T
 /* assume default size of time_t to be 32 bits */
 #define SIZEOF_TIME_T 4
index d4cfedff1743a3f532d09236c32392e05bba7740..fda1472dbf9470b50a3fd5e2ee13e8a4783e700f 100644 (file)
@@ -517,13 +517,8 @@ static CURLcode file_do(struct Curl_easy *data, bool *done)
 
   if(data->state.resume_from) {
     if(!S_ISDIR(statbuf.st_mode)) {
-#ifdef __AMIGA__
       if(data->state.resume_from !=
-         lseek(fd, (off_t)data->state.resume_from, SEEK_SET))
-#else
-      if(data->state.resume_from !=
-         lseek(fd, data->state.resume_from, SEEK_SET))
-#endif
+         curl_lseek(fd, data->state.resume_from, SEEK_SET))
         return CURLE_BAD_DOWNLOAD_RESUME;
     }
     else {
index 7dab44353b2618efbd9abf8a708b6e825222689f..288ff2a5e0b328a7c8cb1bbb59d7fa3a1aa5890c 100755 (executable)
@@ -49,6 +49,7 @@ my @ignore_line;
 
 my %banfunc = (
     "_access" => 1,
+    "_lseeki64" => 1,
     "_mbscat" => 1,
     "_mbsncat" => 1,
     "_open" => 1,
@@ -84,6 +85,7 @@ my %banfunc = (
     "getaddrinfo" => 1,
     "gets" => 1,
     "gmtime" => 1,
+    "llseek" => 1,
     "LoadLibrary" => 1,
     "LoadLibraryA" => 1,
     "LoadLibraryEx" => 1,
@@ -91,6 +93,7 @@ my %banfunc = (
     "LoadLibraryExW" => 1,
     "LoadLibraryW" => 1,
     "localtime" => 1,
+    "lseek" => 1,
     "malloc" => 1,
     "mbstowcs" => 1,
     "MoveFileEx" => 1,
index 112faf0dc24aef11ee480368bf9044f8833dd076..a1983b94cc5b35179c6b44c36305e26077837d08 100644 (file)
@@ -61,13 +61,13 @@ int tool_seek_cb(void *userdata, curl_off_t offset, int whence)
       /* this code path does not support other types */
       return CURL_SEEKFUNC_FAIL;
 
-    if(LSEEK_ERROR == lseek(per->infd, 0, SEEK_SET))
+    if(curl_lseek(per->infd, 0, SEEK_SET) == LSEEK_ERROR)
       /* could not rewind to beginning */
       return CURL_SEEKFUNC_FAIL;
 
     while(left) {
       long step = (left > OUR_MAX_SEEK_O) ? OUR_MAX_SEEK_L : (long)left;
-      if(LSEEK_ERROR == lseek(per->infd, step, SEEK_CUR))
+      if(curl_lseek(per->infd, step, SEEK_CUR) == LSEEK_ERROR)
         /* could not seek forwards the desired amount */
         return CURL_SEEKFUNC_FAIL;
       left -= step;
@@ -76,11 +76,7 @@ int tool_seek_cb(void *userdata, curl_off_t offset, int whence)
   }
 #endif
 
-#ifdef __AMIGA__
-  if(LSEEK_ERROR == lseek(per->infd, (off_t)offset, whence))
-#else
-  if(LSEEK_ERROR == lseek(per->infd, offset, whence))
-#endif
+  if(curl_lseek(per->infd, offset, whence) == LSEEK_ERROR)
     /* could not rewind, the reason is in errno but errno is just not portable
        enough and we do not actually care that much why we failed. We will let
        libcurl know that it may try other means if it wants to. */
index 96b0715b0af3105e217038bc6f8a72f25db65eac..60b3b37cb292a00556adea34ce677bc69abb2ef6 100644 (file)
@@ -86,7 +86,7 @@ int tool_ftruncate64(int fd, curl_off_t where)
 {
   intptr_t handle = _get_osfhandle(fd);
 
-  if(_lseeki64(fd, where, SEEK_SET) < 0)
+  if(curl_lseek(fd, where, SEEK_SET) == LSEEK_ERROR)
     return -1;
 
   if(!SetEndOfFile((HANDLE)handle))
index 031e4cf2be8eaf9c746493d8e72017346fb0ae03..ff894bd4308d95906c1fa72e056bbda573acb43c 100644 (file)
@@ -454,7 +454,7 @@ static ssize_t write_behind(struct testcase *test, int convert)
     c = *p++;                     /* pick up a character */
     if(prevchar == '\r') {        /* if prev char was cr */
       if(c == '\n')               /* if have cr,lf then just */
-        lseek(test->ofile, -1, SEEK_CUR); /* smash lf on top of the cr */
+        curl_lseek(test->ofile, -1, SEEK_CUR); /* smash lf on top of the cr */
       else if(c == '\0')          /* if have cr,nul then */
         goto skipit;              /* just skip over the putc */
       /* else just fall through and allow it */