bugfix
[oweals/gnunet.git] / src / util / container_bloomfilter.c
index 37780cb2a32d5646e254b184b1b124c53c28683d..cf99ac7b4944167a8f9d29234e24ca9a9d584fb0 100644 (file)
@@ -60,7 +60,7 @@ struct GNUNET_CONTAINER_BloomFilter
   /**
    * The bit counter file on disk
    */
-  struct GNUNET_IO_Handle *fh;
+  struct GNUNET_DISK_FileHandle *fh;
 
   /**
    * How many bits we set for each stored element
@@ -142,7 +142,7 @@ testBit (char *bitArray, unsigned int bitIdx)
  * @param fh A file to keep the 4 bit address usage counters in
  */
 static void
-incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_IO_Handle *fh)
+incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh)
 {
   unsigned int fileSlot;
   unsigned char value;
@@ -151,7 +151,7 @@ incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_IO_Handle
   unsigned int targetLoc;
 
   setBit (bitArray, bitIdx);
-  if (GNUNET_IO_handle_invalid (fh))
+  if (GNUNET_DISK_handle_invalid (fh))
     return;
   /* Update the counter file on disk */
   fileSlot = bitIdx / 2;
@@ -187,7 +187,7 @@ incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_IO_Handle
  * @param fh A file to keep the 4bit address usage counters in
  */
 static void
-decrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_IO_Handle *fh)
+decrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh)
 {
   unsigned int fileSlot;
   unsigned char value;
@@ -195,7 +195,7 @@ decrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_IO_Handle
   unsigned int low;
   unsigned int targetLoc;
 
-  if (GNUNET_IO_handle_invalid (fh))
+  if (GNUNET_DISK_handle_invalid (fh))
     return;                     /* cannot decrement! */
   /* Each char slot in the counter file holds two 4 bit counters */
   fileSlot = bitIdx / 2;
@@ -240,13 +240,13 @@ decrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_IO_Handle
  * @return GNUNET_OK if created ok, GNUNET_SYSERR otherwise
  */
 static int
-makeEmptyFile (const struct GNUNET_IO_Handle *fh, unsigned int size)
+makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, unsigned int size)
 {
   char *buffer;
   unsigned int bytesleft = size;
   int res = 0;
 
-  if (GNUNET_IO_handle_invalid (fh))
+  if (GNUNET_DISK_handle_invalid (fh))
     return GNUNET_SYSERR;
   buffer = GNUNET_malloc (BUFFSIZE);
   memset (buffer, 0, BUFFSIZE);
@@ -406,10 +406,10 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, unsigned int size,
   /* Try to open a bloomfilter file */
   if (filename != NULL)
     {
-      bf->fh = GNUNET_DISK_file_open (filename,
-          GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
+      bf->fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READWRITE
+                                     | GNUNET_DISK_OPEN_CREATE,
           GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
-      if (!bf->fh)
+      if (NULL == bf->fh)
         {
           GNUNET_free (bf);
           return NULL;
@@ -437,6 +437,12 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, unsigned int size,
           int res;
 
           res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
+         if (res == -1)
+           {
+             GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+                                       "read",
+                                       bf->filename);
+           }
           if (res == 0)
             break;              /* is ok! we just did not use that many bits yet */
           for (i = 0; i < res; i++)
@@ -535,7 +541,7 @@ GNUNET_CONTAINER_bloomfilter_free (struct GNUNET_CONTAINER_BloomFilter *bf)
     return;
   if (bf->filename != NULL)
     {
-      GNUNET_DISK_file_close (&bf->fh);
+      GNUNET_DISK_file_close (bf->fh);
       GNUNET_free (bf->filename);
     }
   GNUNET_free (bf->bitArray);