From: Brad King Date: Wed, 11 Jan 2012 13:15:03 +0000 (-0500) Subject: Implement custom lseek for Borland X-Git-Tag: v3.0.4~2^2~201 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=127c687a88d55761c3593ffcb61ec0c3860ed57f;p=thirdparty%2Flibarchive.git 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. SVN-Revision: 4125 --- diff --git a/libarchive/archive_windows.c b/libarchive/archive_windows.c index 4d37a9c25..e348b1703 100644 --- a/libarchive/archive_windows.c +++ b/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; @@ -234,6 +251,40 @@ la_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode, return (handle); } +#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/libarchive/archive_windows.h b/libarchive/archive_windows.h index cfb3e97d2..53deadd93 100644 --- a/libarchive/archive_windows.h +++ b/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 @@ -245,6 +250,9 @@ /* Replacement POSIX function */ 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);