aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_bio_lib.h10
-rw-r--r--src/util/bio.c17
-rw-r--r--src/util/test_bio.c16
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,
113 * @param h hande to open file 113 * @param h hande to open file
114 * @param f address of float to read 114 * @param f address of float to read
115 */ 115 */
116#define GNUNET_BIO_read_float(h, f) (sizeof(float) == GNUNET_BIO_read (h, __FILE__ "##__LINE__##", f, sizeof(float))) 116#define GNUNET_BIO_read_float(h, f) (GNUNET_BIO_read (h, __FILE__ "##__LINE__##", f, sizeof(float)))
117 117
118 118
119 119
@@ -123,7 +123,7 @@ int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
123 * @param h hande to open file 123 * @param h hande to open file
124 * @param f address of double to read 124 * @param f address of double to read
125 */ 125 */
126#define GNUNET_BIO_read_double(h, f) (sizeof(double) == GNUNET_BIO_read (h, __FILE__ "##__LINE__##", f, sizeof(double))) 126#define GNUNET_BIO_read_double(h, f) (GNUNET_BIO_read (h, __FILE__ "##__LINE__##", f, sizeof(double)))
127 127
128 128
129/** 129/**
@@ -167,7 +167,7 @@ int GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
167 * @param h hande to open file 167 * @param h hande to open file
168 * @param i address of 64-bit integer to read 168 * @param i address of 64-bit integer to read
169 */ 169 */
170#define GNUNET_BIO_read_int64(h, i) (sizeof(int64_t) == GNUNET_BIO_read (h, __FILE__ "##__LINE__##", (int64_t*) i, sizeof(int64_t))) 170#define GNUNET_BIO_read_int64(h, i) GNUNET_BIO_read_int64__ (h, __FILE__ "##__LINE__##", (int64_t*) i)
171 171
172 172
173/** 173/**
@@ -236,7 +236,7 @@ int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
236 * @param h hande to open file 236 * @param h hande to open file
237 * @param f float to write (must be a variable) 237 * @param f float to write (must be a variable)
238 */ 238 */
239#define GNUNET_BIO_write_float(h, f) (sizeof(float) == GNUNET_BIO_write (h, &f, sizeof(float))) 239#define GNUNET_BIO_write_float(h, f) GNUNET_BIO_write (h, &f, sizeof(float))
240 240
241 241
242 242
@@ -246,7 +246,7 @@ int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
246 * @param h hande to open file 246 * @param h hande to open file
247 * @param f double to write (must be a variable) 247 * @param f double to write (must be a variable)
248 */ 248 */
249#define GNUNET_BIO_write_double(h, f) (sizeof(double) == GNUNET_BIO_write (h, &f, sizeof(double))) 249#define GNUNET_BIO_write_double(h, f) GNUNET_BIO_write (h, &f, sizeof(double))
250 250
251 251
252/** 252/**
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,
169 char *buf; 169 char *buf;
170 uint32_t big; 170 uint32_t big;
171 171
172 if (! GNUNET_BIO_read_int32 (h, &big)) 172 if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big))
173 return GNUNET_SYSERR; 173 return GNUNET_SYSERR;
174 if (big == 0) 174 if (big == 0)
175 { 175 {
@@ -187,7 +187,7 @@ int GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
187 } 187 }
188 buf = GNUNET_malloc (big); 188 buf = GNUNET_malloc (big);
189 buf[--big] = '\0'; 189 buf[--big] = '\0';
190 if (big != GNUNET_BIO_read (h, what, buf, big)) 190 if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big))
191 { 191 {
192 GNUNET_free (buf); 192 GNUNET_free (buf);
193 return GNUNET_SYSERR; 193 return GNUNET_SYSERR;
@@ -227,7 +227,7 @@ int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
227 return GNUNET_SYSERR; 227 return GNUNET_SYSERR;
228 } 228 }
229 buf = GNUNET_malloc (size); 229 buf = GNUNET_malloc (size);
230 if (size != 230 if (GNUNET_OK !=
231 GNUNET_BIO_read (h, what, buf, size)) 231 GNUNET_BIO_read (h, what, buf, size))
232 { 232 {
233 GNUNET_free (buf); 233 GNUNET_free (buf);
@@ -262,7 +262,7 @@ int GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
262{ 262{
263 int32_t big; 263 int32_t big;
264 264
265 if (sizeof (int32_t) != 265 if (GNUNET_OK !=
266 GNUNET_BIO_read (h, 266 GNUNET_BIO_read (h,
267 what, 267 what,
268 &big, 268 &big,
@@ -287,7 +287,7 @@ int GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
287{ 287{
288 int64_t big; 288 int64_t big;
289 289
290 if (sizeof (int64_t) != 290 if (GNUNET_OK !=
291 GNUNET_BIO_read (h, 291 GNUNET_BIO_read (h,
292 what, 292 what,
293 &big, 293 &big,
@@ -342,6 +342,7 @@ struct GNUNET_BIO_WriteHandle *GNUNET_BIO_write_open (const char *fn)
342 */ 342 */
343int GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h) 343int GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
344{ 344{
345 ssize_t wrt;
345 int ret; 346 int ret;
346 347
347 if (NULL == h->fd) 348 if (NULL == h->fd)
@@ -350,8 +351,12 @@ int GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
350 } 351 }
351 else 352 else
352 { 353 {
354 wrt = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
355 if (wrt == h->have)
356 ret = GNUNET_OK;
357 else
358 ret = GNUNET_SYSERR;
353 GNUNET_DISK_file_close (h->fd); 359 GNUNET_DISK_file_close (h->fd);
354 ret = GNUNET_OK;
355 } 360 }
356 GNUNET_free (h); 361 GNUNET_free (h);
357 return ret; 362 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
34main (int argc, char *argv[]) 34main (int argc, char *argv[])
35{ 35{
36 36
37 char *readResultString; 37 char *readResultString;
38 int64_t testNumber = (int64_t)TESTNUMBER64; 38 int64_t testNumber = (int64_t)TESTNUMBER64;
39 39 int64_t testNum;
40 const char *writeString = TESTSTRING;
41 char *msg; 40 char *msg;
42 41
43 char* fileName = GNUNET_DISK_mktemp ("gnunet_bio"); 42 char* fileName = GNUNET_DISK_mktemp ("gnunet_bio");
@@ -49,16 +48,15 @@ main (int argc, char *argv[])
49 metaDataW = GNUNET_CONTAINER_meta_data_create(); 48 metaDataW = GNUNET_CONTAINER_meta_data_create();
50 GNUNET_CONTAINER_meta_data_add_publication_date(metaDataW); 49 GNUNET_CONTAINER_meta_data_add_publication_date(metaDataW);
51 fileW = GNUNET_BIO_write_open(fileName); 50 fileW = GNUNET_BIO_write_open(fileName);
52 GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_string(fileW,writeString)); 51 GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_string(fileW, TESTSTRING));
53 GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_meta_data(fileW,metaDataW)); 52 GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_meta_data(fileW,metaDataW));
54 GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_int64(fileW,testNumber)); 53 GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_int64(fileW,testNumber));
55 GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_close(fileW)); 54 GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_close(fileW));
56 fileR = GNUNET_BIO_read_open (fileName); 55 fileR = GNUNET_BIO_read_open (fileName);
57 GNUNET_BIO_read_meta_data(fileR,"Read meta error",&metaDataR); 56 GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_string(fileR, "Read string error", &readResultString, 200));
58 size_t readMaxLen = 200; 57 GNUNET_BIO_read_meta_data(fileR, "Read meta error", &metaDataR);
59 //GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_string(fileR,"Read string error",&readResultString,readMaxLen)); 58 GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_int64(fileR, &testNum));
60 //GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_int64__(fileR,"Read int64 error",&testNum)); 59 GNUNET_BIO_read_close(fileR,&msg);
61 GNUNET_BIO_read_close(fileR,&msg);
62 GNUNET_CONTAINER_meta_data_destroy(metaDataW); 60 GNUNET_CONTAINER_meta_data_destroy(metaDataW);
63 GNUNET_CONTAINER_meta_data_destroy(metaDataR); 61 GNUNET_CONTAINER_meta_data_destroy(metaDataR);
64 free(fileName); 62 free(fileName);