From: Viktor Szakats Date: Sun, 1 Feb 2026 00:04:58 +0000 (+0100) Subject: build: tidy up local `lseek()` mappings X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96fa42c7c03fc54c9d8311355253fadc3d5240f2;p=thirdparty%2Fcurl.git build: tidy up local `lseek()` mappings - 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 --- diff --git a/docs/internals/CODE_STYLE.md b/docs/internals/CODE_STYLE.md index 6167eaad00..08a5ebef33 100644 --- a/docs/internals/CODE_STYLE.md +++ b/docs/internals/CODE_STYLE.md @@ -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 diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 432d850183..dcfa712e61 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -490,28 +490,28 @@ # include # include /* 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 -# 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 diff --git a/lib/file.c b/lib/file.c index d4cfedff17..fda1472dbf 100644 --- a/lib/file.c +++ b/lib/file.c @@ -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 { diff --git a/scripts/checksrc.pl b/scripts/checksrc.pl index 7dab44353b..288ff2a5e0 100755 --- a/scripts/checksrc.pl +++ b/scripts/checksrc.pl @@ -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, diff --git a/src/tool_cb_see.c b/src/tool_cb_see.c index 112faf0dc2..a1983b94cc 100644 --- a/src/tool_cb_see.c +++ b/src/tool_cb_see.c @@ -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. */ diff --git a/src/tool_util.c b/src/tool_util.c index 96b0715b0a..60b3b37cb2 100644 --- a/src/tool_util.c +++ b/src/tool_util.c @@ -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)) diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index 031e4cf2be..ff894bd430 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -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 */