libarchive: Implement custom lseek for Borland

Restore Windows 64-bit lseek removed by upstream svn revision 3826
(Cast away __la_lseek(), use _lseeki64() instead, 2011-11-21).  We
need it on Borland.
This commit is contained in:
Brad King 2011-12-20 14:20:15 -05:00
parent c37c0c7897
commit ec48f10656
2 changed files with 59 additions and 0 deletions

View File

@ -64,6 +64,23 @@
#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000)
#if defined(__LA_LSEEK_NEEDED)
static BOOL SetFilePointerEx_perso(HANDLE hFile,
LARGE_INTEGER liDistanceToMove,
PLARGE_INTEGER lpNewFilePointer,
DWORD dwMoveMethod)
{
LARGE_INTEGER li;
li.QuadPart = liDistanceToMove.QuadPart;
li.LowPart = SetFilePointer(
hFile, li.LowPart, &li.HighPart, dwMoveMethod);
if(lpNewFilePointer) {
lpNewFilePointer->QuadPart = li.QuadPart;
}
return li.LowPart != -1 || GetLastError() == NO_ERROR;
}
#endif
struct ustat {
int64_t st_atime;
uint32_t st_atime_nsec;
@ -250,6 +267,40 @@ __la_fcntl(int fd, int cmd, int val)
return (-1);
}
#if defined(__LA_LSEEK_NEEDED)
__int64
__la_lseek(int fd, __int64 offset, int whence)
{
LARGE_INTEGER distance;
LARGE_INTEGER newpointer;
HANDLE handle;
if (fd < 0) {
errno = EBADF;
return (-1);
}
handle = (HANDLE)_get_osfhandle(fd);
if (GetFileType(handle) != FILE_TYPE_DISK) {
errno = EBADF;
return (-1);
}
distance.QuadPart = offset;
if (!SetFilePointerEx_perso(handle, distance, &newpointer, whence)) {
DWORD lasterr;
lasterr = GetLastError();
if (lasterr == ERROR_BROKEN_PIPE)
return (0);
if (lasterr == ERROR_ACCESS_DENIED)
errno = EBADF;
else
la_dosmaperr(lasterr);
return (-1);
}
return (newpointer.QuadPart);
}
#endif
/* This can exceed MAX_PATH limitation. */
int
__la_open(const char *path, int flags, ...)

View File

@ -95,7 +95,12 @@
#define fileno _fileno
#endif
#define fstat __la_fstat
#if !defined(__BORLANDC__)
#define lseek _lseeki64
#else
#define lseek __la_lseek
#define __LA_LSEEK_NEEDED
#endif
#define lstat __la_stat
#define open __la_open
#define read __la_read
@ -246,6 +251,9 @@
extern int __la_fcntl(int fd, int cmd, int val);
extern int __la_fstat(int fd, struct stat *st);
extern int __la_lstat(const char *path, struct stat *st);
#if defined(__LA_LSEEK_NEEDED)
extern __int64 __la_lseek(int fd, __int64 offset, int whence);
#endif
extern int __la_open(const char *path, int flags, ...);
extern ssize_t __la_read(int fd, void *buf, size_t nbytes);
extern int __la_stat(const char *path, struct stat *st);