From ec48f10656758fd095ad8a25820fa66e923d90aa Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 20 Dec 2011 14:20:15 -0500 Subject: [PATCH] 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. --- .../cmlibarchive/libarchive/archive_windows.c | 51 +++++++++++++++++++ .../cmlibarchive/libarchive/archive_windows.h | 8 +++ 2 files changed, 59 insertions(+) diff --git a/Utilities/cmlibarchive/libarchive/archive_windows.c b/Utilities/cmlibarchive/libarchive/archive_windows.c index af104b86a..51860ac4d 100644 --- a/Utilities/cmlibarchive/libarchive/archive_windows.c +++ b/Utilities/cmlibarchive/libarchive/archive_windows.c @@ -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, ...) diff --git a/Utilities/cmlibarchive/libarchive/archive_windows.h b/Utilities/cmlibarchive/libarchive/archive_windows.h index b26811e54..51b4a8600 100644 --- a/Utilities/cmlibarchive/libarchive/archive_windows.h +++ b/Utilities/cmlibarchive/libarchive/archive_windows.h @@ -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);