]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Improve portability to old Windows systems by using SetFilePointer
authorTim Kientzle <kientzle@gmail.com>
Sat, 19 Nov 2011 01:45:13 +0000 (20:45 -0500)
committerTim Kientzle <kientzle@gmail.com>
Sat, 19 Nov 2011 01:45:13 +0000 (20:45 -0500)
instead of SetFilePointerEx.
Fix a couple of uninitialized variables.

From: Denis B MARTIN

SVN-Revision: 3807

libarchive/archive_read_disk_windows.c
libarchive/archive_windows.c
libarchive/archive_write_disk_windows.c

index 582fc335a038184055d1c314c950f0ff92fce1e6..d8a1f5577b1877a5c5d72dcfd9004304bb896803 100644 (file)
@@ -86,6 +86,21 @@ __FBSDID("$FreeBSD$");
 #define        IO_REPARSE_TAG_SYMLINK 0xA000000CL
 #endif
 
+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;
+}
+
 /*-
  * This is a new directory-walking system that addresses a number
  * of problems I've had with fts(3).  In particular, it has no
@@ -583,7 +598,7 @@ _archive_read_data_block(struct archive *_a, const void **buff,
        if (t->current_sparse->offset > t->entry_total) {
                LARGE_INTEGER distance;
                distance.QuadPart = t->current_sparse->offset;
-               if (!SetFilePointerEx(t->entry_fh, distance, NULL, FILE_BEGIN)) {
+               if (!SetFilePointerEx_perso(t->entry_fh, distance, NULL, FILE_BEGIN)) {
                        DWORD lasterr;
 
                        lasterr = GetLastError();
@@ -1738,7 +1753,7 @@ archive_read_disk_entry_from_file(struct archive *_a,
        const char *name;
        HANDLE h;
        BY_HANDLE_FILE_INFORMATION bhfi;
-       DWORD fileAttributes;
+       DWORD fileAttributes = 0;
        int r;
 
        archive_clear_error(_a);
index 38480a3c4979cabfd403349bf668432235e5a6bd..45ae9d0f0de15aa895fae7a761e3edadc56835af 100644 (file)
@@ -64,9 +64,7 @@
 
 #define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000)
 
-#if defined(_MSC_VER) && _MSC_VER < 1300
-/* VS 6 does not provide SetFilePointerEx, so define it here.  */
-static BOOL SetFilePointerEx(HANDLE hFile,
+static BOOL SetFilePointerEx_perso(HANDLE hFile,
                              LARGE_INTEGER liDistanceToMove,
                              PLARGE_INTEGER lpNewFilePointer,
                              DWORD dwMoveMethod)
@@ -80,7 +78,6 @@ static BOOL SetFilePointerEx(HANDLE hFile,
        }
        return li.LowPart != -1 || GetLastError() == NO_ERROR;
 }
-#endif
 
 struct ustat {
        int64_t         st_atime;
@@ -285,7 +282,7 @@ __la_lseek(int fd, __int64 offset, int whence)
                return (-1);
        }
        distance.QuadPart = offset;
-       if (!SetFilePointerEx(handle, distance, &newpointer, whence)) {
+       if (!SetFilePointerEx_perso(handle, distance, &newpointer, whence)) {
                DWORD lasterr;
 
                lasterr = GetLastError();
index 799969b7cddf7ed3471988dad7ebe036c6a18055..92d54e041a0ae7638322c70904031117d7013a37 100644 (file)
@@ -77,6 +77,21 @@ __FBSDID("$FreeBSD$");
 #define        IO_REPARSE_TAG_SYMLINK 0xA000000CL
 #endif
 
+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;
+}
+
 struct fixup_entry {
        struct fixup_entry      *next;
        struct archive_acl       acl;
@@ -546,7 +561,7 @@ la_ftruncate(HANDLE handle, int64_t length)
                return (-1);
        }
        distance.QuadPart = length;
-       if (!SetFilePointerEx(handle, distance, NULL, FILE_BEGIN)) {
+       if (!SetFilePointerEx_perso(handle, distance, NULL, FILE_BEGIN)) {
                la_dosmaperr(GetLastError());
                return (-1);
        }
@@ -936,7 +951,7 @@ write_data_block(struct archive_write_disk *a, const char *buff, size_t size)
                if (a->offset != a->fd_offset) {
                        LARGE_INTEGER distance;
                        distance.QuadPart = a->offset;
-                       if (SetFilePointerEx(a->fh, distance, NULL, FILE_BEGIN) == 0) {
+                       if (SetFilePointerEx_perso(a->fh, distance, NULL, FILE_BEGIN) == 0) {
                                DWORD lasterr = GetLastError();
                                if (lasterr == ERROR_ACCESS_DENIED)
                                        errno = EBADF;
@@ -1044,7 +1059,7 @@ _archive_write_disk_finish_entry(struct archive *_a)
                        const char nul = '\0';
                        LARGE_INTEGER distance;
                        distance.QuadPart = a->filesize - 1;
-                       if (!SetFilePointerEx(a->fh, distance, NULL, FILE_BEGIN)) {
+                       if (!SetFilePointerEx_perso(a->fh, distance, NULL, FILE_BEGIN)) {
                                DWORD lasterr = GetLastError();
                                if (lasterr == ERROR_ACCESS_DENIED)
                                        errno = EBADF;
@@ -2232,7 +2247,7 @@ set_times(struct archive_write_disk *a,
 #define WINTIME(sec, nsec) ((Int32x32To64(sec, 10000000) + EPOC_TIME)\
         + (((nsec)/1000)*10))
 
-       HANDLE hw;
+       HANDLE hw = 0;
        ULARGE_INTEGER wintm;
        FILETIME *pfbtime;
        FILETIME fatime, fbtime, fmtime;