summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-10-19 22:28:37 +0000
committerChristian Grothoff <christian@grothoff.org>2009-10-19 22:28:37 +0000
commit09cfcd83bd680bd5178c7fead1c6927fcf45b352 (patch)
tree2e96207c413407d1a487035c9136807b1ffa5b37 /src/util
parent8da07c23a94221fea5d73ebac9a522f72e3adef3 (diff)
downloadgnunet-09cfcd83bd680bd5178c7fead1c6927fcf45b352.tar.gz
gnunet-09cfcd83bd680bd5178c7fead1c6927fcf45b352.zip
fixing bio bugs
Diffstat (limited to 'src/util')
-rw-r--r--src/util/bio.c17
-rw-r--r--src/util/test_bio.c16
2 files changed, 18 insertions, 15 deletions
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);