more consistent disk API
authorChristian Grothoff <christian@grothoff.org>
Sun, 25 Oct 2009 19:28:48 +0000 (19:28 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 25 Oct 2009 19:28:48 +0000 (19:28 +0000)
src/include/gnunet_disk_lib.h
src/peerinfo/gnunet-service-peerinfo.c
src/util/disk.c
src/util/pseudonym.c
src/util/test_disk.c

index 69f7fb825f7a873f12d65f5ca2dcddb0a0f4da23..fc5b9b5eba58cfcc561922cd957a8e66fd5fb781 100644 (file)
@@ -327,6 +327,7 @@ struct GNUNET_DISK_FileHandle *GNUNET_DISK_file_open (const char *fn,
  */
 struct GNUNET_DISK_PipeHandle *GNUNET_DISK_pipe (int blocking);
 
+
 /**
  * Closes an interprocess channel
  * @param p pipe
@@ -334,6 +335,7 @@ struct GNUNET_DISK_PipeHandle *GNUNET_DISK_pipe (int blocking);
  */
 int GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p);
 
+
 /**
  * Close an open file.
  *
@@ -342,6 +344,7 @@ int GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p);
  */
 int GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h);
 
+
 /**
  * Get the handle to a particular pipe end
  * @param p pipe
@@ -384,7 +387,7 @@ ssize_t GNUNET_DISK_fn_read (const char *fn,
  * @param h handle to open file
  * @param buffer the data to write
  * @param n number of bytes to write
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ * @return number of bytes written on success, GNUNET_SYSERR on error
  */
 ssize_t GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, 
                                const void *buffer,
index 3608dab84c1b6d6994318a1f7d0523e97a89ed97..b9b242522fcaff214cc6efcdd64a15b2ba3a33e3 100644 (file)
@@ -477,9 +477,10 @@ flush_trust (struct HostEntry *host)
   else
     {
       trust = htonl (host->trust);
-      if (GNUNET_OK == GNUNET_DISK_fn_write (fn, &trust, sizeof(uint32_t),
-          GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE
-              | GNUNET_DISK_PERM_GROUP_READ | GNUNET_DISK_PERM_OTHER_READ))
+      if (sizeof(uint32_t) == GNUNET_DISK_fn_write (fn, &trust, 
+                                                   sizeof(uint32_t),
+                                                   GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE
+                                                   | GNUNET_DISK_PERM_GROUP_READ | GNUNET_DISK_PERM_OTHER_READ))
         host->disk_trust = host->trust;
     }
   GNUNET_free (fn);
index 40d637ee39b6f1af5c00e4c119e977b7667124b8..b0c648b257e5b616c8907038d5229694d595d4fc 100644 (file)
@@ -653,7 +653,7 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, const void *buff
  * @param buffer the data to write
  * @param n number of bytes to write
  * @param mode file permissions 
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ * @return number of bytes written on success, GNUNET_SYSERR on error
  */
 ssize_t
 GNUNET_DISK_fn_write (const char * fn, const void *buffer,
@@ -661,7 +661,7 @@ GNUNET_DISK_fn_write (const char * fn, const void *buffer,
                      enum GNUNET_DISK_AccessPermissions mode)
 {
   struct GNUNET_DISK_FileHandle *fh;
-  int ret;
+  ssize_t ret;
 
   fh = GNUNET_DISK_file_open (fn, 
                              GNUNET_DISK_OPEN_WRITE 
@@ -669,9 +669,8 @@ GNUNET_DISK_fn_write (const char * fn, const void *buffer,
                              | GNUNET_DISK_OPEN_CREATE, mode);
   if (!fh)
     return GNUNET_SYSERR;
-  ret = (n == GNUNET_DISK_file_write (fh, buffer, n)) ? GNUNET_OK : GNUNET_SYSERR;
+  ret = GNUNET_DISK_file_write (fh, buffer, n);
   GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh));
-
   return ret;
 }
 
index 04a6a1f78ebcd71805bbf1e680fc6b80beb7f266..40165800b7f5fb5045010ad49f54b6137a65d113 100644 (file)
@@ -209,8 +209,9 @@ write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
                                                         off + 1],
                                                    size,
                                                    GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL));
-  GNUNET_DISK_fn_write (fn, buf, tag, GNUNET_DISK_PERM_USER_READ
-      | GNUNET_DISK_PERM_USER_WRITE | GNUNET_DISK_PERM_GROUP_READ);
+  GNUNET_break
+    (tag != GNUNET_DISK_fn_write (fn, buf, tag, GNUNET_DISK_PERM_USER_READ
+                                 | GNUNET_DISK_PERM_USER_WRITE | GNUNET_DISK_PERM_GROUP_READ));
   GNUNET_free (fn);
   GNUNET_free (buf);
   /* create entry for pseudonym name in names */
index 705a24abfd3424c375d1678ef2909c10d6c56d2b..8b485edc51adc181c022b956c62a4c50b91ce029 100644 (file)
@@ -36,8 +36,10 @@ testReadWrite ()
   char tmp[100 + 1];
   int ret;
 
-  if (GNUNET_OK != GNUNET_DISK_fn_write (".testfile", TESTSTRING, strlen (
-      TESTSTRING), GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE))
+  if (strlen(TESTSTRING) != 
+      GNUNET_DISK_fn_write (".testfile", TESTSTRING, 
+                           strlen (TESTSTRING),
+                           GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE))
     return 1;
   if (GNUNET_OK != GNUNET_DISK_file_test (".testfile"))
     return 1;