From 4ebecadf090c6602f8f571d24556e9b902ec5b20 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 31 Dec 2011 10:23:30 +0000 Subject: [PATCH] -LRN: OFF_T/off_t patch for 64-bit files on W32 --- src/include/gnunet_disk_lib.h | 20 +++++++++++++------- src/util/container_bloomfilter.c | 8 ++++---- src/util/disk.c | 29 +++++++++++++++-------------- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h index d0a9dfdb7..eab3c7bfa 100644 --- a/src/include/gnunet_disk_lib.h +++ b/src/include/gnunet_disk_lib.h @@ -25,6 +25,12 @@ #ifndef GNUNET_DISK_LIB_H #define GNUNET_DISK_LIB_H +#if WINDOWS +#define OFF_T uint64_t +#else +#define OFF_T off_t +#endif + /** * Opaque handle used to access files. */ @@ -295,8 +301,8 @@ GNUNET_DISK_file_test (const char *fil); * @param whence specification to which position the offset parameter relates to * @return the new position on success, GNUNET_SYSERR otherwise */ -off_t -GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset, +uint64_t +GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, uint64_t offset, enum GNUNET_DISK_Seek whence); @@ -378,7 +384,7 @@ GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, */ int GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, - off_t *size); + OFF_T *size); /** @@ -624,8 +630,8 @@ GNUNET_DISK_directory_create (const char *dir); * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, - off_t lockEnd, int excl); +GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, OFF_T lockStart, + OFF_T lockEnd, int excl); /** @@ -636,8 +642,8 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart, - off_t unlockEnd); +GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, OFF_T unlockStart, + OFF_T unlockEnd); /** diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c index 9ae8206fe..5016b70ef 100644 --- a/src/util/container_bloomfilter.c +++ b/src/util/container_bloomfilter.c @@ -183,7 +183,7 @@ static void incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh) { - off_t fileSlot; + uint64_t fileSlot; unsigned char value; unsigned int high; unsigned int low; @@ -231,7 +231,7 @@ static void decrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh) { - off_t fileSlot; + uint64_t fileSlot; unsigned char value; unsigned int high; unsigned int low; @@ -453,10 +453,10 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, { struct GNUNET_CONTAINER_BloomFilter *bf; char *rbuff; - off_t pos; + OFF_T pos; int i; size_t ui; - off_t fsize; + OFF_T fsize; int must_read; GNUNET_assert (NULL != filename); diff --git a/src/util/disk.c b/src/util/disk.c index 9e64a3a60..1131ade2d 100644 --- a/src/util/disk.c +++ b/src/util/disk.c @@ -204,7 +204,6 @@ GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h) #endif } - /** * Get the size of an open file. * @@ -214,7 +213,7 @@ GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h) */ int GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, - off_t *size) + OFF_T *size) { #if WINDOWS BOOL b; @@ -225,7 +224,7 @@ GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, SetErrnoFromWinError (GetLastError ()); return GNUNET_SYSERR; } - *size = (off_t) li.QuadPart; + *size = (OFF_T) li.QuadPart; #else struct stat sbuf; @@ -245,8 +244,8 @@ GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, * @param whence specification to which position the offset parameter relates to * @return the new position on success, GNUNET_SYSERR otherwise */ -off_t -GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset, +uint64_t +GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, uint64_t offset, enum GNUNET_DISK_Seek whence) { if (h == NULL) @@ -256,25 +255,27 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset, } #ifdef MINGW - DWORD ret; + LARGE_INTEGER li, new_pos; + BOOL b; static DWORD t[] = {[GNUNET_DISK_SEEK_SET] = FILE_BEGIN, [GNUNET_DISK_SEEK_CUR] = FILE_CURRENT,[GNUNET_DISK_SEEK_END] = FILE_END }; + li.QuadPart = offset; - ret = SetFilePointer (h->h, offset, NULL, t[whence]); - if (ret == INVALID_SET_FILE_POINTER) + b = SetFilePointerEx (h->h, li, &new_pos, t[whence]); + if (b == 0) { SetErrnoFromWinError (GetLastError ()); return GNUNET_SYSERR; } - return ret; + return new_pos.QuadPart; #else static int t[] = {[GNUNET_DISK_SEEK_SET] = SEEK_SET, [GNUNET_DISK_SEEK_CUR] = SEEK_CUR,[GNUNET_DISK_SEEK_END] = SEEK_END }; - return lseek (h->fd, offset, t[whence]); + return lseek64 (h->fd, offset, t[whence]); #endif } @@ -1251,8 +1252,8 @@ GNUNET_DISK_file_change_owner (const char *filename, const char *user) * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, - off_t lockEnd, int excl) +GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, OFF_T lockStart, + OFF_T lockEnd, int excl) { if (fh == NULL) { @@ -1297,8 +1298,8 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart, - off_t unlockEnd) +GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, OFF_T unlockStart, + OFF_T unlockEnd) { if (fh == NULL) { -- 2.25.1