-LRN: OFF_T/off_t patch for 64-bit files on W32
authorChristian Grothoff <christian@grothoff.org>
Sat, 31 Dec 2011 10:23:30 +0000 (10:23 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 31 Dec 2011 10:23:30 +0000 (10:23 +0000)
src/include/gnunet_disk_lib.h
src/util/container_bloomfilter.c
src/util/disk.c

index d0a9dfdb7563b940571ef9783488e24353c951c7..eab3c7bfa05d3390d553743ec4f008267445ae8f 100644 (file)
 #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);
 
 
 /**
index 9ae8206fe17721d2c04e9a92d57d0d04cc1773d8..5016b70efae0412de72c70c94343dbdbbc7743f4 100644 (file)
@@ -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);
index 9e64a3a60c3fec00da11b3412b891fbd89cdaeee..1131ade2d1ce4ca070c5db30cb6d0b7af4ed5344 100644 (file)
@@ -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)
   {