- 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 is the full list of functions generally banned.
_access
+ _lseeki64
_mbscat
_mbsncat
_open
getaddrinfo
gets
gmtime
+ llseek
LoadLibrary
LoadLibraryA
LoadLibraryEx
LoadLibraryExW
LoadLibraryW
localtime
+ lseek
malloc
mbstowcs
MoveFileEx
# 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
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 {
my %banfunc = (
"_access" => 1,
+ "_lseeki64" => 1,
"_mbscat" => 1,
"_mbsncat" => 1,
"_open" => 1,
"getaddrinfo" => 1,
"gets" => 1,
"gmtime" => 1,
+ "llseek" => 1,
"LoadLibrary" => 1,
"LoadLibraryA" => 1,
"LoadLibraryEx" => 1,
"LoadLibraryExW" => 1,
"LoadLibraryW" => 1,
"localtime" => 1,
+ "lseek" => 1,
"malloc" => 1,
"mbstowcs" => 1,
"MoveFileEx" => 1,
/* 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;
}
#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. */
{
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))
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 */