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
This commit is contained in:
Viktor Szakats 2026-02-01 01:04:58 +01:00
parent 47734f3244
commit 96fa42c7c0
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
7 changed files with 24 additions and 27 deletions

View 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

View file

@ -490,28 +490,28 @@
# 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

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

View file

@ -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,

View 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. */

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

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