From 09cfcd83bd680bd5178c7fead1c6927fcf45b352 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 19 Oct 2009 22:28:37 +0000 Subject: [PATCH] fixing bio bugs --- src/include/gnunet_bio_lib.h | 10 +++++----- src/util/bio.c | 17 +++++++++++------ src/util/test_bio.c | 16 +++++++--------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/include/gnunet_bio_lib.h b/src/include/gnunet_bio_lib.h index 2a2639f05..f70baa070 100644 --- a/src/include/gnunet_bio_lib.h +++ b/src/include/gnunet_bio_lib.h @@ -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)) /** diff --git a/src/util/bio.c b/src/util/bio.c index 83afa34f3..20870576b 100644 --- a/src/util/bio.c +++ b/src/util/bio.c @@ -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; diff --git a/src/util/test_bio.c b/src/util/test_bio.c index 47992f56e..fa8fa0e2f 100644 --- a/src/util/test_bio.c +++ b/src/util/test_bio.c @@ -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); -- 2.25.1