GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
enum GNUNET_DISK_AccessPermissions perm);
+
+/**
+ * Get the size of an open file.
+ *
+ * @param fh open file handle
+ * @param size where to write size of the file
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int
+GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
+ off_t *size);
+
+
/**
* Creates an interprocess channel
* @param blocking creates an asynchronous pipe if set to GNUNET_NO
off_t pos;
int i;
size_t ui;
+ off_t fsize;
GNUNET_assert (NULL != filename);
if ((k == 0) || (size == 0))
GNUNET_free (bf);
return NULL;
}
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_handle_size (bf->fh, &fsize))
+ {
+ GNUNET_DISK_file_close (bf->fh);
+ GNUNET_free (bf);
+ return NULL;
+ }
+ if (fsize != size * 8LL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Size of file on disk is incorrect for this Bloom filter\n"));
+ GNUNET_DISK_file_close (bf->fh);
+ GNUNET_free (bf);
+ return NULL;
+ }
bf->filename = GNUNET_strdup (filename);
/* Alloc block */
bf->bitArray = GNUNET_malloc_large (size);
/* Read from the file what bits we can */
rbuff = GNUNET_malloc (BUFFSIZE);
pos = 0;
- while (pos < size * 8)
+ while (pos < size * 8LL)
{
int res;
if (res == -1)
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename);
+ GNUNET_free (rbuff);
+ GNUNET_free (bf->filename);
+ GNUNET_DISK_file_close (bf->fh);
+ GNUNET_free (bf);
+ return NULL;
}
if (res == 0)
break; /* is ok! we just did not use that many bits yet */
}
+/**
+ * Get the size of an open file.
+ *
+ * @param fh open file handle
+ * @param size where to write size of the file
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int
+GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
+ off_t *size)
+{
+ struct stat sbuf;
+
+ if (0 != FSTAT (fh->fd, &sbuf))
+ return GNUNET_SYSERR;
+ *size = sbuf.st_size;
+ return GNUNET_OK;
+}
+
+
/**
* Move the read/write pointer in a file
*