fix timeout of test_service, misc signed/unsigned and unused argument issues
[oweals/gnunet.git] / src / util / bio.c
index 08e30dc01ae8c3125ed3f743e390d1668064de65..816917a223837e28f2b490caa8f57ba0ae3de40b 100644 (file)
@@ -162,15 +162,19 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
     {
       if (min > len - pos)
         min = len - pos;
-      GNUNET_memcpy (&dst[pos], &h->buffer[h->pos], min);
+      GNUNET_memcpy (&dst[pos],
+                    &h->buffer[h->pos],
+                    min);
       h->pos += min;
       pos += min;
     }
     if (pos == len)
       return GNUNET_OK;         /* done! */
-    GNUNET_assert (h->have == h->pos);
+    GNUNET_assert (((off_t) h->have) == h->pos);
     /* fill buffer */
-    ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size);
+    ret = GNUNET_DISK_file_read (h->fd,
+                                h->buffer,
+                                h->size);
     if (-1 == ret)
     {
       GNUNET_asprintf (&h->emsg,
@@ -287,7 +291,9 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
   char *buf;
   struct GNUNET_CONTAINER_MetaData *meta;
 
-  if (GNUNET_BIO_read_int32 (h, (int32_t *) & size) != GNUNET_OK)
+  if (GNUNET_OK !=
+      GNUNET_BIO_read_int32 (h,
+                            (int32_t *) & size))
     return GNUNET_SYSERR;
   if (size == 0)
   {
@@ -298,20 +304,29 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
   {
     GNUNET_asprintf (&h->emsg,
                      _("Serialized metadata `%s' larger than allowed (%u>%u)"),
-                     what, size, MAX_META_DATA);
+                     what,
+                    size,
+                    MAX_META_DATA);
     return GNUNET_SYSERR;
   }
   buf = GNUNET_malloc (size);
-  if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size))
+  if (GNUNET_OK !=
+      GNUNET_BIO_read (h,
+                      what,
+                      buf,
+                      size))
   {
     GNUNET_free (buf);
     return GNUNET_SYSERR;
   }
-  meta = GNUNET_CONTAINER_meta_data_deserialize (buf, size);
-  if (meta == NULL)
+  meta = GNUNET_CONTAINER_meta_data_deserialize (buf,
+                                                size);
+  if (NULL == meta)
   {
     GNUNET_free (buf);
-    GNUNET_asprintf (&h->emsg, _("Metadata `%s' failed to deserialize"), what);
+    GNUNET_asprintf (&h->emsg,
+                    _("Metadata `%s' failed to deserialize"),
+                    what);
     return GNUNET_SYSERR;
   }
   GNUNET_free (buf);
@@ -330,12 +345,19 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  */
 int
-GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
-                         int line, int32_t * i)
+GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
+                        const char *file,
+                         int line,
+                        int32_t * i)
 {
   int32_t big;
 
-  if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof (int32_t)))
+  if (GNUNET_OK !=
+      GNUNET_BIO_read_fn (h,
+                         file,
+                         line,
+                         &big,
+                         sizeof (int32_t)))
     return GNUNET_SYSERR;
   *i = ntohl (big);
   return GNUNET_OK;
@@ -359,7 +381,12 @@ GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
 {
   int64_t big;
 
-  if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof (int64_t)))
+  if (GNUNET_OK !=
+      GNUNET_BIO_read_fn (h,
+                         file,
+                         line,
+                         &big,
+                         sizeof (int64_t)))
     return GNUNET_SYSERR;
   *i = GNUNET_ntohll (big);
   return GNUNET_OK;
@@ -432,7 +459,8 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
   int ret;
 
   ret = GNUNET_SYSERR;
-  if ( (NULL != h->fd) && (GNUNET_OK == (ret = GNUNET_BIO_flush (h))) )
+  if ( (NULL != h->fd) &&
+       (GNUNET_OK == (ret = GNUNET_BIO_flush (h))) )
     GNUNET_DISK_file_close (h->fd);
   GNUNET_free (h);
   return ret;
@@ -451,8 +479,10 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
 {
   ssize_t ret;
 
-  ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
-  if (ret != h->have)
+  ret = GNUNET_DISK_file_write (h->fd,
+                               h->buffer,
+                               h->have);
+  if (ret != (ssize_t) h->have)
   {
     GNUNET_DISK_file_close (h->fd);
     h->fd = NULL;
@@ -472,7 +502,8 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  */
 int
-GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer,
+GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
+                 const void *buffer,
                   size_t n)
 {
   const char *src = buffer;
@@ -488,7 +519,9 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer,
     min = h->size - h->have;
     if (min > n - pos)
       min = n - pos;
-    GNUNET_memcpy (&h->buffer[h->have], &src[pos], min);
+    GNUNET_memcpy (&h->buffer[h->have],
+                  &src[pos],
+                  min);
     pos += min;
     h->have += min;
     if (pos == n)