aboutsummaryrefslogtreecommitdiff
path: root/src/util/bio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/bio.c')
-rw-r--r--src/util/bio.c57
1 files changed, 29 insertions, 28 deletions
diff --git a/src/util/bio.c b/src/util/bio.c
index ce15f073b..39050bb87 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -171,7 +171,7 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
171 if (NULL != emsg) 171 if (NULL != emsg)
172 *emsg = h->emsg; 172 *emsg = h->emsg;
173 else 173 else
174 GNUNET_free_non_null (h->emsg); 174 GNUNET_free (h->emsg);
175 switch (h->type) 175 switch (h->type)
176 { 176 {
177 case IO_FILE: 177 case IO_FILE:
@@ -260,7 +260,7 @@ read_from_buffer (struct GNUNET_BIO_ReadHandle *h,
260 char *result, 260 char *result,
261 size_t len) 261 size_t len)
262{ 262{
263 if (h->size < len || h->size - h->pos < len) 263 if ((h->size < len) || (h->size - h->pos < len))
264 { 264 {
265 GNUNET_asprintf (&h->emsg, 265 GNUNET_asprintf (&h->emsg,
266 _ ("Error while reading `%s' from buffer: %s"), 266 _ ("Error while reading `%s' from buffer: %s"),
@@ -345,7 +345,7 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
345 GNUNET_asprintf (&h->emsg, 345 GNUNET_asprintf (&h->emsg,
346 _ ("Error reading length of string `%s'"), 346 _ ("Error reading length of string `%s'"),
347 what); 347 what);
348 GNUNET_free_non_null (tmp); 348 GNUNET_free (tmp);
349 return GNUNET_SYSERR; 349 return GNUNET_SYSERR;
350 } 350 }
351 if (0 == big) 351 if (0 == big)
@@ -431,6 +431,7 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
431 return GNUNET_OK; 431 return GNUNET_OK;
432} 432}
433 433
434
434/** 435/**
435 * Read a float. 436 * Read a float.
436 * 437 *
@@ -439,9 +440,9 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
439 * @param f address of float to read 440 * @param f address of float to read
440 */ 441 */
441int 442int
442GNUNET_BIO_read_float(struct GNUNET_BIO_ReadHandle *h, 443GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h,
443 const char *what, 444 const char *what,
444 float *f) 445 float *f)
445{ 446{
446 int32_t *i = (int32_t *) f; 447 int32_t *i = (int32_t *) f;
447 return GNUNET_BIO_read_int32 (h, what, i); 448 return GNUNET_BIO_read_int32 (h, what, i);
@@ -456,9 +457,9 @@ GNUNET_BIO_read_float(struct GNUNET_BIO_ReadHandle *h,
456 * @param f address of double to read 457 * @param f address of double to read
457 */ 458 */
458int 459int
459GNUNET_BIO_read_double(struct GNUNET_BIO_ReadHandle *h, 460GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h,
460 const char *what, 461 const char *what,
461 double *f) 462 double *f)
462{ 463{
463 int64_t *i = (int64_t *) f; 464 int64_t *i = (int64_t *) f;
464 return GNUNET_BIO_read_int64 (h, what, i); 465 return GNUNET_BIO_read_int64 (h, what, i);
@@ -612,7 +613,7 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg)
612 if (NULL != emsg) 613 if (NULL != emsg)
613 *emsg = h->emsg; 614 *emsg = h->emsg;
614 else 615 else
615 GNUNET_free_non_null (h->emsg); 616 GNUNET_free (h->emsg);
616 switch (h->type) 617 switch (h->type)
617 { 618 {
618 case IO_FILE: 619 case IO_FILE:
@@ -623,7 +624,7 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg)
623 if (NULL != emsg) 624 if (NULL != emsg)
624 *emsg = h->emsg; 625 *emsg = h->emsg;
625 else 626 else
626 GNUNET_free_non_null (h->emsg); 627 GNUNET_free (h->emsg);
627 err = GNUNET_SYSERR; 628 err = GNUNET_SYSERR;
628 } 629 }
629 else 630 else
@@ -663,7 +664,7 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
663 { 664 {
664 GNUNET_DISK_file_close (h->fd); 665 GNUNET_DISK_file_close (h->fd);
665 h->fd = NULL; 666 h->fd = NULL;
666 GNUNET_free_non_null (h->emsg); 667 GNUNET_free (h->emsg);
667 GNUNET_asprintf (&h->emsg, _ ("Unable to flush buffer to file")); 668 GNUNET_asprintf (&h->emsg, _ ("Unable to flush buffer to file"));
668 return GNUNET_SYSERR; 669 return GNUNET_SYSERR;
669 } 670 }
@@ -692,13 +693,13 @@ GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
692{ 693{
693 if (IO_BUFFER != h->type) 694 if (IO_BUFFER != h->type)
694 return GNUNET_SYSERR; 695 return GNUNET_SYSERR;
695 if (NULL == contents || NULL == size) 696 if ((NULL == contents) || (NULL == size))
696 return GNUNET_SYSERR; 697 return GNUNET_SYSERR;
697 int ret = (NULL != h->emsg) ? GNUNET_SYSERR : GNUNET_OK; 698 int ret = (NULL != h->emsg) ? GNUNET_SYSERR : GNUNET_OK;
698 if (NULL != emsg) 699 if (NULL != emsg)
699 *emsg = h->emsg; 700 *emsg = h->emsg;
700 else 701 else
701 GNUNET_free_non_null (h->emsg); 702 GNUNET_free (h->emsg);
702 *contents = GNUNET_buffer_reap ((struct GNUNET_Buffer *) h->buffer, size); 703 *contents = GNUNET_buffer_reap ((struct GNUNET_Buffer *) h->buffer, size);
703 return ret; 704 return ret;
704} 705}
@@ -750,7 +751,7 @@ write_to_file (struct GNUNET_BIO_WriteHandle *h,
750 _ ("Error while writing `%s' to file: %s"), 751 _ ("Error while writing `%s' to file: %s"),
751 what, 752 what,
752 tmp); 753 tmp);
753 GNUNET_free_non_null (tmp); 754 GNUNET_free (tmp);
754 return GNUNET_SYSERR; 755 return GNUNET_SYSERR;
755 } 756 }
756 } 757 }
@@ -870,7 +871,7 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
870 if (-1 == size) 871 if (-1 == size)
871 { 872 {
872 GNUNET_free (buf); 873 GNUNET_free (buf);
873 GNUNET_free_non_null (h->emsg); 874 GNUNET_free (h->emsg);
874 GNUNET_asprintf (&h->emsg, 875 GNUNET_asprintf (&h->emsg,
875 _ ("Failed to serialize metadata `%s'"), 876 _ ("Failed to serialize metadata `%s'"),
876 what); 877 what);
@@ -897,9 +898,9 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
897 * @param f float to write 898 * @param f float to write
898 */ 899 */
899int 900int
900GNUNET_BIO_write_float(struct GNUNET_BIO_WriteHandle *h, 901GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h,
901 const char *what, 902 const char *what,
902 float f) 903 float f)
903{ 904{
904 int32_t i = f; 905 int32_t i = f;
905 return GNUNET_BIO_write_int32 (h, what, i); 906 return GNUNET_BIO_write_int32 (h, what, i);
@@ -914,9 +915,9 @@ GNUNET_BIO_write_float(struct GNUNET_BIO_WriteHandle *h,
914 * @param f double to write 915 * @param f double to write
915 */ 916 */
916int 917int
917GNUNET_BIO_write_double(struct GNUNET_BIO_WriteHandle *h, 918GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h,
918 const char *what, 919 const char *what,
919 double f) 920 double f)
920{ 921{
921 int64_t i = f; 922 int64_t i = f;
922 return GNUNET_BIO_write_int64 (h, what, i); 923 return GNUNET_BIO_write_int64 (h, what, i);
@@ -1196,7 +1197,7 @@ GNUNET_BIO_read_spec_int64 (const char *what,
1196 * @param f address of float to read 1197 * @param f address of float to read
1197 */ 1198 */
1198struct GNUNET_BIO_ReadSpec 1199struct GNUNET_BIO_ReadSpec
1199GNUNET_BIO_read_spec_float(const char *what, float *f) 1200GNUNET_BIO_read_spec_float (const char *what, float *f)
1200{ 1201{
1201 struct GNUNET_BIO_ReadSpec rs = { 1202 struct GNUNET_BIO_ReadSpec rs = {
1202 .rh = &read_spec_handler_int32, 1203 .rh = &read_spec_handler_int32,
@@ -1216,7 +1217,7 @@ GNUNET_BIO_read_spec_float(const char *what, float *f)
1216 * @param f address of double to read 1217 * @param f address of double to read
1217 */ 1218 */
1218struct GNUNET_BIO_ReadSpec 1219struct GNUNET_BIO_ReadSpec
1219GNUNET_BIO_read_spec_double(const char *what, double *f) 1220GNUNET_BIO_read_spec_double (const char *what, double *f)
1220{ 1221{
1221 struct GNUNET_BIO_ReadSpec rs = { 1222 struct GNUNET_BIO_ReadSpec rs = {
1222 .rh = &read_spec_handler_int64, 1223 .rh = &read_spec_handler_int64,
@@ -1243,7 +1244,7 @@ GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h,
1243{ 1244{
1244 int ret = GNUNET_OK; 1245 int ret = GNUNET_OK;
1245 1246
1246 for (size_t i=0; NULL!=rs[i].rh; ++i) 1247 for (size_t i = 0; NULL!=rs[i].rh; ++i)
1247 { 1248 {
1248 ret = rs[i].rh (rs[i].cls, h, rs[i].what, rs[i].target, rs[i].size); 1249 ret = rs[i].rh (rs[i].cls, h, rs[i].what, rs[i].target, rs[i].size);
1249 if (GNUNET_OK != ret) 1250 if (GNUNET_OK != ret)
@@ -1490,7 +1491,7 @@ GNUNET_BIO_write_spec_int64 (const char *what,
1490 * @return the write spec 1491 * @return the write spec
1491 */ 1492 */
1492struct GNUNET_BIO_WriteSpec 1493struct GNUNET_BIO_WriteSpec
1493GNUNET_BIO_write_spec_float(const char *what, float *f) 1494GNUNET_BIO_write_spec_float (const char *what, float *f)
1494{ 1495{
1495 struct GNUNET_BIO_WriteSpec ws = { 1496 struct GNUNET_BIO_WriteSpec ws = {
1496 .wh = &write_spec_handler_int32, 1497 .wh = &write_spec_handler_int32,
@@ -1512,7 +1513,7 @@ GNUNET_BIO_write_spec_float(const char *what, float *f)
1512 * @return the write spec 1513 * @return the write spec
1513 */ 1514 */
1514struct GNUNET_BIO_WriteSpec 1515struct GNUNET_BIO_WriteSpec
1515GNUNET_BIO_write_spec_double(const char *what, double *f) 1516GNUNET_BIO_write_spec_double (const char *what, double *f)
1516{ 1517{
1517 struct GNUNET_BIO_WriteSpec ws = { 1518 struct GNUNET_BIO_WriteSpec ws = {
1518 .wh = &write_spec_handler_int64, 1519 .wh = &write_spec_handler_int64,
@@ -1540,7 +1541,7 @@ GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h,
1540{ 1541{
1541 int ret = GNUNET_OK; 1542 int ret = GNUNET_OK;
1542 1543
1543 for (size_t i=0; NULL!=ws[i].wh; ++i) 1544 for (size_t i = 0; NULL!=ws[i].wh; ++i)
1544 { 1545 {
1545 ret = ws[i].wh (ws[i].cls, h, ws[i].what, ws[i].source, ws[i].source_size); 1546 ret = ws[i].wh (ws[i].cls, h, ws[i].what, ws[i].source, ws[i].source_size);
1546 if (GNUNET_OK != ret) 1547 if (GNUNET_OK != ret)