fixing bio bugs
authorChristian Grothoff <christian@grothoff.org>
Mon, 19 Oct 2009 22:28:37 +0000 (22:28 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 19 Oct 2009 22:28:37 +0000 (22:28 +0000)
src/include/gnunet_bio_lib.h
src/util/bio.c
src/util/test_bio.c

index 2a2639f05edce002072b0910c4972e5b78ac393b..f70baa0701a57e3b8864fce11aed31f6033cf384 100644 (file)
@@ -113,7 +113,7 @@ int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
  * @param h hande to open file
  * @param f address of float to read
  */ 
-#define GNUNET_BIO_read_float(h, f) (sizeof(float) == GNUNET_BIO_read (h, __FILE__ "##__LINE__##", f, sizeof(float)))
+#define GNUNET_BIO_read_float(h, f) (GNUNET_BIO_read (h, __FILE__ "##__LINE__##", f, sizeof(float)))
 
 
 
@@ -123,7 +123,7 @@ int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
  * @param h hande to open file
  * @param f address of double to read
  */ 
-#define GNUNET_BIO_read_double(h, f) (sizeof(double) == GNUNET_BIO_read (h, __FILE__ "##__LINE__##", f, sizeof(double)))
+#define GNUNET_BIO_read_double(h, f) (GNUNET_BIO_read (h, __FILE__ "##__LINE__##", f, sizeof(double)))
 
 
 /**
@@ -167,7 +167,7 @@ int GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
  * @param h hande to open file
  * @param i address of 64-bit integer to read
  */ 
-#define GNUNET_BIO_read_int64(h, i) (sizeof(int64_t) == GNUNET_BIO_read (h, __FILE__ "##__LINE__##", (int64_t*) i, sizeof(int64_t)))
+#define GNUNET_BIO_read_int64(h, i) GNUNET_BIO_read_int64__ (h, __FILE__ "##__LINE__##", (int64_t*) i)
 
 
 /**
@@ -236,7 +236,7 @@ int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
  * @param h hande to open file
  * @param f float to write (must be a variable)
  */ 
-#define GNUNET_BIO_write_float(h, f) (sizeof(float) == GNUNET_BIO_write (h, &f, sizeof(float)))
+#define GNUNET_BIO_write_float(h, f) GNUNET_BIO_write (h, &f, sizeof(float))
 
 
 
@@ -246,7 +246,7 @@ int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
  * @param h hande to open file
  * @param f double to write (must be a variable)
  */ 
-#define GNUNET_BIO_write_double(h, f) (sizeof(double) == GNUNET_BIO_write (h, &f, sizeof(double)))
+#define GNUNET_BIO_write_double(h, f) GNUNET_BIO_write (h, &f, sizeof(double))
 
 
 /**
index 83afa34f3f83cb322632799e8c0acb7f70855650..20870576b7dadf35f59dd7ee84d1586ca7ad4fe8 100644 (file)
@@ -169,7 +169,7 @@ int GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
   char *buf;
   uint32_t big;
 
-  if (! GNUNET_BIO_read_int32 (h, &big))
+  if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big))
     return GNUNET_SYSERR;
   if (big == 0)
     {
@@ -187,7 +187,7 @@ int GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
     }
   buf = GNUNET_malloc (big);
   buf[--big] = '\0';
-  if (big != GNUNET_BIO_read (h, what, buf, big))
+  if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big))
     {
       GNUNET_free (buf);
       return GNUNET_SYSERR;
@@ -227,7 +227,7 @@ int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
       return GNUNET_SYSERR;
     }
   buf = GNUNET_malloc (size);
-  if (size != 
+  if (GNUNET_OK != 
       GNUNET_BIO_read (h, what, buf, size))
     {
       GNUNET_free (buf);
@@ -262,7 +262,7 @@ int GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
 {
   int32_t big;
 
-  if (sizeof (int32_t) !=
+  if (GNUNET_OK !=
       GNUNET_BIO_read (h,
                       what,
                       &big,
@@ -287,7 +287,7 @@ int GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
 {
   int64_t big;
 
-  if (sizeof (int64_t) != 
+  if (GNUNET_OK != 
       GNUNET_BIO_read (h, 
                       what,
                       &big,
@@ -342,6 +342,7 @@ struct GNUNET_BIO_WriteHandle *GNUNET_BIO_write_open (const char *fn)
  */
 int GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
 {
+  ssize_t wrt;
   int ret;
 
   if (NULL == h->fd)
@@ -350,8 +351,12 @@ int GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
     }
   else
     {
+      wrt = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
+      if (wrt == h->have)
+       ret = GNUNET_OK;
+      else
+       ret = GNUNET_SYSERR;
       GNUNET_DISK_file_close (h->fd);
-      ret = GNUNET_OK;
     }
   GNUNET_free (h);
   return ret;
index 47992f56ee3f32d2534b15094d21473b80d77857..fa8fa0e2f4eec462040ca0a978c8ab0b45010749 100644 (file)
@@ -34,10 +34,9 @@ int
 main (int argc, char *argv[])
 {
 
-       char *readResultString;
+        char *readResultString;
        int64_t testNumber = (int64_t)TESTNUMBER64;
-
-       const char *writeString = TESTSTRING;
+       int64_t testNum;
        char *msg;
 
        char* fileName = GNUNET_DISK_mktemp ("gnunet_bio");
@@ -49,16 +48,15 @@ main (int argc, char *argv[])
        metaDataW = GNUNET_CONTAINER_meta_data_create();
        GNUNET_CONTAINER_meta_data_add_publication_date(metaDataW);
        fileW = GNUNET_BIO_write_open(fileName);
-       GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_string(fileW,writeString));
+       GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_string(fileW, TESTSTRING));
        GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_meta_data(fileW,metaDataW));
        GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_int64(fileW,testNumber));
        GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_close(fileW));
        fileR = GNUNET_BIO_read_open (fileName);
-       GNUNET_BIO_read_meta_data(fileR,"Read meta error",&metaDataR);
-       size_t readMaxLen = 200;
-       //GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_string(fileR,"Read string error",&readResultString,readMaxLen));
-       //GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_int64__(fileR,"Read int64 error",&testNum));
-    GNUNET_BIO_read_close(fileR,&msg);
+       GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_string(fileR, "Read string error", &readResultString, 200));
+       GNUNET_BIO_read_meta_data(fileR, "Read meta error", &metaDataR);
+       GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_int64(fileR, &testNum));
+       GNUNET_BIO_read_close(fileR,&msg);
        GNUNET_CONTAINER_meta_data_destroy(metaDataW);
        GNUNET_CONTAINER_meta_data_destroy(metaDataR);
     free(fileName);