summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/bio.c133
-rw-r--r--src/util/common_allocation.c199
-rw-r--r--src/util/common_logging.c21
-rw-r--r--src/util/configuration.c451
-rw-r--r--src/util/container_bloomfilter.c205
-rw-r--r--src/util/crypto_ecc_setup.c247
-rw-r--r--src/util/crypto_random.c10
-rw-r--r--src/util/disk.c589
-rw-r--r--src/util/dnsstub.c168
-rw-r--r--src/util/getopt.c32
-rw-r--r--src/util/getopt_helpers.c22
-rw-r--r--src/util/gnunet-ecc.c208
-rw-r--r--src/util/gnunet-resolver.c4
-rw-r--r--src/util/gnunet-scrypt.c4
-rw-r--r--src/util/helper.c221
-rw-r--r--src/util/os_installation.c64
-rw-r--r--src/util/os_priority.c604
-rw-r--r--src/util/perf_crypto_asymmetric.c2
-rw-r--r--src/util/perf_crypto_ecc_dlog.c2
-rw-r--r--src/util/plugin.c41
-rw-r--r--src/util/program.c20
-rw-r--r--src/util/service.c856
-rw-r--r--src/util/strings.c693
-rw-r--r--src/util/test_common_allocation.c2
-rw-r--r--src/util/test_common_logging.c8
-rw-r--r--src/util/test_common_logging_dummy.c2
-rw-r--r--src/util/test_common_logging_runtime_loglevels.c6
-rw-r--r--src/util/test_configuration.c14
-rw-r--r--src/util/test_container_bloomfilter.c30
-rw-r--r--src/util/test_crypto_ecc_dlog.c2
-rw-r--r--src/util/test_crypto_ecdh_eddsa.c2
-rw-r--r--src/util/test_crypto_ecdhe.c2
-rw-r--r--src/util/test_crypto_ecdsa.c18
-rw-r--r--src/util/test_crypto_eddsa.c20
-rw-r--r--src/util/test_crypto_hash.c6
-rw-r--r--src/util/test_crypto_random.c2
-rw-r--r--src/util/test_disk.c16
-rw-r--r--src/util/test_getopt.c119
-rw-r--r--src/util/test_peer.c4
-rw-r--r--src/util/test_resolver_api.c4
-rw-r--r--src/util/test_scheduler.c2
-rw-r--r--src/util/test_scheduler_delay.c14
-rw-r--r--src/util/test_service.c2
-rw-r--r--src/util/test_strings.c2
-rw-r--r--src/util/time.c125
45 files changed, 2364 insertions, 2834 deletions
diff --git a/src/util/bio.c b/src/util/bio.c
index def9b02e1..1df249e40 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -25,7 +25,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util-bio",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-bio", __VA_ARGS__)
#ifndef PATH_MAX
/**
@@ -116,8 +116,7 @@ GNUNET_BIO_read_open (const char *fn)
* @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
*/
int
-GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h,
- char **emsg)
+GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
{
int err;
@@ -144,7 +143,8 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h,
int
GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
const char *what,
- void *result, size_t len)
+ void *result,
+ size_t len)
{
char *dst = result;
size_t min;
@@ -162,39 +162,34 @@ 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! */
+ return GNUNET_OK; /* done! */
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,
- _("Error reading `%s': %s"),
- what,
- STRERROR (errno));
+ _ ("Error reading `%s': %s"),
+ what,
+ strerror (errno));
return GNUNET_SYSERR;
}
if (0 == ret)
{
GNUNET_asprintf (&h->emsg,
- _("Error reading `%s': %s"),
- what,
- _("End of file"));
+ _ ("Error reading `%s': %s"),
+ what,
+ _ ("End of file"));
return GNUNET_SYSERR;
}
h->pos = 0;
h->have = ret;
- }
- while (pos < len); /* should always be true */
+ } while (pos < len); /* should always be true */
return GNUNET_OK;
}
@@ -245,7 +240,7 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
if (GNUNET_OK != GNUNET_BIO_read_int32 (h, &big))
{
GNUNET_free_non_null (h->emsg);
- GNUNET_asprintf (&h->emsg, _("Error reading length of string `%s'"), what);
+ GNUNET_asprintf (&h->emsg, _ ("Error reading length of string `%s'"), what);
return GNUNET_SYSERR;
}
if (0 == big)
@@ -255,8 +250,11 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
}
if (big > max_length)
{
- GNUNET_asprintf (&h->emsg, _("String `%s' longer than allowed (%u > %u)"),
- what, big, max_length);
+ GNUNET_asprintf (&h->emsg,
+ _ ("String `%s' longer than allowed (%u > %u)"),
+ what,
+ big,
+ max_length);
return GNUNET_SYSERR;
}
buf = GNUNET_malloc (big);
@@ -291,9 +289,7 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
char *buf;
struct GNUNET_CONTAINER_MetaData *meta;
- if (GNUNET_OK !=
- GNUNET_BIO_read_int32 (h,
- (int32_t *) & size))
+ if (GNUNET_OK != GNUNET_BIO_read_int32 (h, (int32_t *) &size))
return GNUNET_SYSERR;
if (size == 0)
{
@@ -303,30 +299,23 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
if (size > MAX_META_DATA)
{
GNUNET_asprintf (&h->emsg,
- _("Serialized metadata `%s' larger than allowed (%u>%u)"),
+ _ ("Serialized metadata `%s' larger than allowed (%u>%u)"),
what,
- size,
- MAX_META_DATA);
+ 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);
+ 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);
@@ -346,18 +335,13 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
*/
int
GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
- const char *file,
+ const char *file,
int line,
- int32_t * i)
+ 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;
@@ -381,12 +365,7 @@ 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,11 +411,12 @@ GNUNET_BIO_write_open (const char *fn)
struct GNUNET_DISK_FileHandle *fd;
struct GNUNET_BIO_WriteHandle *h;
- fd = GNUNET_DISK_file_open (fn,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE
- | GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ fd =
+ GNUNET_DISK_file_open (fn,
+ GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (NULL == fd)
return NULL;
h = GNUNET_malloc (sizeof (struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE);
@@ -459,8 +439,7 @@ 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;
@@ -479,14 +458,12 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
{
ssize_t ret;
- ret = GNUNET_DISK_file_write (h->fd,
- h->buffer,
- 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;
- return GNUNET_SYSERR; /* error */
+ return GNUNET_SYSERR; /* error */
}
h->have = 0;
return GNUNET_OK;
@@ -503,7 +480,7 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
*/
int
GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
- const void *buffer,
+ const void *buffer,
size_t n)
{
const char *src = buffer;
@@ -519,18 +496,15 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
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)
- return GNUNET_OK; /* done */
+ return GNUNET_OK; /* done */
GNUNET_assert (h->have == h->size);
if (GNUNET_OK != GNUNET_BIO_flush (h))
- return GNUNET_SYSERR; /* error */
- }
- while (pos < n); /* should always be true */
+ return GNUNET_SYSERR; /* error */
+ } while (pos < n); /* should always be true */
GNUNET_break (0);
return GNUNET_OK;
}
@@ -544,8 +518,7 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h,
- const char *s)
+GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s)
{
uint32_t slen;
@@ -575,9 +548,11 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
if (m == NULL)
return GNUNET_BIO_write_int32 (h, 0);
buf = NULL;
- size =
- GNUNET_CONTAINER_meta_data_serialize (m, &buf, MAX_META_DATA,
- GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
+ size = GNUNET_CONTAINER_meta_data_serialize (
+ m,
+ &buf,
+ MAX_META_DATA,
+ GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
if (size == -1)
{
GNUNET_free (buf);
@@ -602,8 +577,7 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
- int32_t i)
+GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i)
{
int32_t big;
@@ -620,8 +594,7 @@ GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h,
- int64_t i)
+GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i)
{
int64_t big;
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index 20333ce56..94890a7f4 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -32,9 +32,11 @@
#include <malloc/malloc.h>
#endif
-#define LOG(kind,...) GNUNET_log_from (kind, "util-common-allocation",__VA_ARGS__)
+#define LOG(kind, ...) \
+ GNUNET_log_from (kind, "util-common-allocation", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-common-allocation", syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-common-allocation", syscall)
#ifndef INT_MAX
#define INT_MAX 0x7FFFFFFF
@@ -61,24 +63,17 @@ static LONG mem_used = 0;
* @return pointer to size bytes of memory
*/
void *
-GNUNET_xmalloc_ (size_t size,
- const char *filename,
- int linenumber)
+GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber)
{
void *ret;
/* As a security precaution, we generally do not allow very large
* allocations using the default 'GNUNET_malloc()' macro */
- GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED,
- filename,
- linenumber);
- ret = GNUNET_xmalloc_unchecked_ (size,
- filename,
- linenumber);
+ GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber);
+ ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber);
if (NULL == ret)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "malloc");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc");
GNUNET_assert (0);
}
return ret;
@@ -101,21 +96,22 @@ GNUNET_xmalloc_ (size_t size,
*/
void **
GNUNET_xnew_array_2d_ (size_t n,
- size_t m,
- size_t elementSize,
+ size_t m,
+ size_t elementSize,
const char *filename,
- int linenumber)
+ int linenumber)
{
- /* use char pointer internally to avoid void pointer arithmetic warnings */
- char **ret = GNUNET_xmalloc_ (n * sizeof (void *) + /* 1. dim header */
- n * m * elementSize, /* element data */
- filename, linenumber);
-
- for (size_t i = 0; i < n; i++)
- ret[i] = (char *)ret + /* base address */
- n * sizeof (void *) + /* skip 1. dim header */
- i * m * elementSize; /* skip to 2. dim row header */
- return (void **)ret;
+ /* use char pointer internally to avoid void pointer arithmetic warnings */
+ char **ret = GNUNET_xmalloc_ (n * sizeof (void *) + /* 1. dim header */
+ n * m * elementSize, /* element data */
+ filename,
+ linenumber);
+
+ for (size_t i = 0; i < n; i++)
+ ret[i] = (char *) ret + /* base address */
+ n * sizeof (void *) + /* skip 1. dim header */
+ i * m * elementSize; /* skip to 2. dim row header */
+ return (void **) ret;
}
@@ -135,29 +131,34 @@ GNUNET_xnew_array_2d_ (size_t n,
* @return allocated memory, never NULL
*/
void ***
-GNUNET_xnew_array_3d_ (size_t n, size_t m, size_t o, size_t elementSize,
- const char *filename, int linenumber)
+GNUNET_xnew_array_3d_ (size_t n,
+ size_t m,
+ size_t o,
+ size_t elementSize,
+ const char *filename,
+ int linenumber)
{
- /* use char pointer internally to avoid void pointer arithmetic warnings */
- char ***ret = GNUNET_xmalloc_ (n * sizeof (void **) + /* 1. dim header */
- n * m * sizeof (void *) + /* 2. dim header */
- n * m * o * elementSize, /* element data */
- filename, linenumber);
-
- for (size_t i = 0; i < n; i++)
- {
- /* need to cast to (char *) temporarily for byte level acuracy */
- ret[i] = (char **)((char *)ret + /* base address */
- n * sizeof (void **) + /* skip 1. dim header */
- i * m * sizeof (void *)); /* skip to 2. dim header */
- for (size_t j = 0; j < m; j++)
- ret[i][j] = (char *)ret + /* base address */
- n * sizeof (void **) + /* skip 1. dim header */
- n * m * sizeof (void *) + /* skip 2. dim header */
- i * m * o * elementSize + /* skip to 2. dim part */
- j * o * elementSize; /* skip to 3. dim row data */
- }
- return (void ***)ret;
+ /* use char pointer internally to avoid void pointer arithmetic warnings */
+ char ***ret = GNUNET_xmalloc_ (n * sizeof (void **) + /* 1. dim header */
+ n * m * sizeof (void *) + /* 2. dim header */
+ n * m * o * elementSize, /* element data */
+ filename,
+ linenumber);
+
+ for (size_t i = 0; i < n; i++)
+ {
+ /* need to cast to (char *) temporarily for byte level acuracy */
+ ret[i] = (char **) ((char *) ret + /* base address */
+ n * sizeof (void **) + /* skip 1. dim header */
+ i * m * sizeof (void *)); /* skip to 2. dim header */
+ for (size_t j = 0; j < m; j++)
+ ret[i][j] = (char *) ret + /* base address */
+ n * sizeof (void **) + /* skip 1. dim header */
+ n * m * sizeof (void *) + /* skip 2. dim header */
+ i * m * o * elementSize + /* skip to 2. dim part */
+ j * o * elementSize; /* skip to 3. dim row data */
+ }
+ return (void ***) ret;
}
@@ -174,8 +175,8 @@ GNUNET_xnew_array_3d_ (size_t n, size_t m, size_t o, size_t elementSize,
*/
void *
GNUNET_xmemdup_ (const void *buf,
- size_t size,
- const char *filename,
+ size_t size,
+ const char *filename,
int linenumber)
{
void *ret;
@@ -215,9 +216,7 @@ GNUNET_xmemdup_ (const void *buf,
* @return pointer to size bytes of memory, NULL if we do not have enough memory
*/
void *
-GNUNET_xmalloc_unchecked_ (size_t size,
- const char *filename,
- int linenumber)
+GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber)
{
void *result;
@@ -256,10 +255,7 @@ GNUNET_xmalloc_unchecked_ (size_t size,
* @return pointer to size bytes of memory
*/
void *
-GNUNET_xrealloc_ (void *ptr,
- size_t n,
- const char *filename,
- int linenumber)
+GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber)
{
(void) filename;
(void) linenumber;
@@ -272,8 +268,7 @@ GNUNET_xrealloc_ (void *ptr,
ptr = realloc (ptr, n);
if ((NULL == ptr) && (n > 0))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "realloc");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc");
GNUNET_assert (0);
}
#ifdef W32_MEM_LIMIT
@@ -283,10 +278,10 @@ GNUNET_xrealloc_ (void *ptr,
}
-# if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER == __LITTLE_ENDIAN
#define BAADFOOD_STR "\x0D\xF0\xAD\xBA"
#endif
-# if __BYTE_ORDER == __BIG_ENDIAN
+#if __BYTE_ORDER == __BIG_ENDIAN
#define BAADFOOD_STR "\xBA\xAD\xF0\x0D"
#endif
@@ -311,13 +306,9 @@ GNUNET_xrealloc_ (void *ptr,
* @param linenumber where in the code was the call to GNUNET_free
*/
void
-GNUNET_xfree_ (void *ptr,
- const char *filename,
- int linenumber)
+GNUNET_xfree_ (void *ptr, const char *filename, int linenumber)
{
- GNUNET_assert_at (NULL != ptr,
- filename,
- linenumber);
+ GNUNET_assert_at (NULL != ptr, filename, linenumber);
#ifdef W32_MEM_LIMIT
ptr = &((size_t *) ptr)[-1];
mem_used -= *((size_t *) ptr);
@@ -330,9 +321,9 @@ GNUNET_xfree_ (void *ptr,
size_t s = M_SIZE (ptr);
size_t i;
- for (i=0;i<s/8;i++)
+ for (i = 0; i < s / 8; i++)
base[i] = baadfood;
- GNUNET_memcpy (&base[s/8], &baadfood, s % 8);
+ GNUNET_memcpy (&base[s / 8], &baadfood, s % 8);
}
#endif
#endif
@@ -349,31 +340,22 @@ GNUNET_xfree_ (void *ptr,
* @return `strdup(@a str)`
*/
char *
-GNUNET_xstrdup_ (const char *str,
- const char *filename,
- int linenumber)
+GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber)
{
char *res;
size_t slen;
- GNUNET_assert_at (str != NULL,
- filename,
- linenumber);
+ GNUNET_assert_at (str != NULL, filename, linenumber);
slen = strlen (str) + 1;
- res = GNUNET_xmalloc_ (slen,
- filename,
- linenumber);
- GNUNET_memcpy (res,
- str,
- slen);
+ res = GNUNET_xmalloc_ (slen, filename, linenumber);
+ GNUNET_memcpy (res, str, slen);
return res;
}
#if ! HAVE_STRNLEN
static size_t
-strnlen (const char *s,
- size_t n)
+strnlen (const char *s, size_t n)
{
const char *e;
@@ -396,22 +378,17 @@ strnlen (const char *s,
*/
char *
GNUNET_xstrndup_ (const char *str,
- size_t len,
- const char *filename,
+ size_t len,
+ const char *filename,
int linenumber)
{
char *res;
if (0 == len)
return GNUNET_strdup ("");
- GNUNET_assert_at (NULL != str,
- filename,
- linenumber);
- len = strnlen (str,
- len);
- res = GNUNET_xmalloc_ (len + 1,
- filename,
- linenumber);
+ GNUNET_assert_at (NULL != str, filename, linenumber);
+ len = strnlen (str, len);
+ res = GNUNET_xmalloc_ (len + 1, filename, linenumber);
GNUNET_memcpy (res, str, len);
/* res[len] = '\0'; 'malloc' zeros out anyway */
return res;
@@ -432,11 +409,11 @@ GNUNET_xstrndup_ (const char *str,
*/
void
GNUNET_xgrow_ (void **old,
- size_t elementSize,
- unsigned int *oldCount,
- unsigned int newCount,
- const char *filename,
- int linenumber)
+ size_t elementSize,
+ unsigned int *oldCount,
+ unsigned int newCount,
+ const char *filename,
+ int linenumber)
{
void *tmp;
size_t size;
@@ -452,7 +429,7 @@ GNUNET_xgrow_ (void **old,
tmp = GNUNET_xmalloc_ (size, filename, linenumber);
if (NULL != *old)
{
- GNUNET_memcpy (tmp, *old, elementSize * GNUNET_MIN(*oldCount, newCount));
+ GNUNET_memcpy (tmp, *old, elementSize * GNUNET_MIN (*oldCount, newCount));
}
}
@@ -474,20 +451,18 @@ GNUNET_xgrow_ (void **old,
* @return number of bytes in `*@a buf`, excluding 0-termination
*/
int
-GNUNET_asprintf (char **buf,
- const char *format,
- ...)
+GNUNET_asprintf (char **buf, const char *format, ...)
{
int ret;
va_list args;
va_start (args, format);
- ret = VSNPRINTF (NULL, 0, format, args);
+ ret = vsnprintf (NULL, 0, format, args);
va_end (args);
GNUNET_assert (ret >= 0);
*buf = GNUNET_malloc (ret + 1);
va_start (args, format);
- ret = VSPRINTF (*buf, format, args);
+ ret = vsprintf (*buf, format, args);
va_end (args);
return ret;
}
@@ -503,21 +478,15 @@ GNUNET_asprintf (char **buf,
* @return number of bytes written to buf or negative value on error
*/
int
-GNUNET_snprintf (char *buf,
- size_t size,
- const char *format, ...)
+GNUNET_snprintf (char *buf, size_t size, const char *format, ...)
{
int ret;
va_list args;
va_start (args, format);
- ret = VSNPRINTF (buf,
- size,
- format,
- args);
+ ret = vsnprintf (buf, size, format, args);
va_end (args);
- GNUNET_assert ( (ret >= 0) &&
- (((size_t) ret) < size) );
+ GNUNET_assert ((ret >= 0) && (((size_t) ret) < size));
return ret;
}
@@ -537,9 +506,7 @@ GNUNET_copy_message (const struct GNUNET_MessageHeader *msg)
msize = ntohs (msg->size);
GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
ret = GNUNET_malloc (msize);
- GNUNET_memcpy (ret,
- msg,
- msize);
+ GNUNET_memcpy (ret, msg, msize);
return ret;
}
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index 19bbbdb81..d3666ae7d 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -107,8 +107,7 @@ static __thread struct GNUNET_AsyncScopeSave current_async_scope;
* Note that this message maybe truncated to the first BULK_TRACK_SIZE
* characters, in which case it is NOT 0-terminated!
*/
-static GNUNET_THREAD_LOCAL char last_bulk[BULK_TRACK_SIZE]
- __nonstring;
+static GNUNET_THREAD_LOCAL char last_bulk[BULK_TRACK_SIZE] __nonstring;
/**
* Type of the last bulk message.
@@ -325,7 +324,7 @@ log_rotate (const char *new_name)
{
/* Note: can't log errors during logging (recursion!), so this
operation MUST silently fail... */
- (void) UNLINK (discard);
+ (void) unlink (discard);
GNUNET_free (discard);
}
rotation[rotation_off % ROTATION_KEEP] = GNUNET_strdup (new_name);
@@ -377,14 +376,14 @@ setup_log_file (const struct tm *tm)
fprintf (stderr,
"Failed to create directory for `%s': %s\n",
fn,
- STRERROR (errno));
+ strerror (errno));
return GNUNET_SYSERR;
}
#if WINDOWS
altlog_fd =
- OPEN (fn, O_APPEND | O_BINARY | O_WRONLY | O_CREAT, _S_IREAD | _S_IWRITE);
+ open (fn, O_APPEND | O_BINARY | O_WRONLY | O_CREAT, _S_IREAD | _S_IWRITE);
#else
- altlog_fd = OPEN (fn,
+ altlog_fd = open (fn,
O_APPEND | O_WRONLY | O_CREAT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
#endif
@@ -841,7 +840,7 @@ output_message (enum GNUNET_ErrorType kind,
* this way if the output is going to logfiles or robots
* instead.
*/
- FPRINTF (GNUNET_stderr, "* %s", msg);
+ fprintf (GNUNET_stderr, "* %s", msg);
}
else if (GNUNET_YES == current_async_scope.have_scope)
{
@@ -857,7 +856,7 @@ output_message (enum GNUNET_ErrorType kind,
GNUNET_assert (NULL != end);
*end = '\0';
skip_log = 0;
- FPRINTF (GNUNET_stderr,
+ fprintf (GNUNET_stderr,
"%s %s(%s) %s %s",
datestr,
comp,
@@ -867,7 +866,7 @@ output_message (enum GNUNET_ErrorType kind,
}
else
{
- FPRINTF (GNUNET_stderr,
+ fprintf (GNUNET_stderr,
"%s %s %s %s",
datestr,
comp,
@@ -991,7 +990,7 @@ mylog (enum GNUNET_ErrorType kind,
va_list vacp;
va_copy (vacp, va);
- size = VSNPRINTF (NULL, 0, message, vacp) + 1;
+ size = vsnprintf (NULL, 0, message, vacp) + 1;
GNUNET_assert (0 != size);
va_end (vacp);
memset (date, 0, DATE_STR_SIZE);
@@ -1065,7 +1064,7 @@ mylog (enum GNUNET_ErrorType kind,
abort ();
}
#endif
- VSNPRINTF (buf, size, message, va);
+ vsnprintf (buf, size, message, va);
#if ! (defined(GNUNET_CULL_LOGGING) || TALER_WALLET_ONLY)
if (NULL != tmptr)
(void) setup_log_file (tmptr);
diff --git a/src/util/configuration.c b/src/util/configuration.c
index a38438ba8..f327071de 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -30,9 +30,10 @@
#include "gnunet_configuration_lib.h"
#include "gnunet_disk_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util", __VA_ARGS__)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
+#define LOG_STRERROR_FILE(kind, syscall, filename) \
+ GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
/**
* @brief configuration entry
@@ -95,7 +96,6 @@ struct GNUNET_CONFIGURATION_Handle
* #GNUNET_SYSERR on error (i.e. last save failed)
*/
int dirty;
-
};
@@ -152,23 +152,20 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
*/
int
GNUNET_CONFIGURATION_parse_and_run (const char *filename,
- GNUNET_CONFIGURATION_Callback cb,
- void *cb_cls)
+ GNUNET_CONFIGURATION_Callback cb,
+ void *cb_cls)
{
struct GNUNET_CONFIGURATION_Handle *cfg;
int ret;
cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_load (cfg,
- filename))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, filename))
{
GNUNET_break (0);
GNUNET_CONFIGURATION_destroy (cfg);
return GNUNET_SYSERR;
}
- ret = cb (cb_cls,
- cfg);
+ ret = cb (cb_cls, cfg);
GNUNET_CONFIGURATION_destroy (cfg);
return ret;
}
@@ -187,9 +184,9 @@ GNUNET_CONFIGURATION_parse_and_run (const char *filename,
*/
int
GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *mem,
- size_t size,
- const char *basedir)
+ const char *mem,
+ size_t size,
+ const char *basedir)
{
char *line;
char *line_orig;
@@ -224,7 +221,8 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
}
else
{
- line_orig = GNUNET_strndup (&mem[r_bytes], line_size = (pos - &mem[r_bytes]));
+ line_orig =
+ GNUNET_strndup (&mem[r_bytes], line_size = (pos - &mem[r_bytes]));
r_bytes += line_size + 1;
}
line = line_orig;
@@ -246,51 +244,46 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
continue;
/* remove tailing whitespace */
- for (i = line_size - 1; (i >= 1) && (isspace ((unsigned char) line[i]));i--)
+ for (i = line_size - 1; (i >= 1) && (isspace ((unsigned char) line[i]));
+ i--)
line[i] = '\0';
/* remove leading whitespace */
- for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++);
+ for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++)
+ ;
/* ignore comments */
- if ( ('#' == line[0]) || ('%' == line[0]) )
+ if (('#' == line[0]) || ('%' == line[0]))
continue;
/* handle special "@INLINE@" directive */
- if (0 == strncasecmp (line,
- "@INLINE@ ",
- strlen ("@INLINE@ ")))
+ if (0 == strncasecmp (line, "@INLINE@ ", strlen ("@INLINE@ ")))
{
/* @INLINE@ value */
value = &line[strlen ("@INLINE@ ")];
if (NULL != basedir)
{
- char *fn;
-
- GNUNET_asprintf (&fn,
- "%s/%s",
- basedir,
- value);
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_parse (cfg,
- fn))
- {
- GNUNET_free (fn);
- ret = GNUNET_SYSERR; /* failed to parse included config */
- break;
- }
- GNUNET_free (fn);
+ char *fn;
+
+ GNUNET_asprintf (&fn, "%s/%s", basedir, value);
+ if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, fn))
+ {
+ GNUNET_free (fn);
+ ret = GNUNET_SYSERR; /* failed to parse included config */
+ break;
+ }
+ GNUNET_free (fn);
}
else
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Ignoring parsing @INLINE@ configurations, not allowed!\n");
- ret = GNUNET_SYSERR;
- break;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Ignoring parsing @INLINE@ configurations, not allowed!\n");
+ ret = GNUNET_SYSERR;
+ break;
}
continue;
}
- if ( ('[' == line[0]) && (']' == line[line_size - 1]) )
+ if (('[' == line[0]) && (']' == line[line_size - 1]))
{
/* [value] */
line[line_size - 1] = '\0';
@@ -304,23 +297,25 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
/* tag = value */
tag = GNUNET_strndup (line, eq - line);
/* remove tailing whitespace */
- for (i = strlen (tag) - 1; (i >= 1) && (isspace ((unsigned char) tag[i]));i--)
- tag[i] = '\0';
+ for (i = strlen (tag) - 1; (i >= 1) && (isspace ((unsigned char) tag[i]));
+ i--)
+ tag[i] = '\0';
/* Strip whitespace */
value = eq + 1;
while (isspace ((unsigned char) value[0]))
- value++;
- for (i = strlen (value) - 1; (i >= 1) && (isspace ((unsigned char) value[i]));i--)
- value[i] = '\0';
+ value++;
+ for (i = strlen (value) - 1;
+ (i >= 1) && (isspace ((unsigned char) value[i]));
+ i--)
+ value[i] = '\0';
/* remove quotes */
i = 0;
- if ( ('"' == value[0]) &&
- ('"' == value[strlen (value) - 1]) )
+ if (('"' == value[0]) && ('"' == value[strlen (value) - 1]))
{
- value[strlen (value) - 1] = '\0';
- value++;
+ value[strlen (value) - 1] = '\0';
+ value++;
}
GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, &value[i]);
GNUNET_free (tag);
@@ -328,14 +323,14 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
}
/* parse error */
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Syntax error while deserializing in line %u\n"),
- nr);
+ _ ("Syntax error while deserializing in line %u\n"),
+ nr);
ret = GNUNET_SYSERR;
break;
}
GNUNET_free_non_null (line_orig);
GNUNET_free (section);
- GNUNET_assert ( (GNUNET_OK != ret) || (r_bytes == size) );
+ GNUNET_assert ((GNUNET_OK != ret) || (r_bytes == size));
return ret;
}
@@ -362,55 +357,40 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
ssize_t sret;
fn = GNUNET_STRINGS_filename_expand (filename);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to parse config file `%s'\n",
- fn);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to parse config file `%s'\n", fn);
if (NULL == fn)
return GNUNET_SYSERR;
- dirty = cfg->dirty; /* back up value! */
+ dirty = cfg->dirty; /* back up value! */
if (GNUNET_SYSERR ==
- GNUNET_DISK_file_size (fn,
- &fs64,
- GNUNET_YES,
- GNUNET_YES))
+ GNUNET_DISK_file_size (fn, &fs64, GNUNET_YES, GNUNET_YES))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- "Error while determining the file size of `%s'\n",
+ "Error while determining the file size of `%s'\n",
fn);
GNUNET_free (fn);
return GNUNET_SYSERR;
}
if (fs64 > SIZE_MAX)
{
- GNUNET_break (0); /* File size is more than the heap size */
+ GNUNET_break (0); /* File size is more than the heap size */
GNUNET_free (fn);
return GNUNET_SYSERR;
}
fs = fs64;
mem = GNUNET_malloc (fs);
- sret = GNUNET_DISK_fn_read (fn,
- mem,
- fs);
- if ( (sret < 0) ||
- (fs != (size_t) sret) )
+ sret = GNUNET_DISK_fn_read (fn, mem, fs);
+ if ((sret < 0) || (fs != (size_t) sret))
{
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Error while reading file `%s'\n"),
- fn);
+ LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Error while reading file `%s'\n"), fn);
GNUNET_free (fn);
GNUNET_free (mem);
return GNUNET_SYSERR;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Deserializing contents of file `%s'\n",
- fn);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Deserializing contents of file `%s'\n", fn);
endsep = strrchr (fn, (int) '/');
if (NULL != endsep)
*endsep = '\0';
- ret = GNUNET_CONFIGURATION_deserialize (cfg,
- mem,
- fs,
- fn);
+ ret = GNUNET_CONFIGURATION_deserialize (cfg, mem, fs, fn);
GNUNET_free (fn);
GNUNET_free (mem);
/* restore dirty flag - anything we set in the meantime
@@ -444,7 +424,7 @@ GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg)
*/
char *
GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
- size_t *size)
+ size_t *size)
{
struct ConfigSection *sec;
struct ConfigEntry *ent;
@@ -466,16 +446,16 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
{
if (NULL != ent->val)
{
- /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
- pos = ent->val;
- while (NULL != (pos = strstr (pos, "\n")))
- {
- m_size++;
- pos++;
- }
- /* For each key = value pair we need to add 4 characters (2
+ /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
+ pos = ent->val;
+ while (NULL != (pos = strstr (pos, "\n")))
+ {
+ m_size++;
+ pos++;
+ }
+ /* For each key = value pair we need to add 4 characters (2
spaces and 1 equal-to character and 1 new line) */
- m_size += strlen (ent->key) + strlen (ent->val) + 4;
+ m_size += strlen (ent->key) + strlen (ent->val) + 4;
}
}
/* A new line after section end */
@@ -498,23 +478,23 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
{
if (NULL != ent->val)
{
- val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
- strcpy (val, ent->val);
+ val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
+ strcpy (val, ent->val);
while (NULL != (pos = strstr (val, "\n")))
{
memmove (&pos[2], &pos[1], strlen (&pos[1]));
pos[0] = '\\';
pos[1] = 'n';
}
- len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
- GNUNET_free (val);
- GNUNET_memcpy (mem + c_size, cbuf, len);
- c_size += len;
- GNUNET_free (cbuf);
+ len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
+ GNUNET_free (val);
+ GNUNET_memcpy (mem + c_size, cbuf, len);
+ c_size += len;
+ GNUNET_free (cbuf);
}
}
GNUNET_memcpy (mem + c_size, "\n", 1);
- c_size ++;
+ c_size++;
sec = sec->next;
}
GNUNET_assert (c_size == m_size);
@@ -548,25 +528,26 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
return GNUNET_SYSERR;
}
cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, &size);
- sret = GNUNET_DISK_fn_write (fn, cfg_buf, size,
- GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE
- | GNUNET_DISK_PERM_GROUP_READ
- | GNUNET_DISK_PERM_GROUP_WRITE);
- if ( (sret < 0) ||
- (size != (size_t) sret) )
+ sret = GNUNET_DISK_fn_write (fn,
+ cfg_buf,
+ size,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_READ |
+ GNUNET_DISK_PERM_GROUP_WRITE);
+ if ((sret < 0) || (size != (size_t) sret))
{
GNUNET_free (fn);
GNUNET_free (cfg_buf);
LOG (GNUNET_ERROR_TYPE_WARNING,
- "Writing configuration to file `%s' failed\n",
+ "Writing configuration to file `%s' failed\n",
filename);
cfg->dirty = GNUNET_SYSERR; /* last write failed */
return GNUNET_SYSERR;
}
GNUNET_free (fn);
GNUNET_free (cfg_buf);
- cfg->dirty = GNUNET_NO; /* last write succeeded */
+ cfg->dirty = GNUNET_NO; /* last write succeeded */
return GNUNET_OK;
}
@@ -589,7 +570,7 @@ GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
for (spos = cfg->sections; NULL != spos; spos = spos->next)
for (epos = spos->entries; NULL != epos; epos = epos->next)
if (NULL != epos->val)
- iter (iter_cls, spos->name, epos->key, epos->val);
+ iter (iter_cls, spos->name, epos->key, epos->val);
}
@@ -602,11 +583,11 @@ GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
* @param iter_cls closure for @a iter
*/
void
-GNUNET_CONFIGURATION_iterate_section_values (const struct
- GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- GNUNET_CONFIGURATION_Iterator iter,
- void *iter_cls)
+GNUNET_CONFIGURATION_iterate_section_values (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ GNUNET_CONFIGURATION_Iterator iter,
+ void *iter_cls)
{
struct ConfigSection *spos;
struct ConfigEntry *epos;
@@ -630,9 +611,10 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct
* @param iter_cls closure for @a iter
*/
void
-GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_CONFIGURATION_Section_Iterator iter,
- void *iter_cls)
+GNUNET_CONFIGURATION_iterate_sections (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ GNUNET_CONFIGURATION_Section_Iterator iter,
+ void *iter_cls)
{
struct ConfigSection *spos;
struct ConfigSection *next;
@@ -757,8 +739,8 @@ find_section (const struct GNUNET_CONFIGURATION_Handle *cfg,
*/
static struct ConfigEntry *
find_entry (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *key)
+ const char *section,
+ const char *key)
{
struct ConfigSection *sec;
struct ConfigEntry *pos;
@@ -786,15 +768,14 @@ static void
compare_entries (void *cls,
const char *section,
const char *option,
- const char *value)
+ const char *value)
{
struct DiffHandle *dh = cls;
struct ConfigEntry *entNew;
entNew = find_entry (dh->cfg_default, section, option);
- if ( (NULL != entNew) &&
- (NULL != entNew->val) &&
- (0 == strcmp (entNew->val, value)) )
+ if ((NULL != entNew) && (NULL != entNew->val) &&
+ (0 == strcmp (entNew->val, value)))
return;
GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value);
}
@@ -808,8 +789,9 @@ compare_entries (void *cls,
* @return configuration with only the differences, never NULL
*/
struct GNUNET_CONFIGURATION_Handle *
-GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle *cfg_default,
- const struct GNUNET_CONFIGURATION_Handle *cfg_new)
+GNUNET_CONFIGURATION_get_diff (
+ const struct GNUNET_CONFIGURATION_Handle *cfg_default,
+ const struct GNUNET_CONFIGURATION_Handle *cfg_new)
{
struct DiffHandle diffHandle;
@@ -829,10 +811,10 @@ GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle *cfg_def
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
- *cfg_default,
- const struct GNUNET_CONFIGURATION_Handle
- *cfg_new, const char *filename)
+GNUNET_CONFIGURATION_write_diffs (
+ const struct GNUNET_CONFIGURATION_Handle *cfg_default,
+ const struct GNUNET_CONFIGURATION_Handle *cfg_new,
+ const char *filename)
{
int ret;
struct GNUNET_CONFIGURATION_Handle *diff;
@@ -854,7 +836,8 @@ GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle
*/
void
GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section, const char *option,
+ const char *section,
+ const char *option,
const char *value)
{
struct ConfigSection *sec;
@@ -904,19 +887,13 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
void
GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
const char *section,
- const char *option,
+ const char *option,
unsigned long long number)
{
char s[64];
- GNUNET_snprintf (s,
- 64,
- "%llu",
- number);
- GNUNET_CONFIGURATION_set_value_string (cfg,
- section,
- option,
- s);
+ GNUNET_snprintf (s, 64, "%llu", number);
+ GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s);
}
@@ -930,10 +907,11 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- unsigned long long *number)
+GNUNET_CONFIGURATION_get_value_number (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ unsigned long long *number)
{
struct ConfigEntry *e;
char dummy[2];
@@ -942,10 +920,7 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
return GNUNET_SYSERR;
if (NULL == e->val)
return GNUNET_SYSERR;
- if (1 != SSCANF (e->val,
- "%llu%1s",
- number,
- dummy))
+ if (1 != sscanf (e->val, "%llu%1s", number, dummy))
return GNUNET_SYSERR;
return GNUNET_OK;
}
@@ -961,10 +936,11 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- float *number)
+GNUNET_CONFIGURATION_get_value_float (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ float *number)
{
struct ConfigEntry *e;
char dummy[2];
@@ -973,16 +949,12 @@ GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle
return GNUNET_SYSERR;
if (NULL == e->val)
return GNUNET_SYSERR;
- if (1 != SSCANF (e->val,
- "%f%1s",
- number,
- dummy))
+ if (1 != sscanf (e->val, "%f%1s", number, dummy))
return GNUNET_SYSERR;
return GNUNET_OK;
}
-
/**
* Get a configuration value that should be a relative time.
*
@@ -993,27 +965,25 @@ GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- struct GNUNET_TIME_Relative *time)
+GNUNET_CONFIGURATION_get_value_time (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ struct GNUNET_TIME_Relative *time)
{
struct ConfigEntry *e;
int ret;
- if (NULL == (e = find_entry (cfg,
- section,
- option)))
+ if (NULL == (e = find_entry (cfg, section, option)))
return GNUNET_SYSERR;
if (NULL == e->val)
return GNUNET_SYSERR;
- ret = GNUNET_STRINGS_fancy_time_to_relative (e->val,
- time);
+ ret = GNUNET_STRINGS_fancy_time_to_relative (e->val, time);
if (GNUNET_OK != ret)
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
section,
option,
- _("Not a valid relative time specification"));
+ _ ("Not a valid relative time specification"));
return ret;
}
@@ -1028,10 +998,11 @@ GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *c
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- unsigned long long *size)
+GNUNET_CONFIGURATION_get_value_size (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ unsigned long long *size)
{
struct ConfigEntry *e;
@@ -1054,15 +1025,15 @@ GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle *c
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- char **value)
+GNUNET_CONFIGURATION_get_value_string (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ char **value)
{
struct ConfigEntry *e;
- if ( (NULL == (e = find_entry (cfg, section, option))) ||
- (NULL == e->val) )
+ if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val))
{
*value = NULL;
return GNUNET_SYSERR;
@@ -1085,11 +1056,12 @@ GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- const char *const *choices,
- const char **value)
+GNUNET_CONFIGURATION_get_value_choice (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ const char *const *choices,
+ const char **value)
{
struct ConfigEntry *e;
unsigned int i;
@@ -1102,8 +1074,8 @@ GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
if (NULL == choices[i])
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Configuration value '%s' for '%s'"
- " in section '%s' is not in set of legal choices\n"),
+ _ ("Configuration value '%s' for '%s'"
+ " in section '%s' is not in set of legal choices\n"),
e->val,
option,
section);
@@ -1138,10 +1110,8 @@ GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
size_t data_size;
if (GNUNET_OK !=
- (res = GNUNET_CONFIGURATION_get_value_string (cfg,
- section,
- option,
- &enc)))
+ (res =
+ GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &enc)))
return res;
data_size = (strlen (enc) * 5) / 8;
if (data_size != buf_size)
@@ -1150,9 +1120,7 @@ GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (enc,
- strlen (enc),
- buf, buf_size))
+ GNUNET_STRINGS_string_to_data (enc, strlen (enc), buf, buf_size))
{
GNUNET_free (enc);
return GNUNET_SYSERR;
@@ -1221,17 +1189,15 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
if (depth > 128)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Recursive expansion suspected, aborting $-expansion for term `%s'\n"),
+ _ (
+ "Recursive expansion suspected, aborting $-expansion for term `%s'\n"),
orig);
return orig;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Asked to $-expand %s\n",
- orig);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to $-expand %s\n", orig);
if ('$' != orig[0])
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Doesn't start with $ - not expanding\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Doesn't start with $ - not expanding\n");
return orig;
}
erased_char = 0;
@@ -1254,7 +1220,7 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
break;
case '\0':
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Missing closing `%s' in option `%s'\n"),
+ _ ("Missing closing `%s' in option `%s'\n"),
"}",
orig);
return orig;
@@ -1271,8 +1237,7 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
{
*def = '\0';
def++;
- if ( ('-' == *def) ||
- ('=' == *def) )
+ if (('-' == *def) || ('=' == *def))
def++;
def = GNUNET_strdup (def);
}
@@ -1282,10 +1247,8 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
start = &orig[1];
def = NULL;
i = 0;
- while ( (orig[i] != '/') &&
- (orig[i] != '\\') &&
- (orig[i] != '\0') &&
- (orig[i] != ' ') )
+ while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0') &&
+ (orig[i] != ' '))
i++;
if (orig[i] == '\0')
{
@@ -1305,10 +1268,7 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
post,
def);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "PATHS",
- start,
- &prefix))
+ GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", start, &prefix))
{
if (NULL == (env = getenv (start)))
{
@@ -1322,15 +1282,17 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
if (erased_pos)
*erased_pos = erased_char;
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n"),
- start, orig);
+ _ (
+ "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n"),
+ start,
+ orig);
GNUNET_free (start);
return orig;
}
prefix = GNUNET_strdup (env);
}
prefix = GNUNET_CONFIGURATION_expand_dollar (cfg, prefix);
- if ( (erased_pos) && ('}' != erased_char) )
+ if ((erased_pos) && ('}' != erased_char))
{
len = strlen (prefix) + 1;
prefix = GNUNET_realloc (prefix, len + 1);
@@ -1364,8 +1326,9 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
* @return $-expanded string
*/
char *
-GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
- char *orig)
+GNUNET_CONFIGURATION_expand_dollar (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ char *orig)
{
char *dup;
size_t i;
@@ -1397,18 +1360,18 @@ GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cf
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- char **value)
+GNUNET_CONFIGURATION_get_value_filename (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ char **value)
{
char *tmp;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp))
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to retrieve filename\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n");
*value = NULL;
return GNUNET_SYSERR;
}
@@ -1431,16 +1394,17 @@ GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handl
* @return #GNUNET_YES, #GNUNET_NO or #GNUNET_SYSERR
*/
int
-GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option)
+GNUNET_CONFIGURATION_get_value_yesno (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option)
{
- static const char *yesno[] = { "YES", "NO", NULL };
+ static const char *yesno[] = {"YES", "NO", NULL};
const char *val;
int ret;
ret =
- GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
+ GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val);
if (ret == GNUNET_SYSERR)
return ret;
if (val == yesno[0])
@@ -1460,11 +1424,12 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *
* @return number of filenames iterated over, -1 on error
*/
int
-GNUNET_CONFIGURATION_iterate_value_filenames (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- GNUNET_FileNameCallback cb,
- void *cb_cls)
+GNUNET_CONFIGURATION_iterate_value_filenames (
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ GNUNET_FileNameCallback cb,
+ void *cb_cls)
{
char *list;
char *pos;
@@ -1590,20 +1555,23 @@ test_match (void *cls, const char *fn)
* #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option,
- const char *value)
+GNUNET_CONFIGURATION_append_value_filename (
+ struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ const char *value)
{
char *escaped;
char *old;
char *nw;
if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_iterate_value_filenames (cfg, section, option,
+ GNUNET_CONFIGURATION_iterate_value_filenames (cfg,
+ section,
+ option,
&test_match,
(void *) value))
- return GNUNET_NO; /* already exists */
+ return GNUNET_NO; /* already exists */
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
old = GNUNET_strdup ("");
@@ -1634,10 +1602,11 @@ GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *
* #GNUNET_SYSERR on error
*/
int
-GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
- *cfg, const char *section,
- const char *option,
- const char *value)
+GNUNET_CONFIGURATION_remove_value_filename (
+ struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option,
+ const char *value)
{
char *list;
char *pos;
@@ -1719,16 +1688,14 @@ static int
parse_configuration_file (void *cls, const char *filename)
{
struct GNUNET_CONFIGURATION_Handle *cfg = cls;
- char * ext;
+ char *ext;
int ret;
/* Examine file extension */
ext = strrchr (filename, '.');
if ((NULL == ext) || (0 != strcmp (ext, ".conf")))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Skipping file `%s'\n",
- filename);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Skipping file `%s'\n", filename);
return GNUNET_OK;
}
@@ -1747,13 +1714,11 @@ parse_configuration_file (void *cls, const char *filename)
*/
int
GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *defaults_d)
+ const char *defaults_d)
{
if (GNUNET_SYSERR ==
- GNUNET_DISK_directory_scan (defaults_d,
- &parse_configuration_file,
- cfg))
- return GNUNET_SYSERR; /* no configuration at all found */
+ GNUNET_DISK_directory_scan (defaults_d, &parse_configuration_file, cfg))
+ return GNUNET_SYSERR; /* no configuration at all found */
return GNUNET_OK;
}
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c
index a41c0cf8a..fe7d86421 100644
--- a/src/util/container_bloomfilter.c
+++ b/src/util/container_bloomfilter.c
@@ -42,11 +42,17 @@
#include "platform.h"
#include "gnunet_util_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util-container-bloomfilter", __VA_ARGS__)
+#define LOG(kind, ...) \
+ GNUNET_log_from (kind, "util-container-bloomfilter", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-container-bloomfilter", syscall)
+#define LOG_strerror(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-container-bloomfilter", syscall)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-container-bloomfilter", syscall, filename)
+#define LOG_strerror_FILE(kind, syscall, filename) \
+ GNUNET_log_from_strerror_file (kind, \
+ "util-container-bloomfilter", \
+ syscall, \
+ filename)
struct GNUNET_CONTAINER_BloomFilter
{
@@ -75,7 +81,6 @@ struct GNUNET_CONTAINER_BloomFilter
* Size of bitArray in bytes
*/
size_t bitArraySize;
-
};
@@ -86,8 +91,8 @@ struct GNUNET_CONTAINER_BloomFilter
* @return addresses set per element in the bf
*/
size_t
-GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct GNUNET_CONTAINER_BloomFilter
- *bf)
+GNUNET_CONTAINER_bloomfilter_get_element_addresses (
+ const struct GNUNET_CONTAINER_BloomFilter *bf)
{
if (bf == NULL)
return 0;
@@ -102,8 +107,8 @@ GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct GNUNET_CONTAINE
* @return number of bytes used for the data of the bloom filter
*/
size_t
-GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter
- *bf)
+GNUNET_CONTAINER_bloomfilter_get_size (
+ const struct GNUNET_CONTAINER_BloomFilter *bf)
{
if (bf == NULL)
return 0;
@@ -118,10 +123,11 @@ GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter
* @return copy of the bf
*/
struct GNUNET_CONTAINER_BloomFilter *
-GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter
- *bf)
+GNUNET_CONTAINER_bloomfilter_copy (
+ const struct GNUNET_CONTAINER_BloomFilter *bf)
{
- return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, bf->bitArraySize,
+ return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray,
+ bf->bitArraySize,
bf->addressesPerElement);
}
@@ -193,7 +199,8 @@ testBit (char *bitArray, unsigned int bitIdx)
* @param fh A file to keep the 4 bit address usage counters in
*/
static void
-incrementBit (char *bitArray, unsigned int bitIdx,
+incrementBit (char *bitArray,
+ unsigned int bitIdx,
const struct GNUNET_DISK_FileHandle *fh)
{
off_t fileSlot;
@@ -241,7 +248,8 @@ incrementBit (char *bitArray, unsigned int bitIdx,
* @param fh A file to keep the 4bit address usage counters in
*/
static void
-decrementBit (char *bitArray, unsigned int bitIdx,
+decrementBit (char *bitArray,
+ unsigned int bitIdx,
const struct GNUNET_DISK_FileHandle *fh)
{
off_t fileslot;
@@ -251,15 +259,16 @@ decrementBit (char *bitArray, unsigned int bitIdx,
unsigned int targetLoc;
if (GNUNET_DISK_handle_invalid (fh))
- return; /* cannot decrement! */
+ return; /* cannot decrement! */
/* Each char slot in the counter file holds two 4 bit counters */
fileslot = bitIdx / 2;
targetLoc = bitIdx % 2;
- if (GNUNET_SYSERR == GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek");
- return;
- }
+ if (GNUNET_SYSERR ==
+ GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek");
+ return;
+ }
if (1 != GNUNET_DISK_file_read (fh, &value, 1))
value = 0;
low = value & 0xF;
@@ -285,11 +294,12 @@ decrementBit (char *bitArray, unsigned int bitIdx,
}
}
value = ((high << 4) | low);
- if (GNUNET_SYSERR == GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek");
- return;
- }
+ if (GNUNET_SYSERR ==
+ GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek");
+ return;
+ }
GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1));
}
@@ -319,13 +329,13 @@ make_empty_file (const struct GNUNET_DISK_FileHandle *fh, size_t size)
{
res = GNUNET_DISK_file_write (fh, buffer, sizeof (buffer));
if (res >= 0)
- bytesleft -= res;
+ bytesleft -= res;
}
else
{
res = GNUNET_DISK_file_write (fh, buffer, bytesleft);
if (res >= 0)
- bytesleft -= res;
+ bytesleft -= res;
}
if (GNUNET_SYSERR == res)
return GNUNET_SYSERR;
@@ -346,7 +356,7 @@ make_empty_file (const struct GNUNET_DISK_FileHandle *fh, size_t size)
* @return GNUNET_YES to continue, GNUNET_NO to stop early
*/
typedef int (*BitIterator) (void *cls,
- const struct GNUNET_CONTAINER_BloomFilter * bf,
+ const struct GNUNET_CONTAINER_BloomFilter *bf,
unsigned int bit);
@@ -361,7 +371,9 @@ typedef int (*BitIterator) (void *cls,
*/
static void
iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
- BitIterator callback, void *arg, const struct GNUNET_HashCode *key)
+ BitIterator callback,
+ void *arg,
+ const struct GNUNET_HashCode *key)
{
struct GNUNET_HashCode tmp[2];
int bitCount;
@@ -378,9 +390,10 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
while (slot < (sizeof (struct GNUNET_HashCode) / sizeof (uint32_t)))
{
if (GNUNET_YES !=
- callback (arg, bf,
- ntohl ((((uint32_t *) & tmp[round & 1])[slot])) %
- ((bf->bitArraySize * 8LL))))
+ callback (arg,
+ bf,
+ ntohl ((((uint32_t *) &tmp[round & 1])[slot])) %
+ ((bf->bitArraySize * 8LL))))
return;
slot++;
bitCount--;
@@ -389,7 +402,8 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
}
if (bitCount > 0)
{
- GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (struct GNUNET_HashCode),
+ GNUNET_CRYPTO_hash (&tmp[round & 1],
+ sizeof (struct GNUNET_HashCode),
&tmp[(round + 1) & 1]);
round++;
slot = 0;
@@ -407,7 +421,8 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
* @return GNUNET_YES
*/
static int
-incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
+incrementBitCallback (void *cls,
+ const struct GNUNET_CONTAINER_BloomFilter *bf,
unsigned int bit)
{
struct GNUNET_CONTAINER_BloomFilter *b = cls;
@@ -426,7 +441,8 @@ incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
* @return GNUNET_YES
*/
static int
-decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
+decrementBitCallback (void *cls,
+ const struct GNUNET_CONTAINER_BloomFilter *bf,
unsigned int bit)
{
struct GNUNET_CONTAINER_BloomFilter *b = cls;
@@ -445,7 +461,8 @@ decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
* @return YES if the bit is set, NO if not
*/
static int
-testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
+testBitCallback (void *cls,
+ const struct GNUNET_CONTAINER_BloomFilter *bf,
unsigned int bit)
{
int *arg = cls;
@@ -472,7 +489,8 @@ testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
* @return the bloomfilter
*/
struct GNUNET_CONTAINER_BloomFilter *
-GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
+GNUNET_CONTAINER_bloomfilter_load (const char *filename,
+ size_t size,
unsigned int k)
{
struct GNUNET_CONTAINER_BloomFilter *bf;
@@ -489,25 +507,22 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
if (size < BUFFSIZE)
size = BUFFSIZE;
ui = 1;
- while ( (ui < size) &&
- (ui * 2 > ui) )
+ while ((ui < size) && (ui * 2 > ui))
ui *= 2;
- size = ui; /* make sure it's a power of 2 */
+ size = ui; /* make sure it's a power of 2 */
bf = GNUNET_new (struct GNUNET_CONTAINER_BloomFilter);
/* Try to open a bloomfilter file */
if (GNUNET_YES == GNUNET_DISK_file_test (filename))
- bf->fh =
- GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_READWRITE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ bf->fh = GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_READWRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (NULL != bf->fh)
{
/* file existed, try to read it! */
must_read = GNUNET_YES;
- if (GNUNET_OK !=
- GNUNET_DISK_file_handle_size (bf->fh, &fsize))
+ if (GNUNET_OK != GNUNET_DISK_file_handle_size (bf->fh, &fsize))
{
GNUNET_DISK_file_close (bf->fh);
GNUNET_free (bf);
@@ -516,22 +531,22 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
if (0 == fsize)
{
/* found existing empty file, just overwrite */
- if (GNUNET_OK !=
- make_empty_file (bf->fh, size * 4LL))
+ if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "write");
- GNUNET_DISK_file_close (bf->fh);
- GNUNET_free (bf);
- return NULL;
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
+ GNUNET_DISK_file_close (bf->fh);
+ GNUNET_free (bf);
+ return NULL;
}
}
else if (fsize != ((off_t) size) * 4LL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"),
- (unsigned long long) (size * 4LL),
- (unsigned long long) fsize);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ (
+ "Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"),
+ (unsigned long long) (size * 4LL),
+ (unsigned long long) fsize);
GNUNET_DISK_file_close (bf->fh);
GNUNET_free (bf);
return NULL;
@@ -541,21 +556,19 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
{
/* file did not exist, don't read, just create */
must_read = GNUNET_NO;
- bf->fh =
- GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_CREATE |
- GNUNET_DISK_OPEN_READWRITE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ bf->fh = GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_CREATE |
+ GNUNET_DISK_OPEN_READWRITE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (NULL == bf->fh)
- {
- GNUNET_free (bf);
- return NULL;
- }
+ {
+ GNUNET_free (bf);
+ return NULL;
+ }
if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "write");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
GNUNET_DISK_file_close (bf->fh);
GNUNET_free (bf);
return NULL;
@@ -583,14 +596,10 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
{
int res;
- res = GNUNET_DISK_file_read (bf->fh,
- rbuff,
- BUFFSIZE);
+ res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
if (res == -1)
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "read",
- bf->filename);
+ LOG_strerror_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename);
GNUNET_free (rbuff);
GNUNET_free (bf->filename);
GNUNET_DISK_file_close (bf->fh);
@@ -598,7 +607,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
return NULL;
}
if (res == 0)
- break; /* is ok! we just did not use that many bits yet */
+ break; /* is ok! we just did not use that many bits yet */
for (i = 0; i < res; i++)
{
if ((rbuff[i] & 0x0F) != 0)
@@ -608,7 +617,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
}
if (res < BUFFSIZE)
break;
- pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */
+ pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */
}
GNUNET_free (rbuff);
return bf;
@@ -629,7 +638,8 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
* @return the bloomfilter
*/
struct GNUNET_CONTAINER_BloomFilter *
-GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size,
+GNUNET_CONTAINER_bloomfilter_init (const char *data,
+ size_t size,
unsigned int k)
{
struct GNUNET_CONTAINER_BloomFilter *bf;
@@ -663,9 +673,10 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size,
* @return #GNUNET_SYSERR if the data array is not big enough
*/
int
-GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct
- GNUNET_CONTAINER_BloomFilter *bf,
- char *data, size_t size)
+GNUNET_CONTAINER_bloomfilter_get_raw_data (
+ const struct GNUNET_CONTAINER_BloomFilter *bf,
+ char *data,
+ size_t size)
{
if (NULL == bf)
return GNUNET_SYSERR;
@@ -721,8 +732,9 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf)
* @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf,
- const struct GNUNET_HashCode * e)
+GNUNET_CONTAINER_bloomfilter_test (
+ const struct GNUNET_CONTAINER_BloomFilter *bf,
+ const struct GNUNET_HashCode *e)
{
int res;
@@ -742,7 +754,7 @@ GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf
*/
void
GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
- const struct GNUNET_HashCode * e)
+ const struct GNUNET_HashCode *e)
{
if (NULL == bf)
return;
@@ -763,7 +775,7 @@ GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
int
GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
const char *data,
- size_t size)
+ size_t size)
{
unsigned int i;
unsigned int n;
@@ -796,8 +808,9 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
* @return #GNUNET_OK on success
*/
int
-GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
- const struct GNUNET_CONTAINER_BloomFilter *to_or)
+GNUNET_CONTAINER_bloomfilter_or2 (
+ struct GNUNET_CONTAINER_BloomFilter *bf,
+ const struct GNUNET_CONTAINER_BloomFilter *to_or)
{
unsigned int i;
unsigned int n;
@@ -839,10 +852,7 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
return;
if (NULL == bf->filename)
return;
- iterateBits (bf,
- &decrementBitCallback,
- bf,
- e);
+ iterateBits (bf, &decrementBitCallback, bf, e);
}
/**
@@ -860,7 +870,7 @@ void
GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
GNUNET_CONTAINER_HashCodeIterator iterator,
void *iterator_cls,
- size_t size,
+ size_t size,
unsigned int k)
{
struct GNUNET_HashCode hc;
@@ -870,17 +880,14 @@ GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
i = 1;
while (i < size)
i *= 2;
- size = i; /* make sure it's a power of 2 */
+ size = i; /* make sure it's a power of 2 */
bf->addressesPerElement = k;
bf->bitArraySize = size;
bf->bitArray = GNUNET_malloc (size);
if (NULL != bf->filename)
- make_empty_file (bf->fh,
- bf->bitArraySize * 4LL);
- while (GNUNET_YES == iterator (iterator_cls,
- &hc))
- GNUNET_CONTAINER_bloomfilter_add (bf,
- &hc);
+ make_empty_file (bf->fh, bf->bitArraySize * 4LL);
+ while (GNUNET_YES == iterator (iterator_cls, &hc))
+ GNUNET_CONTAINER_bloomfilter_add (bf, &hc);
}
/* end of container_bloomfilter.c */
diff --git a/src/util/crypto_ecc_setup.c b/src/util/crypto_ecc_setup.c
index 1031b302e..c556d805d 100644
--- a/src/util/crypto_ecc_setup.c
+++ b/src/util/crypto_ecc_setup.c
@@ -27,18 +27,29 @@
#include <gcrypt.h>
#include "gnunet_util_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-crypto-ecc", syscall, filename)
+#define LOG_STRERROR_FILE(kind, syscall, filename) \
+ GNUNET_log_from_strerror_file (kind, "util-crypto-ecc", syscall, filename)
/**
* Log an error message at log-level 'level' that indicates
* a failure of the command 'cmd' with the message given
* by gcry_strerror(rc).
*/
-#define LOG_GCRY(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gcry_strerror(rc)); } while(0)
+#define LOG_GCRY(level, cmd, rc) \
+ do \
+ { \
+ LOG (level, \
+ _ ("`%s' failed at %s:%d with error: %s\n"), \
+ cmd, \
+ __FILE__, \
+ __LINE__, \
+ gcry_strerror (rc)); \
+ } while (0)
/**
@@ -86,11 +97,12 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
return NULL;
while (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
- fd = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE
- | GNUNET_DISK_OPEN_FAILIFEXISTS,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ fd =
+ GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
+ GNUNET_DISK_OPEN_FAILIFEXISTS,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (NULL == fd)
{
if (EEXIST == errno)
@@ -98,10 +110,10 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
if (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
/* must exist but not be accessible, fail for good! */
- if (0 != ACCESS (filename, R_OK))
+ if (0 != access (filename, R_OK))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename);
else
- GNUNET_break (0); /* what is going on!? */
+ GNUNET_break (0); /* what is going on!? */
return NULL;
}
continue;
@@ -111,7 +123,8 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
}
cnt = 0;
while (GNUNET_YES !=
- GNUNET_DISK_file_lock (fd, 0,
+ GNUNET_DISK_file_lock (fd,
+ 0,
sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey),
GNUNET_YES))
{
@@ -120,27 +133,29 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
{
ec = errno;
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Could not acquire lock on file `%s': %s...\n"),
- filename,
- STRERROR (ec));
+ _ ("Could not acquire lock on file `%s': %s...\n"),
+ filename,
+ strerror (ec));
}
}
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Creating a new private key. This may take a while.\n"));
+ _ ("Creating a new private key. This may take a while.\n"));
priv = GNUNET_CRYPTO_eddsa_key_create ();
GNUNET_assert (NULL != priv);
GNUNET_assert (sizeof (*priv) ==
GNUNET_DISK_file_write (fd, priv, sizeof (*priv)));
GNUNET_DISK_file_sync (fd);
if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
+ GNUNET_DISK_file_unlock (fd,
+ 0,
sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
return priv;
}
/* key file exists already, read it! */
- fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
+ fd = GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
if (NULL == fd)
{
@@ -151,7 +166,8 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
while (1)
{
if (GNUNET_YES !=
- GNUNET_DISK_file_lock (fd, 0,
+ GNUNET_DISK_file_lock (fd,
+ 0,
sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey),
GNUNET_NO))
{
@@ -159,11 +175,13 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
{
ec = errno;
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Could not acquire lock on file `%s': %s...\n"), filename,
- STRERROR (ec));
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _
- ("This may be ok if someone is currently generating a private key.\n"));
+ _ ("Could not acquire lock on file `%s': %s...\n"),
+ filename,
+ strerror (ec));
+ LOG (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ (
+ "This may be ok if someone is currently generating a private key.\n"));
}
short_wait ();
continue;
@@ -173,57 +191,56 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
/* eh, what!? File we opened is now gone!? */
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
- sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)))
+ GNUNET_DISK_file_unlock (fd,
+ 0,
+ sizeof (
+ struct GNUNET_CRYPTO_EddsaPrivateKey)))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
return NULL;
}
- if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
fs = 0;
if (fs < sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))
{
/* maybe we got the read lock before the key generating
* process had a chance to get the write lock; give it up! */
if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
- sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)))
+ GNUNET_DISK_file_unlock (fd,
+ 0,
+ sizeof (
+ struct GNUNET_CRYPTO_EddsaPrivateKey)))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
if (0 == ++cnt % 10)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
+ _ (
+ "When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
filename,
- (unsigned int) fs,
+ (unsigned int) fs,
(unsigned int) sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("This may be ok if someone is currently generating a key.\n"));
+ _ ("This may be ok if someone is currently generating a key.\n"));
}
- short_wait (); /* wait a bit longer! */
+ short_wait (); /* wait a bit longer! */
continue;
}
break;
}
fs = sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey);
priv = GNUNET_malloc (fs);
- sret = GNUNET_DISK_file_read (fd,
- priv,
- fs);
- GNUNET_assert ( (sret >= 0) &&
- (fs == (size_t) sret) );
+ sret = GNUNET_DISK_file_read (fd, priv, fs);
+ GNUNET_assert ((sret >= 0) && (fs == (size_t) sret));
if (GNUNET_YES !=
GNUNET_DISK_file_unlock (fd,
- 0,
+ 0,
sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "fcntl",
- filename);
- GNUNET_assert (GNUNET_YES ==
- GNUNET_DISK_file_close (fd));
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
+ GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
#if CRYPTO_BUG
- if (GNUNET_OK !=
- check_eddsa_key (priv))
+ if (GNUNET_OK != check_eddsa_key (priv))
{
GNUNET_break (0);
GNUNET_free (priv);
@@ -258,16 +275,16 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
uint64_t fs;
ssize_t sret;
- if (GNUNET_SYSERR ==
- GNUNET_DISK_directory_create_for_file (filename))
+ if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
return NULL;
while (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
- fd = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE
- | GNUNET_DISK_OPEN_FAILIFEXISTS,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ fd =
+ GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
+ GNUNET_DISK_OPEN_FAILIFEXISTS,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE);
if (NULL == fd)
{
if (EEXIST == errno)
@@ -275,25 +292,21 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
if (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
/* must exist but not be accessible, fail for good! */
- if (0 != ACCESS (filename, R_OK))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
- "access",
- filename);
+ if (0 != access (filename, R_OK))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename);
else
- GNUNET_break (0); /* what is going on!? */
+ GNUNET_break (0); /* what is going on!? */
return NULL;
}
continue;
}
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
- "open",
- filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
return NULL;
}
cnt = 0;
while (GNUNET_YES !=
GNUNET_DISK_file_lock (fd,
- 0,
+ 0,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
GNUNET_YES))
{
@@ -302,46 +315,41 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
{
ec = errno;
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Could not acquire lock on file `%s': %s...\n"),
- filename,
- STRERROR (ec));
+ _ ("Could not acquire lock on file `%s': %s...\n"),
+ filename,
+ strerror (ec));
}
}
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Creating a new private key. This may take a while.\n"));
+ _ ("Creating a new private key. This may take a while.\n"));
priv = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (NULL != priv);
GNUNET_assert (sizeof (*priv) ==
- GNUNET_DISK_file_write (fd,
- priv,
- sizeof (*priv)));
+ GNUNET_DISK_file_write (fd, priv, sizeof (*priv)));
GNUNET_DISK_file_sync (fd);
if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
+ GNUNET_DISK_file_unlock (fd,
+ 0,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "fcntl",
- filename);
- GNUNET_assert (GNUNET_YES ==
- GNUNET_DISK_file_close (fd));
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
+ GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
return priv;
}
/* key file exists already, read it! */
fd = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
if (NULL == fd)
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
- "open",
- filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename);
return NULL;
}
cnt = 0;
while (1)
{
if (GNUNET_YES !=
- GNUNET_DISK_file_lock (fd, 0,
+ GNUNET_DISK_file_lock (fd,
+ 0,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
GNUNET_NO))
{
@@ -349,78 +357,70 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
{
ec = errno;
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Could not acquire lock on file `%s': %s...\n"),
- filename,
- STRERROR (ec));
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("This may be ok if someone is currently generating a private key.\n"));
+ _ ("Could not acquire lock on file `%s': %s...\n"),
+ filename,
+ strerror (ec));
+ LOG (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ (
+ "This may be ok if someone is currently generating a private key.\n"));
}
short_wait ();
continue;
}
- if (GNUNET_YES !=
- GNUNET_DISK_file_test (filename))
+ if (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
/* eh, what!? File we opened is now gone!? */
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "stat",
- filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "fcntl",
- filename);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_file_close (fd));
+ GNUNET_DISK_file_unlock (fd,
+ 0,
+ sizeof (
+ struct GNUNET_CRYPTO_EcdsaPrivateKey)))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
return NULL;
}
if (GNUNET_OK !=
- GNUNET_DISK_file_size (filename,
- &fs,
- GNUNET_YES,
- GNUNET_YES))
+ GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
fs = 0;
if (fs < sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))
{
/* maybe we got the read lock before the key generating
* process had a chance to get the write lock; give it up! */
if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "fcntl",
- filename);
+ GNUNET_DISK_file_unlock (fd,
+ 0,
+ sizeof (
+ struct GNUNET_CRYPTO_EcdsaPrivateKey)))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
if (0 == ++cnt % 10)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
- filename, (unsigned int) fs,
+ _ (
+ "When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
+ filename,
+ (unsigned int) fs,
(unsigned int) sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("This may be ok if someone is currently generating a key.\n"));
+ _ ("This may be ok if someone is currently generating a key.\n"));
}
- short_wait (); /* wait a bit longer! */
+ short_wait (); /* wait a bit longer! */
continue;
}
break;
}
fs = sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
priv = GNUNET_malloc (fs);
- sret = GNUNET_DISK_file_read (fd,
- priv,
- fs);
- GNUNET_assert ( (sret >= 0) &&
- (fs == (size_t) sret) );
+ sret = GNUNET_DISK_file_read (fd, priv, fs);
+ GNUNET_assert ((sret >= 0) && (fs == (size_t) sret));
if (GNUNET_YES !=
- GNUNET_DISK_file_unlock (fd, 0,
+ GNUNET_DISK_file_unlock (fd,
+ 0,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "fcntl",
- filename);
- GNUNET_assert (GNUNET_YES ==
- GNUNET_DISK_file_close (fd));
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
+ GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
return priv;
}
@@ -434,7 +434,8 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
* permission denied)
*/
struct GNUNET_CRYPTO_EddsaPrivateKey *
-GNUNET_CRYPTO_eddsa_key_create_from_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
+GNUNET_CRYPTO_eddsa_key_create_from_configuration (
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
char *fn;
@@ -465,7 +466,7 @@ GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg,
if (NULL == (priv = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not load peer's private key\n"));
+ _ ("Could not load peer's private key\n"));
return GNUNET_SYSERR;
}
GNUNET_CRYPTO_eddsa_key_get_public (priv, &dst->public_key);
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index 71eaab87a..58cab082e 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -80,7 +80,7 @@ glibc_weak_rand32 ()
static double
get_weak_random ()
{
- return ((double) RANDOM () / RAND_MAX);
+ return ((double) random () / RAND_MAX);
}
@@ -93,7 +93,7 @@ get_weak_random ()
void
GNUNET_CRYPTO_seed_weak_random (int32_t seed)
{
- SRANDOM (seed);
+ srandom (seed);
}
@@ -324,7 +324,7 @@ void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init ()
if (! gcry_check_version (NEED_LIBGCRYPT_VERSION))
{
- FPRINTF (
+ fprintf (
stderr,
_ ("libgcrypt has not the expected version (version %s is required).\n"),
NEED_LIBGCRYPT_VERSION);
@@ -334,14 +334,14 @@ void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init ()
gcry_set_allocation_handler (&w_malloc, &w_malloc, &w_check, &realloc, &free);
/* Disable use of secure memory */
if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0)))
- FPRINTF (stderr,
+ fprintf (stderr,
"Failed to set libgcrypt option %s: %s\n",
"DISABLE_SECMEM",
gcry_strerror (rc));
/* Otherwise gnunet-ecc takes forever to complete, besides
we are fine with "just" using GCRY_STRONG_RANDOM */
if ((rc = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0)))
- FPRINTF (stderr,
+ fprintf (stderr,
"Failed to set libgcrypt option %s: %s\n",
"ENABLE_QUICK_RANDOM",
gcry_strerror (rc));
diff --git a/src/util/disk.c b/src/util/disk.c
index f395a375e..c1f24e4c8 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -28,11 +28,13 @@
#include "gnunet_strings_lib.h"
#include "gnunet_disk_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util-disk", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-disk", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-disk", syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-disk", syscall)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-disk", syscall, filename)
+#define LOG_STRERROR_FILE(kind, syscall, filename) \
+ GNUNET_log_from_strerror_file (kind, "util-disk", syscall, filename)
/**
* Block size for IO for copying files.
@@ -54,9 +56,9 @@
#endif
#ifndef S_ISLNK
-#define _IFMT 0170000 /* type of file */
-#define _IFLNK 0120000 /* symbolic link */
-#define S_ISLNK(m) (((m)&_IFMT) == _IFLNK)
+#define _IFMT 0170000 /* type of file */
+#define _IFLNK 0120000 /* symbolic link */
+#define S_ISLNK(m) (((m) &_IFMT) == _IFLNK)
#endif
@@ -147,7 +149,8 @@ getSizeRec (void *cls, const char *fn)
{
struct GetFileSizeData *gfsd = cls;
-#if defined (HAVE_STAT64) && !(defined (_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64)
+#if defined(HAVE_STAT64) && \
+ ! (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64)
STRUCT_STAT64 buf;
if (0 != STAT64 (fn, &buf))
@@ -158,7 +161,7 @@ getSizeRec (void *cls, const char *fn)
#else
struct stat buf;
- if (0 != STAT (fn, &buf))
+ if (0 != stat (fn, &buf))
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_DEBUG, "stat", fn);
return GNUNET_SYSERR;
@@ -169,10 +172,10 @@ getSizeRec (void *cls, const char *fn)
errno = EISDIR;
return GNUNET_SYSERR;
}
- if ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))
+ if ((! S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))
gfsd->total += buf.st_size;
- if ((S_ISDIR (buf.st_mode)) && (0 == ACCESS (fn, X_OK)) &&
- ((!S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)))
+ if ((S_ISDIR (buf.st_mode)) && (0 == access (fn, X_OK)) &&
+ ((! S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES)))
{
if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd))
return GNUNET_SYSERR;
@@ -191,9 +194,9 @@ int
GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h)
{
#ifdef MINGW
- return ((!h) || (h->h == INVALID_HANDLE_VALUE)) ? GNUNET_YES : GNUNET_NO;
+ return ((! h) || (h->h == INVALID_HANDLE_VALUE)) ? GNUNET_YES : GNUNET_NO;
#else
- return ((!h) || (h->fd == -1)) ? GNUNET_YES : GNUNET_NO;
+ return ((! h) || (h->fd == -1)) ? GNUNET_YES : GNUNET_NO;
#endif
}
@@ -205,14 +208,13 @@ GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h)
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
- off_t *size)
+GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, off_t *size)
{
#if WINDOWS
BOOL b;
LARGE_INTEGER li;
b = GetFileSizeEx (fh->h, &li);
- if (!b)
+ if (! b)
{
SetErrnoFromWinError (GetLastError ());
return GNUNET_SYSERR;
@@ -221,7 +223,7 @@ GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
#else
struct stat sbuf;
- if (0 != FSTAT (fh->fd, &sbuf))
+ if (0 != fstat (fh->fd, &sbuf))
return GNUNET_SYSERR;
*size = sbuf.st_size;
#endif
@@ -239,7 +241,7 @@ GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
*/
off_t
GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h,
- off_t offset,
+ off_t offset,
enum GNUNET_DISK_Seek whence)
{
if (h == NULL)
@@ -253,7 +255,7 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h,
LARGE_INTEGER new_pos;
BOOL b;
- static DWORD t[] = { FILE_BEGIN, FILE_CURRENT, FILE_END };
+ static DWORD t[] = {FILE_BEGIN, FILE_CURRENT, FILE_END};
li.QuadPart = offset;
b = SetFilePointerEx (h->h, li, &new_pos, t[whence]);
@@ -264,7 +266,7 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h,
}
return (off_t) new_pos.QuadPart;
#else
- static int t[] = { SEEK_SET, SEEK_CUR, SEEK_END };
+ static int t[] = {SEEK_SET, SEEK_CUR, SEEK_END};
return lseek (h->fd, offset, t[whence]);
#endif
@@ -287,9 +289,9 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h,
*/
int
GNUNET_DISK_file_size (const char *filename,
- uint64_t * size,
+ uint64_t *size,
int include_symbolic_links,
- int single_file_mode)
+ int single_file_mode)
{
struct GetFileSizeData gfsd;
int ret;
@@ -320,8 +322,9 @@ GNUNET_DISK_file_size (const char *filename,
* @return #GNUNET_OK on success
*/
int
-GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev,
- uint64_t * ino)
+GNUNET_DISK_file_get_identifiers (const char *filename,
+ uint64_t *dev,
+ uint64_t *ino)
{
#if WINDOWS
{
@@ -337,12 +340,13 @@ GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev,
return GNUNET_SYSERR;
succ = GetFileInformationByHandle (fh->h, &info);
GNUNET_DISK_file_close (fh);
- if (!succ)
+ if (! succ)
{
return GNUNET_SYSERR;
}
*dev = info.dwVolumeSerialNumber;
- *ino = ((((uint64_t) info.nFileIndexHigh) << (sizeof (DWORD) * 8)) | info.nFileIndexLow);
+ *ino = ((((uint64_t) info.nFileIndexHigh) << (sizeof (DWORD) * 8)) |
+ info.nFileIndexLow);
}
#else /* !WINDOWS */
#if HAVE_STAT
@@ -376,8 +380,8 @@ GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev,
{
return GNUNET_SYSERR;
}
- *dev = ((uint64_t) fbuf.f_fsid.val[0]) << 32 ||
- ((uint64_t) fbuf.f_fsid.val[1]);
+ *dev =
+ ((uint64_t) fbuf.f_fsid.val[0]) << 32 || ((uint64_t) fbuf.f_fsid.val[1]);
}
#else
*dev = 0;
@@ -402,9 +406,9 @@ mktemp_name (const char *t)
if ((t[0] != '/') && (t[0] != '\\')
#if WINDOWS
- && !(isalpha ((int) t[0]) && (t[0] != '\0') && (t[1] == ':'))
+ && ! (isalpha ((int) t[0]) && (t[0] != '\0') && (t[1] == ':'))
#endif
- )
+ )
{
/* FIXME: This uses system codepage on W32, not UTF-8 */
tmpdir = getenv ("TMPDIR");
@@ -506,11 +510,10 @@ GNUNET_DISK_fix_permissions (const char *fn,
else if (GNUNET_YES == require_gid_match)
mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP;
else
- mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH;
+ mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH |
+ S_IWOTH | S_IXOTH;
if (0 != chmod (fn, mode))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "chmod",
- fn);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "chmod", fn);
}
#endif
@@ -565,15 +568,10 @@ GNUNET_DISK_file_backup (const char *fil)
num = 0;
do
{
- GNUNET_snprintf (target, slen,
- "%s.%u~",
- fil,
- num++);
+ GNUNET_snprintf (target, slen, "%s.%u~", fil, num++);
} while (0 == access (target, F_OK));
if (0 != rename (fil, target))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "rename",
- fil);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "rename", fil);
GNUNET_free (target);
}
@@ -606,7 +604,7 @@ GNUNET_DISK_mktemp (const char *t)
return NULL;
}
umask (omask);
- if (0 != CLOSE (fd))
+ if (0 != close (fd))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "close", fn);
return fn;
}
@@ -625,29 +623,29 @@ GNUNET_DISK_mktemp (const char *t)
* does not exist or stat'ed
*/
int
-GNUNET_DISK_directory_test (const char *fil,
- int is_readable)
+GNUNET_DISK_directory_test (const char *fil, int is_readable)
{
struct stat filestat;
int ret;
- ret = STAT (fil, &filestat);
+ ret = stat (fil, &filestat);
if (ret != 0)
{
if (errno != ENOENT)
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", fil);
return GNUNET_SYSERR;
}
- if (!S_ISDIR (filestat.st_mode))
+ if (! S_ISDIR (filestat.st_mode))
{
LOG (GNUNET_ERROR_TYPE_INFO,
- "A file already exits with the same name %s\n", fil);
+ "A file already exits with the same name %s\n",
+ fil);
return GNUNET_NO;
}
if (GNUNET_YES == is_readable)
- ret = ACCESS (fil, R_OK | X_OK);
+ ret = access (fil, R_OK | X_OK);
else
- ret = ACCESS (fil, X_OK);
+ ret = access (fil, X_OK);
if (ret < 0)
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", fil);
@@ -676,7 +674,7 @@ GNUNET_DISK_file_test (const char *fil)
if (rdir == NULL)
return GNUNET_SYSERR;
- ret = STAT (rdir, &filestat);
+ ret = stat (rdir, &filestat);
if (ret != 0)
{
if (errno != ENOENT)
@@ -688,12 +686,12 @@ GNUNET_DISK_file_test (const char *fil)
GNUNET_free (rdir);
return GNUNET_NO;
}
- if (!S_ISREG (filestat.st_mode))
+ if (! S_ISREG (filestat.st_mode))
{
GNUNET_free (rdir);
return GNUNET_NO;
}
- if (ACCESS (rdir, F_OK) < 0)
+ if (access (rdir, F_OK) < 0)
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", rdir);
GNUNET_free (rdir);
@@ -728,7 +726,7 @@ GNUNET_DISK_directory_create (const char *dir)
len = strlen (rdir);
#ifndef MINGW
- pos = 1; /* skip heading '/' */
+ pos = 1; /* skip heading '/' */
#else
/* Local or Network path? */
if (strncmp (rdir, "\\\\", 2) == 0)
@@ -746,7 +744,7 @@ GNUNET_DISK_directory_create (const char *dir)
}
else
{
- pos = 3; /* strlen("C:\\") */
+ pos = 3; /* strlen("C:\\") */
}
#endif
/* Check which low level directories already exist */
@@ -796,11 +794,13 @@ GNUNET_DISK_directory_create (const char *dir)
if (GNUNET_SYSERR == ret)
{
#ifndef MINGW
- ret = mkdir (rdir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); /* 755 */
+ ret = mkdir (rdir,
+ S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH |
+ S_IXOTH); /* 755 */
#else
wchar_t wrdir[MAX_PATH + 1];
- if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv(rdir, wrdir))
- ret = !CreateDirectoryW (wrdir, NULL);
+ if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv (rdir, wrdir))
+ ret = ! CreateDirectoryW (wrdir, NULL);
else
ret = 1;
#endif
@@ -843,7 +843,7 @@ GNUNET_DISK_directory_create_for_file (const char *filename)
errno = EINVAL;
return GNUNET_SYSERR;
}
- if (0 == ACCESS (rdir, W_OK))
+ if (0 == access (rdir, W_OK))
{
GNUNET_free (rdir);
return GNUNET_OK;
@@ -860,7 +860,7 @@ GNUNET_DISK_directory_create_for_file (const char *filename)
rdir = GNUNET_strdup ("/");
}
ret = GNUNET_DISK_directory_create (rdir);
- if ((GNUNET_OK == ret) && (0 != ACCESS (rdir, W_OK)))
+ if ((GNUNET_OK == ret) && (0 != access (rdir, W_OK)))
ret = GNUNET_NO;
eno = errno;
GNUNET_free (rdir);
@@ -893,7 +893,7 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE)
{
- if (!ReadFile (h->h, result, len, &bytes_read, NULL))
+ if (! ReadFile (h->h, result, len, &bytes_read, NULL))
{
SetErrnoFromWinError (GetLastError ());
return GNUNET_SYSERR;
@@ -901,7 +901,7 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
}
else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
{
- if (!ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead))
+ if (! ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead))
{
if (GetLastError () != ERROR_IO_PENDING)
{
@@ -939,8 +939,8 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h,
*/
ssize_t
GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
- void *result,
- size_t len)
+ void *result,
+ size_t len)
{
if (NULL == h)
{
@@ -953,7 +953,7 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE)
{
- if (!ReadFile (h->h, result, len, &bytes_read, NULL))
+ if (! ReadFile (h->h, result, len, &bytes_read, NULL))
{
SetErrnoFromWinError (GetLastError ());
return GNUNET_SYSERR;
@@ -961,26 +961,25 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
}
else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
{
- if (!ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead))
+ if (! ReadFile (h->h, result, len, &bytes_read, h->oOverlapRead))
{
if (GetLastError () != ERROR_IO_PENDING)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Error reading from pipe: %u\n", GetLastError ());
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Error reading from pipe: %u\n",
+ GetLastError ());
SetErrnoFromWinError (GetLastError ());
return GNUNET_SYSERR;
}
else
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "ReadFile() queued a read, cancelling\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "ReadFile() queued a read, cancelling\n");
CancelIo (h->h);
errno = EAGAIN;
return GNUNET_SYSERR;
}
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Read %u bytes\n",
- bytes_read);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytes_read);
}
else
{
@@ -997,11 +996,11 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
(void) fcntl (h->fd, F_SETFL, flags | O_NONBLOCK);
ret = read (h->fd, result, len);
if (0 == (flags & O_NONBLOCK))
- {
- int eno = errno;
- (void) fcntl (h->fd, F_SETFL, flags);
- errno = eno;
- }
+ {
+ int eno = errno;
+ (void) fcntl (h->fd, F_SETFL, flags);
+ errno = eno;
+ }
return ret;
#endif
}
@@ -1016,17 +1015,13 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h,
* @return number of bytes read, #GNUNET_SYSERR on failure
*/
ssize_t
-GNUNET_DISK_fn_read (const char *fn,
- void *result,
- size_t len)
+GNUNET_DISK_fn_read (const char *fn, void *result, size_t len)
{
struct GNUNET_DISK_FileHandle *fh;
ssize_t ret;
int eno;
- fh = GNUNET_DISK_file_open (fn,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
if (NULL == fh)
return GNUNET_SYSERR;
ret = GNUNET_DISK_file_read (fh, result, len);
@@ -1046,9 +1041,9 @@ GNUNET_DISK_fn_read (const char *fn,
* @return number of bytes written on success, #GNUNET_SYSERR on error
*/
ssize_t
-GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
+GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
const void *buffer,
- size_t n)
+ size_t n)
{
if (NULL == h)
{
@@ -1061,7 +1056,7 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
if (h->type == GNUNET_DISK_HANLDE_TYPE_FILE)
{
- if (!WriteFile (h->h, buffer, n, &bytes_written, NULL))
+ if (! WriteFile (h->h, buffer, n, &bytes_written, NULL))
{
SetErrnoFromWinError (GetLastError ());
return GNUNET_SYSERR;
@@ -1070,46 +1065,50 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
else if (h->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "It is a pipe trying to write %u bytes\n", n);
- if (!WriteFile (h->h, buffer, n, &bytes_written, h->oOverlapWrite))
+ if (! WriteFile (h->h, buffer, n, &bytes_written, h->oOverlapWrite))
{
if (GetLastError () != ERROR_IO_PENDING)
{
SetErrnoFromWinError (GetLastError ());
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n",
- GetLastError ());
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Error writing to pipe: %u\n",
+ GetLastError ());
return GNUNET_SYSERR;
}
LOG (GNUNET_ERROR_TYPE_DEBUG, "Will get overlapped result\n");
- if (!GetOverlappedResult (h->h, h->oOverlapWrite, &bytes_written, TRUE))
+ if (! GetOverlappedResult (h->h, h->oOverlapWrite, &bytes_written, TRUE))
{
SetErrnoFromWinError (GetLastError ());
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Error getting overlapped result while writing to pipe: %u\n",
- GetLastError ());
+ "Error getting overlapped result while writing to pipe: %u\n",
+ GetLastError ());
return GNUNET_SYSERR;
}
}
else
{
DWORD ovr;
- if (!GetOverlappedResult (h->h, h->oOverlapWrite, &ovr, TRUE))
+ if (! GetOverlappedResult (h->h, h->oOverlapWrite, &ovr, TRUE))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Error getting control overlapped result while writing to pipe: %u\n",
- GetLastError ());
+ "Error getting control overlapped result while writing to pipe: %u\n",
+ GetLastError ());
}
else
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Wrote %u bytes (ovr says %u), picking the greatest\n",
- bytes_written, ovr);
+ "Wrote %u bytes (ovr says %u), picking the greatest\n",
+ bytes_written,
+ ovr);
}
}
if (bytes_written == 0)
{
if (n > 0)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes, returning -1 with EAGAIN\n", bytes_written);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Wrote %u bytes, returning -1 with EAGAIN\n",
+ bytes_written);
errno = EAGAIN;
return GNUNET_SYSERR;
}
@@ -1136,7 +1135,7 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
* @return number of bytes written on success, #GNUNET_SYSERR on error
*/
ssize_t
-GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h,
+GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h,
const void *buffer,
size_t n)
{
@@ -1150,28 +1149,28 @@ GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h,
DWORD bytes_written;
/* We do a non-overlapped write, which is as blocking as it gets */
LOG (GNUNET_ERROR_TYPE_DEBUG, "Writing %u bytes\n", n);
- if (!WriteFile (h->h, buffer, n, &bytes_written, NULL))
+ if (! WriteFile (h->h, buffer, n, &bytes_written, NULL))
{
SetErrnoFromWinError (GetLastError ());
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n",
- GetLastError ());
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Error writing to pipe: %u\n",
+ GetLastError ());
return GNUNET_SYSERR;
}
if (bytes_written == 0 && n > 0)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "Waiting for pipe to clean\n");
WaitForSingleObject (h->h, INFINITE);
- if (!WriteFile (h->h, buffer, n, &bytes_written, NULL))
+ if (! WriteFile (h->h, buffer, n, &bytes_written, NULL))
{
SetErrnoFromWinError (GetLastError ());
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Error writing to pipe: %u\n",
- GetLastError ());
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Error writing to pipe: %u\n",
+ GetLastError ());
return GNUNET_SYSERR;
}
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Wrote %u bytes\n",
- bytes_written);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Wrote %u bytes\n", bytes_written);
return bytes_written;
#else
int flags;
@@ -1208,9 +1207,11 @@ GNUNET_DISK_fn_write (const char *fn,
struct GNUNET_DISK_FileHandle *fh;
ssize_t ret;
- fh = GNUNET_DISK_file_open (fn,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE
- | GNUNET_DISK_OPEN_CREATE, mode);
+ fh =
+ GNUNET_DISK_file_open (fn,
+ GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE |
+ GNUNET_DISK_OPEN_CREATE,
+ mode);
if (! fh)
return GNUNET_SYSERR;
ret = GNUNET_DISK_file_write (fh, buffer, n);
@@ -1248,45 +1249,39 @@ GNUNET_DISK_directory_scan (const char *dir_name,
dname = GNUNET_STRINGS_filename_expand (dir_name);
if (NULL == dname)
return GNUNET_SYSERR;
- while ( (strlen (dname) > 0) &&
- (dname[strlen (dname) - 1] == DIR_SEPARATOR) )
+ while ((strlen (dname) > 0) && (dname[strlen (dname) - 1] == DIR_SEPARATOR))
dname[strlen (dname) - 1] = '\0';
- if (0 != STAT (dname, &istat))
+ if (0 != stat (dname, &istat))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "stat",
- dname);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", dname);
GNUNET_free (dname);
return GNUNET_SYSERR;
}
if (! S_ISDIR (istat.st_mode))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Expected `%s' to be a directory!\n"),
+ _ ("Expected `%s' to be a directory!\n"),
dir_name);
GNUNET_free (dname);
return GNUNET_SYSERR;
}
errno = 0;
- dinfo = OPENDIR (dname);
- if ( (EACCES == errno) ||
- (NULL == dinfo) )
+ dinfo = opendir (dname);
+ if ((EACCES == errno) || (NULL == dinfo))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "opendir",
- dname);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "opendir", dname);
if (NULL != dinfo)
- CLOSEDIR (dinfo);
+ closedir (dinfo);
GNUNET_free (dname);
return GNUNET_SYSERR;
}
name_len = 256;
n_size = strlen (dname) + name_len + strlen (DIR_SEPARATOR_STR) + 1;
name = GNUNET_malloc (n_size);
- while (NULL != (finfo = READDIR (dinfo)))
+ while (NULL != (finfo = readdir (dinfo)))
{
- if ( (0 == strcmp (finfo->d_name, ".")) ||
- (0 == strcmp (finfo->d_name, "..")) )
+ if ((0 == strcmp (finfo->d_name, ".")) ||
+ (0 == strcmp (finfo->d_name, "..")))
continue;
if (NULL != callback)
{
@@ -1304,16 +1299,14 @@ GNUNET_DISK_directory_scan (const char *dir_name,
n_size,
"%s%s%s",
dname,
- (0 == strcmp (dname,
- DIR_SEPARATOR_STR))
- ? ""
- : DIR_SEPARATOR_STR,
+ (0 == strcmp (dname, DIR_SEPARATOR_STR))
+ ? ""
+ : DIR_SEPARATOR_STR,
finfo->d_name);
- ret = callback (callback_cls,
- name);
+ ret = callback (callback_cls, name);
if (GNUNET_OK != ret)
{
- CLOSEDIR (dinfo);
+ closedir (dinfo);
GNUNET_free (name);
GNUNET_free (dname);
if (GNUNET_NO == ret)
@@ -1323,7 +1316,7 @@ GNUNET_DISK_directory_scan (const char *dir_name,
}
count++;
}
- CLOSEDIR (dinfo);
+ closedir (dinfo);
GNUNET_free (name);
GNUNET_free (dname);
return count;
@@ -1339,8 +1332,7 @@ GNUNET_DISK_directory_scan (const char *dir_name,
* @return #GNUNET_OK
*/
static int
-remove_helper (void *unused,
- const char *fn)
+remove_helper (void *unused, const char *fn)
{
(void) unused;
(void) GNUNET_DISK_directory_remove (fn);
@@ -1365,35 +1357,26 @@ GNUNET_DISK_directory_remove (const char *filename)
GNUNET_break (0);
return GNUNET_SYSERR;
}
- if (0 != LSTAT (filename, &istat))
- return GNUNET_NO; /* file may not exist... */
- (void) CHMOD (filename,
- S_IWUSR | S_IRUSR | S_IXUSR);
- if (0 == UNLINK (filename))
+ if (0 != lstat (filename, &istat))
+ return GNUNET_NO; /* file may not exist... */
+ (void) chmod (filename, S_IWUSR | S_IRUSR | S_IXUSR);
+ if (0 == unlink (filename))
return GNUNET_OK;
- if ( (errno != EISDIR) &&
- /* EISDIR is not sufficient in all cases, e.g.
+ if ((errno != EISDIR) &&
+ /* EISDIR is not sufficient in all cases, e.g.
* sticky /tmp directory may result in EPERM on BSD.
* So we also explicitly check "isDirectory" */
- (GNUNET_YES !=
- GNUNET_DISK_directory_test (filename,
- GNUNET_YES)) )
+ (GNUNET_YES != GNUNET_DISK_directory_test (filename, GNUNET_YES)))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "rmdir",
- filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", filename);
return GNUNET_SYSERR;
}
if (GNUNET_SYSERR ==
- GNUNET_DISK_directory_scan (filename,
- &remove_helper,
- NULL))
+ GNUNET_DISK_directory_scan (filename, &remove_helper, NULL))
return GNUNET_SYSERR;
- if (0 != RMDIR (filename))
+ if (0 != rmdir (filename))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "rmdir",
- filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", filename);
return GNUNET_SYSERR;
}
return GNUNET_OK;
@@ -1408,8 +1391,7 @@ GNUNET_DISK_directory_remove (const char *filename)
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_DISK_file_copy (const char *src,
- const char *dst)
+GNUNET_DISK_file_copy (const char *src, const char *dst)
{
char *buf;
uint64_t pos;
@@ -1419,41 +1401,30 @@ GNUNET_DISK_file_copy (const char *src,
struct GNUNET_DISK_FileHandle *in;
struct GNUNET_DISK_FileHandle *out;
- if (GNUNET_OK !=
- GNUNET_DISK_file_size (src,
- &size,
- GNUNET_YES,
- GNUNET_YES))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "stat",
- src);
+ if (GNUNET_OK != GNUNET_DISK_file_size (src, &size, GNUNET_YES, GNUNET_YES))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "stat", src);
return GNUNET_SYSERR;
}
pos = 0;
- in = GNUNET_DISK_file_open (src,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ in =
+ GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE);
if (! in)
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "open",
- src);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", src);
return GNUNET_SYSERR;
}
out =
- GNUNET_DISK_file_open (dst,
- GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
+ GNUNET_DISK_file_open (dst,
+ GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
GNUNET_DISK_OPEN_FAILIFEXISTS,
- GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE |
GNUNET_DISK_PERM_GROUP_READ |
GNUNET_DISK_PERM_GROUP_WRITE);
- if (!out)
+ if (! out)
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "open",
- dst);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", dst);
GNUNET_DISK_file_close (in);
return GNUNET_SYSERR;
}
@@ -1463,17 +1434,11 @@ GNUNET_DISK_file_copy (const char *src,
len = COPY_BLK_SIZE;
if (len > size - pos)
len = size - pos;
- sret = GNUNET_DISK_file_read (in,
- buf,
- len);
- if ( (sret < 0) ||
- (len != (size_t) sret) )
+ sret = GNUNET_DISK_file_read (in, buf, len);
+ if ((sret < 0) || (len != (size_t) sret))
goto FAIL;
- sret = GNUNET_DISK_file_write (out,
- buf,
- len);
- if ( (sret < 0) ||
- (len != (size_t) sret) )
+ sret = GNUNET_DISK_file_write (out, buf, len);
+ if ((sret < 0) || (len != (size_t) sret))
goto FAIL;
pos += len;
}
@@ -1503,8 +1468,7 @@ GNUNET_DISK_filename_canonicalize (char *fn)
{
c = *idx;
- if (c == '/' || c == '\\' || c == ':' ||
- c == '*' || c == '?' || c == '"' ||
+ if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || c == '"' ||
c == '<' || c == '>' || c == '|')
{
*idx = '_';
@@ -1513,7 +1477,6 @@ GNUNET_DISK_filename_canonicalize (char *fn)
}
-
/**
* @brief Change owner of a file
*
@@ -1522,8 +1485,7 @@ GNUNET_DISK_filename_canonicalize (char *fn)
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
int
-GNUNET_DISK_file_change_owner (const char *filename,
- const char *user)
+GNUNET_DISK_file_change_owner (const char *filename, const char *user)
{
#ifndef MINGW
struct passwd *pws;
@@ -1532,18 +1494,14 @@ GNUNET_DISK_file_change_owner (const char *filename,
if (NULL == pws)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Cannot obtain information about user `%s': %s\n"),
+ _ ("Cannot obtain information about user `%s': %s\n"),
user,
- STRERROR (errno));
+ strerror (errno));
return GNUNET_SYSERR;
}
- if (0 != chown (filename,
- pws->pw_uid,
- pws->pw_gid))
+ if (0 != chown (filename, pws->pw_uid, pws->pw_gid))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "chown",
- filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "chown", filename);
return GNUNET_SYSERR;
}
#endif
@@ -1590,12 +1548,18 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh,
diff_high = (DWORD) ((diff >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
memset (&o, 0, sizeof (OVERLAPPED));
- o.Offset = (DWORD) (lock_start & 0xFFFFFFFF);;
- o.OffsetHigh = (DWORD) (((lock_start & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
-
- if (!LockFileEx
- (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) | LOCKFILE_FAIL_IMMEDIATELY,
- 0, diff_low, diff_high, &o))
+ o.Offset = (DWORD) (lock_start & 0xFFFFFFFF);
+ ;
+ o.OffsetHigh =
+ (DWORD) (((lock_start & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
+
+ if (! LockFileEx (fh->h,
+ (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) |
+ LOCKFILE_FAIL_IMMEDIATELY,
+ 0,
+ diff_low,
+ diff_high,
+ &o))
{
SetErrnoFromWinError (GetLastError ());
return GNUNET_SYSERR;
@@ -1643,10 +1607,12 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh,
diff_high = (DWORD) ((diff >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
memset (&o, 0, sizeof (OVERLAPPED));
- o.Offset = (DWORD) (unlock_start & 0xFFFFFFFF);;
- o.OffsetHigh = (DWORD) (((unlock_start & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
+ o.Offset = (DWORD) (unlock_start & 0xFFFFFFFF);
+ ;
+ o.OffsetHigh = (DWORD) (
+ ((unlock_start & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF);
- if (!UnlockFileEx (fh->h, 0, diff_low, diff_high, &o))
+ if (! UnlockFileEx (fh->h, 0, diff_low, diff_high, &o))
{
SetErrnoFromWinError (GetLastError ());
return GNUNET_SYSERR;
@@ -1694,7 +1660,7 @@ GNUNET_DISK_file_open (const char *fn,
#ifndef MINGW
mode = 0;
if (GNUNET_DISK_OPEN_READWRITE == (flags & GNUNET_DISK_OPEN_READWRITE))
- oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */
+ oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */
else if (flags & GNUNET_DISK_OPEN_READ)
oflags = O_RDONLY;
else if (flags & GNUNET_DISK_OPEN_WRITE)
@@ -1706,26 +1672,28 @@ GNUNET_DISK_file_open (const char *fn,
return NULL;
}
if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)
- oflags |= (O_CREAT | O_EXCL);
+ oflags |= (O_CREAT | O_EXCL);
if (flags & GNUNET_DISK_OPEN_TRUNCATE)
oflags |= O_TRUNC;
if (flags & GNUNET_DISK_OPEN_APPEND)
oflags |= O_APPEND;
- if(GNUNET_NO == GNUNET_DISK_file_test(fn))
- {
- if (flags & GNUNET_DISK_OPEN_CREATE )
- {
- (void) GNUNET_DISK_directory_create_for_file (expfn);
- oflags |= O_CREAT;
- mode = translate_unix_perms (perm);
- }
+ if (GNUNET_NO == GNUNET_DISK_file_test (fn))
+ {
+ if (flags & GNUNET_DISK_OPEN_CREATE)
+ {
+ (void) GNUNET_DISK_directory_create_for_file (expfn);
+ oflags |= O_CREAT;
+ mode = translate_unix_perms (perm);
+ }
}
- fd = open (expfn, oflags
+ fd = open (expfn,
+ oflags
#if O_CLOEXEC
- | O_CLOEXEC
+ | O_CLOEXEC
#endif
- | O_LARGEFILE, mode);
+ | O_LARGEFILE,
+ mode);
if (fd == -1)
{
if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS))
@@ -1767,10 +1735,14 @@ GNUNET_DISK_file_open (const char *fn,
disp = OPEN_EXISTING;
}
- if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv(expfn, wexpfn))
- h = CreateFileW (wexpfn, access,
- FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
- disp, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv (expfn, wexpfn))
+ h = CreateFileW (wexpfn,
+ access,
+ FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ disp,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
else
h = INVALID_HANDLE_VALUE;
if (h == INVALID_HANDLE_VALUE)
@@ -1844,7 +1816,7 @@ GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h)
}
if (h->oOverlapWrite)
{
- if (!CloseHandle (h->oOverlapWrite->hEvent))
+ if (! CloseHandle (h->oOverlapWrite->hEvent))
{
SetErrnoFromWinError (GetLastError ());
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close");
@@ -1888,8 +1860,8 @@ GNUNET_DISK_get_handle_from_w32_handle (HANDLE osfh)
ftype = GNUNET_DISK_HANLDE_TYPE_PIPE;
break;
case FILE_TYPE_UNKNOWN:
- if ( (GetLastError () == NO_ERROR) ||
- (GetLastError () == ERROR_INVALID_HANDLE) )
+ if ((GetLastError () == NO_ERROR) ||
+ (GetLastError () == ERROR_INVALID_HANDLE))
{
if (0 != ResetEvent (osfh))
ftype = GNUNET_DISK_HANLDE_TYPE_EVENT;
@@ -1938,8 +1910,7 @@ GNUNET_DISK_get_handle_from_int_fd (int fno)
{
struct GNUNET_DISK_FileHandle *fh;
- if ( (((off_t) -1) == lseek (fno, 0, SEEK_CUR)) &&
- (EBADF == errno) )
+ if ((((off_t) -1) == lseek (fno, 0, SEEK_CUR)) && (EBADF == errno))
return NULL; /* invalid FD */
#ifndef WINDOWS
@@ -2019,7 +1990,8 @@ struct GNUNET_DISK_MapHandle
void *
GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
struct GNUNET_DISK_MapHandle **m,
- enum GNUNET_DISK_MapType access, size_t len)
+ enum GNUNET_DISK_MapType access,
+ size_t len)
{
if (NULL == h)
{
@@ -2062,7 +2034,7 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
}
(*m)->addr = MapViewOfFile ((*m)->h, mapAccess, 0, 0, len);
- if (!(*m)->addr)
+ if (! (*m)->addr)
{
SetErrnoFromWinError (GetLastError ());
CloseHandle ((*m)->h);
@@ -2111,7 +2083,7 @@ GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h)
ret = UnmapViewOfFile (h->addr) ? GNUNET_OK : GNUNET_SYSERR;
if (ret != GNUNET_OK)
SetErrnoFromWinError (GetLastError ());
- if (!CloseHandle (h->h) && (ret == GNUNET_OK))
+ if (! CloseHandle (h->h) && (ret == GNUNET_OK))
{
ret = GNUNET_SYSERR;
SetErrnoFromWinError (GetLastError ());
@@ -2155,7 +2127,7 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
#if WINDOWS
#ifndef PIPE_BUF
-#define PIPE_BUF 512
+#define PIPE_BUF 512
#endif
/* Copyright Bob Byrnes <byrnes <at> curl.com>
http://permalink.gmane.org/gmane.os.cygwin.patches/2121
@@ -2168,9 +2140,12 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
Note that the return value is either NO_ERROR or GetLastError,
unlike CreatePipe, which returns a bool for success or failure. */
static int
-create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
- LPSECURITY_ATTRIBUTES sa_ptr, DWORD psize,
- DWORD dwReadMode, DWORD dwWriteMode)
+create_selectable_pipe (PHANDLE read_pipe_ptr,
+ PHANDLE write_pipe_ptr,
+ LPSECURITY_ATTRIBUTES sa_ptr,
+ DWORD psize,
+ DWORD dwReadMode,
+ DWORD dwWriteMode)
{
/* Default to error. */
*read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE;
@@ -2191,10 +2166,15 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
{
static volatile LONG pipe_unique_id;
- snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld",
- getpid (), InterlockedIncrement ((LONG *) & pipe_unique_id));
- LOG (GNUNET_ERROR_TYPE_DEBUG, "CreateNamedPipe: name = %s, size = %lu\n",
- pipename, psize);
+ snprintf (pipename,
+ sizeof pipename,
+ "\\\\.\\pipe\\gnunet-%d-%ld",
+ getpid (),
+ InterlockedIncrement ((LONG *) &pipe_unique_id));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "CreateNamedPipe: name = %s, size = %lu\n",
+ pipename,
+ psize);
/* Use CreateNamedPipe instead of CreatePipe, because the latter
* returns a write handle that does not permit FILE_READ_ATTRIBUTES
* access, on versions of win32 earlier than WinXP SP2.
@@ -2203,10 +2183,15 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
* It's important to only allow a single instance, to ensure that
* the pipe was not created earlier by some other process, even if
* the pid has been reused. */
- read_pipe = CreateNamedPipeA (pipename, PIPE_ACCESS_INBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE | dwReadMode, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, /* max instances */
- psize, /* output buffer size */
- psize, /* input buffer size */
- NMPWAIT_USE_DEFAULT_WAIT, sa_ptr);
+ read_pipe = CreateNamedPipeA (pipename,
+ PIPE_ACCESS_INBOUND |
+ FILE_FLAG_FIRST_PIPE_INSTANCE | dwReadMode,
+ PIPE_TYPE_BYTE | PIPE_READMODE_BYTE,
+ 1, /* max instances */
+ psize, /* output buffer size */
+ psize, /* input buffer size */
+ NMPWAIT_USE_DEFAULT_WAIT,
+ sa_ptr);
if (read_pipe != INVALID_HANDLE_VALUE)
{
@@ -2233,10 +2218,12 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
* Return an anonymous pipe as the best approximation. */
LOG (GNUNET_ERROR_TYPE_DEBUG,
"CreateNamedPipe not implemented, resorting to "
- "CreatePipe: size = %lu\n", psize);
+ "CreatePipe: size = %lu\n",
+ psize);
if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize))
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "pipe read handle = %p, write handle = %p\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "pipe read handle = %p, write handle = %p\n",
*read_pipe_ptr,
*write_pipe_ptr);
return GNUNET_OK;
@@ -2254,8 +2241,12 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
/* Open the named pipe for writing.
* Be sure to permit FILE_READ_ATTRIBUTES access. */
- write_pipe = CreateFileA (pipename, GENERIC_WRITE | FILE_READ_ATTRIBUTES, 0, /* share mode */
- sa_ptr, OPEN_EXISTING, dwWriteMode, /* flags and attributes */
+ write_pipe = CreateFileA (pipename,
+ GENERIC_WRITE | FILE_READ_ATTRIBUTES,
+ 0, /* share mode */
+ sa_ptr,
+ OPEN_EXISTING,
+ dwWriteMode, /* flags and attributes */
0); /* handle to template file */
if (write_pipe == INVALID_HANDLE_VALUE)
@@ -2287,9 +2278,9 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
*/
struct GNUNET_DISK_PipeHandle *
GNUNET_DISK_pipe (int blocking_read,
- int blocking_write,
- int inherit_read,
- int inherit_write)
+ int blocking_write,
+ int inherit_read,
+ int inherit_write)
{
#ifndef MINGW
int fd[2];
@@ -2302,14 +2293,11 @@ GNUNET_DISK_pipe (int blocking_read,
if (ret == -1)
{
eno = errno;
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "pipe");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
errno = eno;
return NULL;
}
- return GNUNET_DISK_pipe_from_fd (blocking_read,
- blocking_write,
- fd);
+ return GNUNET_DISK_pipe_from_fd (blocking_read, blocking_write, fd);
#else
struct GNUNET_DISK_PipeHandle *p;
BOOL ret;
@@ -2329,11 +2317,13 @@ GNUNET_DISK_pipe (int blocking_read,
* Pipes are not seekable, and need no offsets, which is
* probably why it works for them.
*/
- ret =
- create_selectable_pipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0,
- FILE_FLAG_OVERLAPPED,
- FILE_FLAG_OVERLAPPED);
- if (!ret)
+ ret = create_selectable_pipe (&p->fd[0]->h,
+ &p->fd[1]->h,
+ NULL,
+ 0,
+ FILE_FLAG_OVERLAPPED,
+ FILE_FLAG_OVERLAPPED);
+ if (! ret)
{
SetErrnoFromWinError (GetLastError ());
save_errno = errno;
@@ -2343,9 +2333,13 @@ GNUNET_DISK_pipe (int blocking_read,
errno = save_errno;
return NULL;
}
- if (!DuplicateHandle
- (GetCurrentProcess (), p->fd[0]->h, GetCurrentProcess (), &tmp_handle, 0,
- inherit_read == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS))
+ if (! DuplicateHandle (GetCurrentProcess (),
+ p->fd[0]->h,
+ GetCurrentProcess (),
+ &tmp_handle,
+ 0,
+ inherit_read == GNUNET_YES ? TRUE : FALSE,
+ DUPLICATE_SAME_ACCESS))
{
SetErrnoFromWinError (GetLastError ());
save_errno = errno;
@@ -2360,9 +2354,13 @@ GNUNET_DISK_pipe (int blocking_read,
CloseHandle (p->fd[0]->h);
p->fd[0]->h = tmp_handle;
- if (!DuplicateHandle
- (GetCurrentProcess (), p->fd[1]->h, GetCurrentProcess (), &tmp_handle, 0,
- inherit_write == GNUNET_YES ? TRUE : FALSE, DUPLICATE_SAME_ACCESS))
+ if (! DuplicateHandle (GetCurrentProcess (),
+ p->fd[1]->h,
+ GetCurrentProcess (),
+ &tmp_handle,
+ 0,
+ inherit_write == GNUNET_YES ? TRUE : FALSE,
+ DUPLICATE_SAME_ACCESS))
{
SetErrnoFromWinError (GetLastError ());
save_errno = errno;
@@ -2423,14 +2421,14 @@ GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2])
{
p->fd[0] = GNUNET_new (struct GNUNET_DISK_FileHandle);
p->fd[0]->fd = fd[0];
- if (!blocking_read)
+ if (! blocking_read)
{
flags = fcntl (fd[0], F_GETFL);
flags |= O_NONBLOCK;
if (0 > fcntl (fd[0], F_SETFL, flags))
{
- ret = -1;
- eno = errno;
+ ret = -1;
+ eno = errno;
}
}
flags = fcntl (fd[0], F_GETFD);
@@ -2446,14 +2444,14 @@ GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2])
{
p->fd[1] = GNUNET_new (struct GNUNET_DISK_FileHandle);
p->fd[1]->fd = fd[1];
- if (!blocking_write)
+ if (! blocking_write)
{
flags = fcntl (fd[1], F_GETFL);
flags |= O_NONBLOCK;
if (0 > fcntl (fd[1], F_SETFL, flags))
{
- ret = -1;
- eno = errno;
+ ret = -1;
+ eno = errno;
}
}
flags = fcntl (fd[1], F_GETFD);
@@ -2663,7 +2661,8 @@ GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p,
*/
int
GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
- void *dst, size_t dst_len)
+ void *dst,
+ size_t dst_len)
{
if (NULL == fh)
return GNUNET_SYSERR;
@@ -2689,29 +2688,20 @@ GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
* @return #GNUNET_OK on success
*/
static int
-purge_cfg_dir (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+purge_cfg_dir (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
const char *option = cls;
char *tmpname;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "PATHS",
- option,
- &tmpname))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "PATHS",
- option);
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", option, &tmpname))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "PATHS", option);
return GNUNET_NO;
}
- if (GNUNET_SYSERR ==
- GNUNET_DISK_directory_remove (tmpname))
+ if (GNUNET_SYSERR == GNUNET_DISK_directory_remove (tmpname))
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "remove",
- tmpname);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "remove", tmpname);
GNUNET_free (tmpname);
return GNUNET_OK;
}
@@ -2728,13 +2718,12 @@ purge_cfg_dir (void *cls,
* @param option option with the dir name to purge
*/
void
-GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
- const char *option)
+GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, const char *option)
{
GNUNET_break (GNUNET_OK ==
- GNUNET_CONFIGURATION_parse_and_run (cfg_filename,
- &purge_cfg_dir,
- (void *) option));
+ GNUNET_CONFIGURATION_parse_and_run (cfg_filename,
+ &purge_cfg_dir,
+ (void *) option));
}
diff --git a/src/util/dnsstub.c b/src/util/dnsstub.c
index a16a9a7dd..aa0c2191a 100644
--- a/src/util/dnsstub.c
+++ b/src/util/dnsstub.c
@@ -28,7 +28,8 @@
/**
* Timeout for retrying DNS queries.
*/
-#define DNS_RETRANSMIT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
+#define DNS_RETRANSMIT_DELAY \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
/**
@@ -92,7 +93,6 @@ struct GNUNET_DNSSTUB_RequestSocket
* Number of bytes in @a request.
*/
size_t request_len;
-
};
@@ -149,7 +149,6 @@ struct GNUNET_DNSSTUB_Context
* Length of @e sockets array.
*/
unsigned int num_sockets;
-
};
@@ -223,13 +222,11 @@ open_socket (int af)
return NULL;
}
sa->sa_family = af;
- if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret,
- sa,
- alen))
+ if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret, sa, alen))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not bind to any port: %s\n"),
- STRERROR (errno));
+ _ ("Could not bind to any port: %s\n"),
+ strerror (errno));
GNUNET_NETWORK_socket_close (ret);
return NULL;
}
@@ -249,7 +246,7 @@ get_request_socket (struct GNUNET_DNSSTUB_Context *ctx)
{
struct GNUNET_DNSSTUB_RequestSocket *rs;
- for (unsigned int i=0;i<256;i++)
+ for (unsigned int i = 0; i < 256; i++)
{
rs = &ctx->sockets[GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
ctx->num_sockets)];
@@ -259,9 +256,7 @@ get_request_socket (struct GNUNET_DNSSTUB_Context *ctx)
if (NULL != rs->rc)
{
/* signal "failure" */
- rs->rc (rs->rc_cls,
- NULL,
- 0);
+ rs->rc (rs->rc_cls, NULL, 0);
rs->rc = NULL;
}
if (NULL != rs->read_task)
@@ -294,16 +289,14 @@ get_request_socket (struct GNUNET_DNSSTUB_Context *ctx)
*/
static int
do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
- struct GNUNET_NETWORK_Handle *dnsout)
+ struct GNUNET_NETWORK_Handle *dnsout)
{
struct GNUNET_DNSSTUB_Context *ctx = rs->ctx;
ssize_t r;
int len;
#ifndef MINGW
- if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout),
- FIONREAD,
- &len))
+ if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len))
{
/* conservative choice: */
len = UINT16_MAX;
@@ -312,9 +305,7 @@ do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
/* port the code above? */
len = UINT16_MAX;
#endif
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receiving %d byte DNS reply\n",
- len);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving %d byte DNS reply\n", len);
{
unsigned char buf[len] GNUNET_ALIGN;
int found;
@@ -323,18 +314,15 @@ do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
struct GNUNET_TUN_DnsHeader *dns;
addrlen = sizeof (addr);
- memset (&addr,
- 0,
- sizeof (addr));
+ memset (&addr, 0, sizeof (addr));
r = GNUNET_NETWORK_socket_recvfrom (dnsout,
- buf,
+ buf,
sizeof (buf),
- (struct sockaddr*) &addr,
+ (struct sockaddr *) &addr,
&addrlen);
if (-1 == r)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "recvfrom");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "recvfrom");
GNUNET_NETWORK_socket_close (dnsout);
return GNUNET_SYSERR;
}
@@ -343,8 +331,7 @@ do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
{
if (0 == memcmp (&addr,
&ds->ss,
- GNUNET_MIN (sizeof (struct sockaddr_storage),
- addrlen)))
+ GNUNET_MIN (sizeof (struct sockaddr_storage), addrlen)))
{
found = GNUNET_YES;
break;
@@ -353,26 +340,24 @@ do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
if (GNUNET_NO == found)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received DNS response from server we never asked (ignored)");
+ "Received DNS response from server we never asked (ignored)");
return GNUNET_NO;
}
if (sizeof (struct GNUNET_TUN_DnsHeader) > (size_t) r)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Received DNS response that is too small (%u bytes)"),
- (unsigned int) r);
+ _ ("Received DNS response that is too small (%u bytes)"),
+ (unsigned int) r);
return GNUNET_NO;
}
dns = (struct GNUNET_TUN_DnsHeader *) buf;
if (NULL == rs->rc)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Request timeout or cancelled; ignoring reply\n");
+ "Request timeout or cancelled; ignoring reply\n");
return GNUNET_NO;
}
- rs->rc (rs->rc_cls,
- dns,
- r);
+ rs->rc (rs->rc_cls, dns, r);
}
return GNUNET_OK;
}
@@ -401,17 +386,16 @@ schedule_read (struct GNUNET_DNSSTUB_RequestSocket *rs)
GNUNET_SCHEDULER_cancel (rs->read_task);
rset = GNUNET_NETWORK_fdset_create ();
if (NULL != rs->dnsout4)
- GNUNET_NETWORK_fdset_set (rset,
- rs->dnsout4);
+ GNUNET_NETWORK_fdset_set (rset, rs->dnsout4);
if (NULL != rs->dnsout6)
- GNUNET_NETWORK_fdset_set (rset,
- rs->dnsout6);
- rs->read_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_TIME_UNIT_FOREVER_REL,
- rset,
- NULL,
- &read_response,
- rs);
+ GNUNET_NETWORK_fdset_set (rset, rs->dnsout6);
+ rs->read_task =
+ GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ rset,
+ NULL,
+ &read_response,
+ rs);
GNUNET_NETWORK_fdset_destroy (rset);
}
@@ -430,19 +414,13 @@ read_response (void *cls)
rs->read_task = NULL;
tc = GNUNET_SCHEDULER_get_task_context ();
/* read and process ready sockets */
- if ( (NULL != rs->dnsout4) &&
- (GNUNET_NETWORK_fdset_isset (tc->read_ready,
- rs->dnsout4)) &&
- (GNUNET_SYSERR ==
- do_dns_read (rs,
- rs->dnsout4)) )
+ if ((NULL != rs->dnsout4) &&
+ (GNUNET_NETWORK_fdset_isset (tc->read_ready, rs->dnsout4)) &&
+ (GNUNET_SYSERR == do_dns_read (rs, rs->dnsout4)))
rs->dnsout4 = NULL;
- if ( (NULL != rs->dnsout6) &&
- (GNUNET_NETWORK_fdset_isset (tc->read_ready,
- rs->dnsout6)) &&
- (GNUNET_SYSERR ==
- do_dns_read (rs,
- rs->dnsout6)) )
+ if ((NULL != rs->dnsout6) &&
+ (GNUNET_NETWORK_fdset_isset (tc->read_ready, rs->dnsout6)) &&
+ (GNUNET_SYSERR == do_dns_read (rs, rs->dnsout6)))
rs->dnsout6 = NULL;
/* re-schedule read task */
schedule_read (rs);
@@ -465,9 +443,8 @@ transmit_query (void *cls)
struct DnsServer *ds;
struct GNUNET_NETWORK_Handle *dnsout;
- rs->retry_task = GNUNET_SCHEDULER_add_delayed (ctx->retry_freq,
- &transmit_query,
- rs);
+ rs->retry_task =
+ GNUNET_SCHEDULER_add_delayed (ctx->retry_freq, &transmit_query, rs);
ds = rs->ds_pos;
rs->ds_pos = ds->next;
if (NULL == rs->ds_pos)
@@ -499,22 +476,19 @@ transmit_query (void *cls)
"Unable to use configure DNS server, skipping\n");
return;
}
- if (GNUNET_SYSERR ==
- GNUNET_NETWORK_socket_sendto (dnsout,
- rs->request,
- rs->request_len,
- sa,
- salen))
+ if (GNUNET_SYSERR == GNUNET_NETWORK_socket_sendto (dnsout,
+ rs->request,
+ rs->request_len,
+ sa,
+ salen))
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to send DNS request to %s: %s\n"),
- GNUNET_a2s (sa,
- salen),
- STRERROR (errno));
+ _ ("Failed to send DNS request to %s: %s\n"),
+ GNUNET_a2s (sa, salen),
+ strerror (errno));
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Sent DNS request to %s\n"),
- GNUNET_a2s (sa,
- salen));
+ _ ("Sent DNS request to %s\n"),
+ GNUNET_a2s (sa, salen));
schedule_read (rs);
}
@@ -531,10 +505,10 @@ transmit_query (void *cls)
*/
struct GNUNET_DNSSTUB_RequestSocket *
GNUNET_DNSSTUB_resolve (struct GNUNET_DNSSTUB_Context *ctx,
- const void *request,
- size_t request_len,
- GNUNET_DNSSTUB_ResultCallback rc,
- void *rc_cls)
+ const void *request,
+ size_t request_len,
+ GNUNET_DNSSTUB_ResultCallback rc,
+ void *rc_cls)
{
struct GNUNET_DNSSTUB_RequestSocket *rs;
@@ -553,11 +527,9 @@ GNUNET_DNSSTUB_resolve (struct GNUNET_DNSSTUB_Context *ctx,
rs->ds_pos = ctx->dns_head;
rs->rc = rc;
rs->rc_cls = rc_cls;
- rs->request = GNUNET_memdup (request,
- request_len);
+ rs->request = GNUNET_memdup (request, request_len);
rs->request_len = request_len;
- rs->retry_task = GNUNET_SCHEDULER_add_now (&transmit_query,
- rs);
+ rs->retry_task = GNUNET_SCHEDULER_add_now (&transmit_query, rs);
return rs;
}
@@ -603,8 +575,8 @@ GNUNET_DNSSTUB_start (unsigned int num_sockets)
}
ctx = GNUNET_new (struct GNUNET_DNSSTUB_Context);
ctx->num_sockets = num_sockets;
- ctx->sockets = GNUNET_new_array (num_sockets,
- struct GNUNET_DNSSTUB_RequestSocket);
+ ctx->sockets =
+ GNUNET_new_array (num_sockets, struct GNUNET_DNSSTUB_RequestSocket);
ctx->retry_freq = DNS_RETRANSMIT_DELAY;
return ctx;
}
@@ -627,9 +599,7 @@ GNUNET_DNSSTUB_add_dns_ip (struct GNUNET_DNSSTUB_Context *ctx,
struct in6_addr i6;
ds = GNUNET_new (struct DnsServer);
- if (1 == inet_pton (AF_INET,
- dns_ip,
- &i4))
+ if (1 == inet_pton (AF_INET, dns_ip, &i4))
{
struct sockaddr_in *s4 = (struct sockaddr_in *) &ds->ss;
@@ -640,9 +610,7 @@ GNUNET_DNSSTUB_add_dns_ip (struct GNUNET_DNSSTUB_Context *ctx,
s4->sin_len = (u_char) sizeof (struct sockaddr_in);
#endif
}
- else if (1 == inet_pton (AF_INET6,
- dns_ip,
- &i6))
+ else if (1 == inet_pton (AF_INET6, dns_ip, &i6))
{
struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) &ds->ss;
@@ -661,9 +629,7 @@ GNUNET_DNSSTUB_add_dns_ip (struct GNUNET_DNSSTUB_Context *ctx,
GNUNET_free (ds);
return GNUNET_SYSERR;
}
- GNUNET_CONTAINER_DLL_insert (ctx->dns_head,
- ctx->dns_tail,
- ds);
+ GNUNET_CONTAINER_DLL_insert (ctx->dns_head, ctx->dns_tail, ds);
return GNUNET_OK;
}
@@ -686,23 +652,17 @@ GNUNET_DNSSTUB_add_dns_sa (struct GNUNET_DNSSTUB_Context *ctx,
switch (sa->sa_family)
{
case AF_INET:
- GNUNET_memcpy (&ds->ss,
- sa,
- sizeof (struct sockaddr_in));
+ GNUNET_memcpy (&ds->ss, sa, sizeof (struct sockaddr_in));
break;
case AF_INET6:
- GNUNET_memcpy (&ds->ss,
- sa,
- sizeof (struct sockaddr_in6));
+ GNUNET_memcpy (&ds->ss, sa, sizeof (struct sockaddr_in6));
break;
default:
GNUNET_break (0);
GNUNET_free (ds);
return GNUNET_SYSERR;
}
- GNUNET_CONTAINER_DLL_insert (ctx->dns_head,
- ctx->dns_tail,
- ds);
+ GNUNET_CONTAINER_DLL_insert (ctx->dns_head, ctx->dns_tail, ds);
return GNUNET_OK;
}
@@ -734,12 +694,10 @@ GNUNET_DNSSTUB_stop (struct GNUNET_DNSSTUB_Context *ctx)
while (NULL != (ds = ctx->dns_head))
{
- GNUNET_CONTAINER_DLL_remove (ctx->dns_head,
- ctx->dns_tail,
- ds);
+ GNUNET_CONTAINER_DLL_remove (ctx->dns_head, ctx->dns_tail, ds);
GNUNET_free (ds);
}
- for (unsigned int i=0;i<ctx->num_sockets;i++)
+ for (unsigned int i = 0; i < ctx->num_sockets; i++)
cleanup_rs (&ctx->sockets[i]);
GNUNET_free (ctx->sockets);
GNUNET_free (ctx);
diff --git a/src/util/getopt.c b/src/util/getopt.c
index 048f52ee0..678e2a61f 100644
--- a/src/util/getopt.c
+++ b/src/util/getopt.c
@@ -563,7 +563,7 @@ GN_getopt_internal (int argc,
if (ambig && ! exact)
{
if (GNopterr)
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option `%s' is ambiguous\n"),
argv[0],
argv[GNoptind]);
@@ -588,13 +588,13 @@ GN_getopt_internal (int argc,
{
if (argv[GNoptind - 1][1] == '-')
/* --option */
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option `--%s' does not allow an argument\n"),
argv[0],
pfound->name);
else
/* +option or -option */
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option `%c%s' does not allow an argument\n"),
argv[0],
argv[GNoptind - 1][0],
@@ -614,7 +614,7 @@ GN_getopt_internal (int argc,
{
if (GNopterr)
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option `%s' requires an argument\n"),
argv[0],
argv[GNoptind - 1]);
@@ -645,13 +645,13 @@ GN_getopt_internal (int argc,
{
if (argv[GNoptind][1] == '-')
/* --option */
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: unrecognized option `--%s'\n"),
argv[0],
nextchar);
else
/* +option or -option */
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: unrecognized option `%c%s'\n"),
argv[0],
argv[GNoptind][0],
@@ -679,9 +679,9 @@ GN_getopt_internal (int argc,
{
if (posixly_correct)
/* 1003.2 specifies the format of this message. */
- FPRINTF (stderr, _ ("%s: illegal option -- %c\n"), argv[0], c);
+ fprintf (stderr, _ ("%s: illegal option -- %c\n"), argv[0], c);
else
- FPRINTF (stderr, _ ("%s: invalid option -- %c\n"), argv[0], c);
+ fprintf (stderr, _ ("%s: invalid option -- %c\n"), argv[0], c);
}
return '?';
}
@@ -709,7 +709,7 @@ GN_getopt_internal (int argc,
if (GNopterr)
{
/* 1003.2 specifies the format of this message. */
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option requires an argument -- %c\n"),
argv[0],
c);
@@ -759,7 +759,7 @@ GN_getopt_internal (int argc,
if (ambig && ! exact)
{
if (GNopterr)
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option `-W %s' is ambiguous\n"),
argv[0],
argv[GNoptind]);
@@ -779,7 +779,7 @@ GN_getopt_internal (int argc,
else
{
if (GNopterr)
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option `-W %s' does not allow an argument\n"),
argv[0],
pfound->name);
@@ -795,7 +795,7 @@ GN_getopt_internal (int argc,
else
{
if (GNopterr)
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option `%s' requires an argument\n"),
argv[0],
argv[GNoptind - 1]);
@@ -845,7 +845,7 @@ GN_getopt_internal (int argc,
if (GNopterr)
{
/* 1003.2 specifies the format of this message. */
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("%s: option requires an argument -- %c\n"),
argv[0],
c);
@@ -972,7 +972,7 @@ GNUNET_GETOPT_run (const char *binaryOptions,
}
if (i == count)
{
- FPRINTF (stderr, _ ("Use %s to get a list of options.\n"), "--help");
+ fprintf (stderr, _ ("Use %s to get a list of options.\n"), "--help");
cont = GNUNET_SYSERR;
}
}
@@ -983,7 +983,7 @@ GNUNET_GETOPT_run (const char *binaryOptions,
is the only option that was provided */
if ((NULL != have_exclusive) && (optmatch > 1))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("Option `%s' can't be used with other options.\n"),
have_exclusive);
cont = GNUNET_SYSERR;
@@ -995,7 +995,7 @@ GNUNET_GETOPT_run (const char *binaryOptions,
{
if ((0 == seen[count]) && (allOptions[count].option_mandatory))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("Missing mandatory option `%s'.\n"),
allOptions[count].name);
cont = GNUNET_SYSERR;
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c
index 80d1037bb..f53441508 100644
--- a/src/util/getopt_helpers.c
+++ b/src/util/getopt_helpers.c
@@ -184,7 +184,7 @@ format_help (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
if (0 != pd->is_gnu)
printf ("General help using GNU software: http://www.gnu.org/gethelp/\n");
-
+
return GNUNET_NO;
}
@@ -544,9 +544,9 @@ set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
char dummy[2];
(void) ctx;
- if (1 != SSCANF (value, "%llu%1s", val, dummy))
+ if (1 != sscanf (value, "%llu%1s", val, dummy))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("You must pass a number to the `%s' option.\n"),
option);
return GNUNET_SYSERR;
@@ -607,7 +607,7 @@ set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
(void) ctx;
if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (value, val))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("You must pass relative time to the `%s' option.\n"),
option);
return GNUNET_SYSERR;
@@ -669,7 +669,7 @@ set_absolute_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
(void) ctx;
if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (value, val))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("You must pass absolute time to the `%s' option.\n"),
option);
return GNUNET_SYSERR;
@@ -732,15 +732,15 @@ set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
(void) ctx;
if ('-' == *value)
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ (
"Your input for the '%s' option has to be a non negative number \n"),
option);
return GNUNET_SYSERR;
}
- if (1 != SSCANF (value, "%u%1s", val, dummy))
+ if (1 != sscanf (value, "%u%1s", val, dummy))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("You must pass a number to the `%s' option.\n"),
option);
return GNUNET_SYSERR;
@@ -801,16 +801,16 @@ set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
char dummy[2];
(void) ctx;
- if (1 != SSCANF (value, "%u%1s", &v, dummy))
+ if (1 != sscanf (value, "%u%1s", &v, dummy))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("You must pass a number to the `%s' option.\n"),
option);
return GNUNET_SYSERR;
}
if (v > UINT16_MAX)
{
- FPRINTF (stderr,
+ fprintf (stderr,
_ ("You must pass a number below %u to the `%s' option.\n"),
(unsigned int) UINT16_MAX,
option);
diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c
index d2253337c..e7a170b81 100644
--- a/src/util/gnunet-ecc.c
+++ b/src/util/gnunet-ecc.c
@@ -31,7 +31,7 @@
/**
* Number of characters a Base32-encoded public key requires.
*/
-#define KEY_STR_LEN sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)*8/5+1
+#define KEY_STR_LEN sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) * 8 / 5 + 1
/**
* Flag for listing public key.
@@ -91,7 +91,7 @@ create_keys (const char *fn, const char *prefix)
if (NULL == (f = fopen (fn, "w+")))
{
- fprintf (stderr, _("Failed to open `%s': %s\n"), fn, STRERROR (errno));
+ fprintf (stderr, _ ("Failed to open `%s': %s\n"), fn, strerror (errno));
return;
}
if (NULL != prefix)
@@ -116,7 +116,7 @@ create_keys (const char *fn, const char *prefix)
* rest = 5%8 = 5 (bits)
* mask = ~(2**(8 - 5) - 1) = ~(2**3 - 1) = ~(8 - 1) = ~b111 = b11111000
*/
- mask = ~ ((int)pow (2, 8 - rest) - 1);
+ mask = ~((int) pow (2, 8 - rest) - 1);
target_byte = ((unsigned char *) &target_pub)[n] & mask;
}
else
@@ -126,21 +126,15 @@ create_keys (const char *fn, const char *prefix)
}
s = GNUNET_CRYPTO_eddsa_public_key_to_string (&target_pub);
fprintf (stderr,
- _("Generating %u keys like %s, please wait"),
+ _ ("Generating %u keys like %s, please wait"),
make_keys,
s);
GNUNET_free (s);
- fprintf (stderr,
- "\nattempt %s [%u, %X]\n",
- vanity,
- (unsigned int) n,
- mask);
+ fprintf (stderr, "\nattempt %s [%u, %X]\n", vanity, (unsigned int) n, mask);
}
else
{
- fprintf (stderr,
- _("Generating %u keys, please wait"),
- make_keys);
+ fprintf (stderr, _ ("Generating %u keys, please wait"), make_keys);
/* Just so old (debian) versions of GCC calm down with the warnings. */
n = rest = target_byte = mask = 0;
}
@@ -150,8 +144,8 @@ create_keys (const char *fn, const char *prefix)
fprintf (stderr, ".");
if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create ()))
{
- GNUNET_break (0);
- break;
+ GNUNET_break (0);
+ break;
}
if (NULL != prefix)
{
@@ -176,38 +170,32 @@ create_keys (const char *fn, const char *prefix)
}
}
if (GNUNET_TESTING_HOSTKEYFILESIZE !=
- fwrite (pk, 1,
- GNUNET_TESTING_HOSTKEYFILESIZE, f))
+ fwrite (pk, 1, GNUNET_TESTING_HOSTKEYFILESIZE, f))
{
fprintf (stderr,
- _("\nFailed to write to `%s': %s\n"),
- fn,
- STRERROR (errno));
+ _ ("\nFailed to write to `%s': %s\n"),
+ fn,
+ strerror (errno));
GNUNET_free (pk);
break;
}
GNUNET_free (pk);
}
if (UINT_MAX == make_keys)
- fprintf (stderr,
- _("\nFinished!\n"));
+ fprintf (stderr, _ ("\nFinished!\n"));
else
- fprintf (stderr,
- _("\nError, %u keys not generated\n"),
- make_keys);
+ fprintf (stderr, _ ("\nError, %u keys not generated\n"), make_keys);
fclose (f);
}
static void
-print_hex (const char *msg,
- const void *buf,
- size_t size)
+print_hex (const char *msg, const void *buf, size_t size)
{
printf ("%s: ", msg);
for (size_t i = 0; i < size; i++)
{
- printf ("%02hhx", ((const uint8_t *)buf)[i]);
+ printf ("%02hhx", ((const uint8_t *) buf)[i]);
}
printf ("\n");
}
@@ -230,7 +218,8 @@ print_examples_ecdh ()
GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv1, dh_pub1);
GNUNET_CRYPTO_ecdhe_key_get_public (dh_priv2, dh_pub2);
- GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_priv1, 32, buf, 128));
+ GNUNET_assert (NULL !=
+ GNUNET_STRINGS_data_to_string (dh_priv1, 32, buf, 128));
printf ("ECDHE key 1:\n");
printf ("private: %s\n", buf);
print_hex ("private(hex)", dh_priv1, sizeof *dh_priv1);
@@ -238,7 +227,8 @@ print_examples_ecdh ()
printf ("public: %s\n", buf);
print_hex ("public(hex)", dh_pub1, sizeof *dh_pub1);
- GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (dh_priv2, 32, buf, 128));
+ GNUNET_assert (NULL !=
+ GNUNET_STRINGS_data_to_string (dh_priv2, 32, buf, 128));
printf ("ECDHE key 2:\n");
printf ("private: %s\n", buf);
print_hex ("private(hex)", dh_priv2, sizeof *dh_priv2);
@@ -246,7 +236,8 @@ print_examples_ecdh ()
printf ("public: %s\n", buf);
print_hex ("public(hex)", dh_pub2, sizeof *dh_pub2);
- GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecc_ecdh (dh_priv1, dh_pub2, &hash));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_ecc_ecdh (dh_priv1, dh_pub2, &hash));
GNUNET_assert (NULL != GNUNET_STRINGS_data_to_string (&hash, 64, buf, 128));
printf ("ECDH shared secret: %s\n", buf);
@@ -282,56 +273,39 @@ print_key (const char *filename)
unsigned int c;
ssize_t sret;
- if (GNUNET_YES !=
- GNUNET_DISK_file_test (filename))
+ if (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
- fprintf (stderr,
- _("Hostkeys file `%s' not found\n"),
- filename);
+ fprintf (stderr, _ ("Hostkeys file `%s' not found\n"), filename);
return;
}
/* Check hostkey file size, read entire thing into memory */
if (GNUNET_OK !=
- GNUNET_DISK_file_size (filename,
- &fs,
- GNUNET_YES,
- GNUNET_YES))
+ GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
fs = 0;
if (0 == fs)
{
- fprintf (stderr,
- _("Hostkeys file `%s' is empty\n"),
- filename);
- return; /* File is empty */
+ fprintf (stderr, _ ("Hostkeys file `%s' is empty\n"), filename);
+ return; /* File is empty */
}
if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
{
- fprintf (stderr,
- _("Incorrect hostkey file format: %s\n"),
- filename);
+ fprintf (stderr, _ ("Incorrect hostkey file format: %s\n"), filename);
return;
}
fd = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE);
if (NULL == fd)
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "open",
- filename);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
return;
}
hostkeys_data = GNUNET_malloc (fs);
- sret = GNUNET_DISK_file_read (fd,
- hostkeys_data,
- fs);
- if ( (sret < 0) ||
- (fs != (size_t) sret) )
+ sret = GNUNET_DISK_file_read (fd, hostkeys_data, fs);
+ if ((sret < 0) || (fs != (size_t) sret))
{
- fprintf (stderr,
- _("Could not read hostkey file: %s\n"),
- filename);
+ fprintf (stderr, _ ("Could not read hostkey file: %s\n"), filename);
GNUNET_free (hostkeys_data);
GNUNET_DISK_file_close (fd);
return;
@@ -344,8 +318,8 @@ print_key (const char *filename)
for (c = 0; (c < total_hostkeys) && (c < list_keys_count); c++)
{
GNUNET_memcpy (&private_key,
- hostkeys_data + (c * GNUNET_TESTING_HOSTKEYFILESIZE),
- GNUNET_TESTING_HOSTKEYFILESIZE);
+ hostkeys_data + (c * GNUNET_TESTING_HOSTKEYFILESIZE),
+ GNUNET_TESTING_HOSTKEYFILESIZE);
GNUNET_CRYPTO_eddsa_key_get_public (&private_key, &public_key);
hostkey_str = GNUNET_CRYPTO_eddsa_public_key_to_string (&public_key);
if (NULL != hostkey_str)
@@ -377,7 +351,7 @@ run (void *cls,
(void) cls;
(void) cfgfile;
(void) cfg;
-
+
if (print_examples_flag)
{
print_examples ();
@@ -385,9 +359,7 @@ run (void *cls,
}
if (NULL == args[0])
{
- FPRINTF (stderr,
- "%s",
- _("No hostkey file specified on command line\n"));
+ fprintf (stderr, "%s", _ ("No hostkey file specified on command line\n"));
return;
}
if (list_keys)
@@ -407,12 +379,12 @@ run (void *cls,
struct GNUNET_CRYPTO_EddsaPrivateKey pk;
struct GNUNET_CRYPTO_EddsaPublicKey pub;
- keyfile = GNUNET_DISK_file_open (args[0], GNUNET_DISK_OPEN_READ,
+ keyfile = GNUNET_DISK_file_open (args[0],
+ GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
if (NULL == keyfile)
return;
- while (sizeof (pk) ==
- GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk)))
+ while (sizeof (pk) == GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk)))
{
GNUNET_CRYPTO_eddsa_key_get_public (&pk, &pub);
if (print_public_key_hex)
@@ -422,19 +394,18 @@ run (void *cls,
else if (print_public_key)
{
str = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub);
- FPRINTF (stdout, "%s\n", str);
+ fprintf (stdout, "%s\n", str);
GNUNET_free (str);
}
else if (print_private_key)
{
str = GNUNET_CRYPTO_eddsa_private_key_to_string (&pk);
- FPRINTF (stdout, "%s\n", str);
+ fprintf (stdout, "%s\n", str);
GNUNET_free (str);
}
}
GNUNET_DISK_file_close (keyfile);
}
-
}
@@ -446,59 +417,66 @@ run (void *cls,
* @return 0 ok, 1 on error
*/
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_flag ('i',
- "iterate",
- gettext_noop ("list keys included in a file (for testing)"),
- &list_keys),
- GNUNET_GETOPT_option_uint ('e',
- "end=",
- "COUNT",
- gettext_noop ("number of keys to list included in a file (for testing)"),
- &list_keys_count),
- GNUNET_GETOPT_option_uint ('g',
- "generate-keys",
- "COUNT",
- gettext_noop ("create COUNT public-private key pairs (for testing)"),
- &make_keys),
- GNUNET_GETOPT_option_flag ('p',
- "print-public-key",
- gettext_noop ("print the public key in ASCII format"),
- &print_public_key),
- GNUNET_GETOPT_option_flag ('P',
- "print-private-key",
- gettext_noop ("print the private key in ASCII format"),
- &print_private_key),
- GNUNET_GETOPT_option_flag ('x',
- "print-hex",
- gettext_noop ("print the public key in HEX format"),
- &print_public_key_hex),
- GNUNET_GETOPT_option_flag ('E',
- "examples",
- gettext_noop ("print examples of ECC operations (used for compatibility testing)"),
- &print_examples_flag),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_flag ('i',
+ "iterate",
+ gettext_noop (
+ "list keys included in a file (for testing)"),
+ &list_keys),
+ GNUNET_GETOPT_option_uint (
+ 'e',
+ "end=",
+ "COUNT",
+ gettext_noop ("number of keys to list included in a file (for testing)"),
+ &list_keys_count),
+ GNUNET_GETOPT_option_uint (
+ 'g',
+ "generate-keys",
+ "COUNT",
+ gettext_noop ("create COUNT public-private key pairs (for testing)"),
+ &make_keys),
+ GNUNET_GETOPT_option_flag ('p',
+ "print-public-key",
+ gettext_noop (
+ "print the public key in ASCII format"),
+ &print_public_key),
+ GNUNET_GETOPT_option_flag ('P',
+ "print-private-key",
+ gettext_noop (
+ "print the private key in ASCII format"),
+ &print_private_key),
+ GNUNET_GETOPT_option_flag ('x',
+ "print-hex",
+ gettext_noop (
+ "print the public key in HEX format"),
+ &print_public_key_hex),
+ GNUNET_GETOPT_option_flag (
+ 'E',
+ "examples",
+ gettext_noop (
+ "print examples of ECC operations (used for compatibility testing)"),
+ &print_examples_flag),
+ GNUNET_GETOPT_OPTION_END};
int ret;
list_keys_count = UINT32_MAX;
- if (GNUNET_OK !=
- GNUNET_STRINGS_get_utf8_args (argc, argv,
- &argc, &argv))
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc,
+ GNUNET_PROGRAM_run (argc,
argv,
"gnunet-ecc [OPTIONS] keyfile [VANITY_PREFIX]",
- gettext_noop ("Manipulate GNUnet private ECC key files"),
- options,
+ gettext_noop (
+ "Manipulate GNUnet private ECC key files"),
+ options,
&run,
- NULL)) ? 0 : 1;
- GNUNET_free ((void*) argv);
+ NULL))
+ ? 0
+ : 1;
+ GNUNET_free ((void *) argv);
return ret;
}
diff --git a/src/util/gnunet-resolver.c b/src/util/gnunet-resolver.c
index e5d58b4b6..3aba5fb1e 100644
--- a/src/util/gnunet-resolver.c
+++ b/src/util/gnunet-resolver.c
@@ -49,7 +49,7 @@ print_hostname (void *cls,
(void) cls;
if (NULL == hostname)
return;
- FPRINTF (stdout,
+ fprintf (stdout,
"%s\n",
hostname);
}
@@ -70,7 +70,7 @@ print_sockaddr (void *cls,
(void) cls;
if (NULL == addr)
return;
- FPRINTF (stdout,
+ fprintf (stdout,
"%s\n",
GNUNET_a2s (addr,
addrlen));
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c
index f4149a398..6f9690c99 100644
--- a/src/util/gnunet-scrypt.c
+++ b/src/util/gnunet-scrypt.c
@@ -144,7 +144,7 @@ find_proof (void *cls)
if (nse_work_required <= count_leading_zeroes (&result))
{
proof = counter;
- FPRINTF (stdout,
+ fprintf (stdout,
"Proof of work found: %llu!\n",
(unsigned long long) proof);
GNUNET_SCHEDULER_shutdown ();
@@ -236,7 +236,7 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn);
if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn)))
{
- FPRINTF (stderr, _ ("Loading hostkey from `%s' failed.\n"), pkfn);
+ fprintf (stderr, _ ("Loading hostkey from `%s' failed.\n"), pkfn);
GNUNET_free (pkfn);
return;
}
diff --git a/src/util/helper.c b/src/util/helper.c
index 7eb2ce6d9..aa452d22b 100644
--- a/src/util/helper.c
+++ b/src/util/helper.c
@@ -70,7 +70,6 @@ struct GNUNET_HELPER_SendHandle
* Current write position.
*/
unsigned int wpos;
-
};
@@ -177,17 +176,14 @@ struct GNUNET_HELPER_Handle
* @return #GNUNET_OK on success; #GNUNET_SYSERR on error
*/
int
-GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h,
- int soft_kill)
+GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, int soft_kill)
{
struct GNUNET_HELPER_SendHandle *sh;
int ret;
while (NULL != (sh = h->sh_head))
{
- GNUNET_CONTAINER_DLL_remove (h->sh_head,
- h->sh_tail,
- sh);
+ GNUNET_CONTAINER_DLL_remove (h->sh_head, h->sh_tail, sh);
if (NULL != sh->cont)
sh->cont (sh->cont_cls, GNUNET_NO);
GNUNET_free (sh);
@@ -264,19 +260,14 @@ GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h)
}
while (NULL != (sh = h->sh_head))
{
- GNUNET_CONTAINER_DLL_remove (h->sh_head,
- h->sh_tail,
- sh);
+ GNUNET_CONTAINER_DLL_remove (h->sh_head, h->sh_tail, sh);
if (NULL != sh->cont)
sh->cont (sh->cont_cls, GNUNET_NO);
GNUNET_free (sh);
}
/* purge MST buffer */
if (NULL != h->mst)
- (void) GNUNET_MST_from_buffer (h->mst,
- NULL, 0,
- GNUNET_YES,
- GNUNET_NO);
+ (void) GNUNET_MST_from_buffer (h->mst, NULL, 0, GNUNET_YES, GNUNET_NO);
return ret;
}
@@ -289,8 +280,7 @@ GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h)
* stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper
*/
static void
-stop_helper (struct GNUNET_HELPER_Handle *h,
- int soft_kill)
+stop_helper (struct GNUNET_HELPER_Handle *h, int soft_kill)
{
if (NULL != h->restart_task)
{
@@ -332,9 +322,9 @@ helper_read (void *cls)
{
/* On read-error, restart the helper */
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Error reading from `%s': %s\n"),
- h->binary_name,
- STRERROR (errno));
+ _ ("Error reading from `%s': %s\n"),
+ h->binary_name,
+ strerror (errno));
if (NULL != h->exp_cb)
{
h->exp_cb (h->cb_cls);
@@ -343,9 +333,11 @@ helper_read (void *cls)
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off),
- &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task,
+ h);
return;
}
if (0 == t)
@@ -353,8 +345,8 @@ helper_read (void *cls)
/* this happens if the helper is shut down via a
signal, so it is not a "hard" error */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got 0 bytes from helper `%s' (EOF)\n",
- h->binary_name);
+ "Got 0 bytes from helper `%s' (EOF)\n",
+ h->binary_name);
if (NULL != h->exp_cb)
{
h->exp_cb (h->cb_cls);
@@ -363,28 +355,27 @@ helper_read (void *cls)
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off),
- &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task,
+ h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got %u bytes from helper `%s'\n",
- (unsigned int) t,
- h->binary_name);
+ "Got %u bytes from helper `%s'\n",
+ (unsigned int) t,
+ h->binary_name);
h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->fh_from_helper,
- &helper_read, h);
+ h->fh_from_helper,
+ &helper_read,
+ h);
if (GNUNET_SYSERR ==
- GNUNET_MST_from_buffer (h->mst,
- buf, t,
- GNUNET_NO,
- GNUNET_NO))
+ GNUNET_MST_from_buffer (h->mst, buf, t, GNUNET_NO, GNUNET_NO))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to parse inbound message from helper `%s'\n"),
- h->binary_name);
+ _ ("Failed to parse inbound message from helper `%s'\n"),
+ h->binary_name);
if (NULL != h->exp_cb)
{
h->exp_cb (h->cb_cls);
@@ -393,9 +384,11 @@ helper_read (void *cls)
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off),
- &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task,
+ h);
return;
}
}
@@ -409,46 +402,53 @@ helper_read (void *cls)
static void
start_helper (struct GNUNET_HELPER_Handle *h)
{
- h->helper_in = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
- h->helper_out = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
- if ( (h->helper_in == NULL) || (h->helper_out == NULL))
+ h->helper_in =
+ GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
+ h->helper_out =
+ GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
+ if ((h->helper_in == NULL) || (h->helper_out == NULL))
{
/* out of file descriptors? try again later... */
stop_helper (h, GNUNET_NO);
- h->restart_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off),
- &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task,
+ h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting HELPER process `%s'\n",
- h->binary_name);
+ "Starting HELPER process `%s'\n",
+ h->binary_name);
h->fh_from_helper =
- GNUNET_DISK_pipe_handle (h->helper_out, GNUNET_DISK_PIPE_END_READ);
+ GNUNET_DISK_pipe_handle (h->helper_out, GNUNET_DISK_PIPE_END_READ);
h->fh_to_helper =
- GNUNET_DISK_pipe_handle (h->helper_in, GNUNET_DISK_PIPE_END_WRITE);
- h->helper_proc =
- GNUNET_OS_start_process_vap (h->with_control_pipe, GNUNET_OS_INHERIT_STD_ERR,
- h->helper_in, h->helper_out, NULL,
- h->binary_name,
- h->binary_argv);
+ GNUNET_DISK_pipe_handle (h->helper_in, GNUNET_DISK_PIPE_END_WRITE);
+ h->helper_proc = GNUNET_OS_start_process_vap (h->with_control_pipe,
+ GNUNET_OS_INHERIT_STD_ERR,
+ h->helper_in,
+ h->helper_out,
+ NULL,
+ h->binary_name,
+ h->binary_argv);
if (NULL == h->helper_proc)
{
/* failed to start process? try again later... */
stop_helper (h, GNUNET_NO);
- h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off),
- &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task,
+ h);
return;
}
GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE);
GNUNET_DISK_pipe_close_end (h->helper_in, GNUNET_DISK_PIPE_END_READ);
if (NULL != h->mst)
h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->fh_from_helper,
- &helper_read,
- h);
+ h->fh_from_helper,
+ &helper_read,
+ h);
}
@@ -460,7 +460,7 @@ start_helper (struct GNUNET_HELPER_Handle *h)
static void
restart_task (void *cls)
{
- struct GNUNET_HELPER_Handle*h = cls;
+ struct GNUNET_HELPER_Handle *h = cls;
h->restart_task = NULL;
h->retry_back_off++;
@@ -489,11 +489,11 @@ restart_task (void *cls)
*/
struct GNUNET_HELPER_Handle *
GNUNET_HELPER_start (int with_control_pipe,
- const char *binary_name,
- char *const binary_argv[],
- GNUNET_MessageTokenizerCallback cb,
- GNUNET_HELPER_ExceptionCallback exp_cb,
- void *cb_cls)
+ const char *binary_name,
+ char *const binary_argv[],
+ GNUNET_MessageTokenizerCallback cb,
+ GNUNET_HELPER_ExceptionCallback exp_cb,
+ void *cb_cls)
{
struct GNUNET_HELPER_Handle *h;
unsigned int c;
@@ -505,15 +505,15 @@ GNUNET_HELPER_start (int with_control_pipe,
h->binary_name = GNUNET_OS_get_libexec_binary_path (binary_name);
else
h->binary_name = GNUNET_strdup (binary_name);
- for (c = 0; NULL != binary_argv[c]; c++);
+ for (c = 0; NULL != binary_argv[c]; c++)
+ ;
h->binary_argv = GNUNET_malloc (sizeof (char *) * (c + 1));
for (c = 0; NULL != binary_argv[c]; c++)
h->binary_argv[c] = GNUNET_strdup (binary_argv[c]);
h->binary_argv[c] = NULL;
h->cb_cls = cb_cls;
if (NULL != cb)
- h->mst = GNUNET_MST_create (cb,
- h->cb_cls);
+ h->mst = GNUNET_MST_create (cb, h->cb_cls);
h->exp_cb = exp_cb;
h->retry_back_off = 0;
start_helper (h);
@@ -541,9 +541,7 @@ GNUNET_HELPER_destroy (struct GNUNET_HELPER_Handle *h)
GNUNET_assert (NULL == h->restart_task);
while (NULL != (sh = h->sh_head))
{
- GNUNET_CONTAINER_DLL_remove (h->sh_head,
- h->sh_tail,
- sh);
+ GNUNET_CONTAINER_DLL_remove (h->sh_head, h->sh_tail, sh);
if (NULL != sh->cont)
sh->cont (sh->cont_cls, GNUNET_SYSERR);
GNUNET_free (sh);
@@ -566,8 +564,7 @@ GNUNET_HELPER_destroy (struct GNUNET_HELPER_Handle *h)
* stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper
*/
void
-GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h,
- int soft_kill)
+GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h, int soft_kill)
{
h->exp_cb = NULL;
stop_helper (h, soft_kill);
@@ -591,21 +588,20 @@ helper_write (void *cls)
h->write_task = NULL;
if (NULL == (sh = h->sh_head))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Helper write had no work!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Helper write had no work!\n");
return; /* how did this happen? */
}
- buf = (const char*) sh->msg;
+ buf = (const char *) sh->msg;
t = GNUNET_DISK_file_write (h->fh_to_helper,
- &buf[sh->wpos],
- ntohs (sh->msg->size) - sh->wpos);
+ &buf[sh->wpos],
+ ntohs (sh->msg->size) - sh->wpos);
if (-1 == t)
{
/* On write-error, restart the helper */
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Error writing to `%s': %s\n"),
- h->binary_name,
- STRERROR (errno));
+ _ ("Error writing to `%s': %s\n"),
+ h->binary_name,
+ strerror (errno));
if (NULL != h->exp_cb)
{
h->exp_cb (h->cb_cls);
@@ -613,33 +609,34 @@ helper_write (void *cls)
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stopping and restarting helper task!\n");
+ "Stopping and restarting helper task!\n");
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off),
- &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task,
+ h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitted %u bytes to %s\n",
- (unsigned int) t,
- h->binary_name);
+ "Transmitted %u bytes to %s\n",
+ (unsigned int) t,
+ h->binary_name);
sh->wpos += t;
if (sh->wpos == ntohs (sh->msg->size))
{
- GNUNET_CONTAINER_DLL_remove (h->sh_head,
- h->sh_tail,
- sh);
+ GNUNET_CONTAINER_DLL_remove (h->sh_head, h->sh_tail, sh);
if (NULL != sh->cont)
sh->cont (sh->cont_cls, GNUNET_YES);
GNUNET_free (sh);
}
if (NULL != h->sh_head)
- h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->fh_to_helper,
- &helper_write,
- h);
+ h->write_task =
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ h->fh_to_helper,
+ &helper_write,
+ h);
}
@@ -658,34 +655,32 @@ helper_write (void *cls)
*/
struct GNUNET_HELPER_SendHandle *
GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h,
- const struct GNUNET_MessageHeader *msg,
- int can_drop,
- GNUNET_HELPER_Continuation cont,
- void *cont_cls)
+ const struct GNUNET_MessageHeader *msg,
+ int can_drop,
+ GNUNET_HELPER_Continuation cont,
+ void *cont_cls)
{
struct GNUNET_HELPER_SendHandle *sh;
uint16_t mlen;
if (NULL == h->fh_to_helper)
return NULL;
- if ( (GNUNET_YES == can_drop) &&
- (NULL != h->sh_head) )
+ if ((GNUNET_YES == can_drop) && (NULL != h->sh_head))
return NULL;
mlen = ntohs (msg->size);
sh = GNUNET_malloc (sizeof (struct GNUNET_HELPER_SendHandle) + mlen);
- sh->msg = (const struct GNUNET_MessageHeader*) &sh[1];
+ sh->msg = (const struct GNUNET_MessageHeader *) &sh[1];
GNUNET_memcpy (&sh[1], msg, mlen);
sh->h = h;
sh->cont = cont;
sh->cont_cls = cont_cls;
- GNUNET_CONTAINER_DLL_insert_tail (h->sh_head,
- h->sh_tail,
- sh);
+ GNUNET_CONTAINER_DLL_insert_tail (h->sh_head, h->sh_tail, sh);
if (NULL == h->write_task)
- h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->fh_to_helper,
- &helper_write,
- h);
+ h->write_task =
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ h->fh_to_helper,
+ &helper_write,
+ h);
return sh;
}
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index 8dacd431d..3e5a99811 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -107,7 +107,7 @@ GNUNET_OS_project_data_get ()
{
char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
if (NULL != path)
- BINDTEXTDOMAIN (PACKAGE, path);
+ bindtextdomain (PACKAGE, path);
GNUNET_free (path);
gettextinit = 1;
}
@@ -127,7 +127,7 @@ GNUNET_OS_init (const struct GNUNET_OS_ProjectData *pd)
{
char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
if (NULL != path)
- BINDTEXTDOMAIN (PACKAGE, path);
+ bindtextdomain (PACKAGE, path);
GNUNET_free (path);
gettextinit = 1;
}
@@ -152,7 +152,7 @@ get_path_from_proc_maps ()
char *lgu;
GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/maps", getpid ());
- if (NULL == (f = FOPEN (fn, "r")))
+ if (NULL == (f = fopen (fn, "r")))
return NULL;
while (NULL != fgets (line, sizeof (line), f))
{
@@ -162,11 +162,11 @@ get_path_from_proc_maps ()
(NULL != (lgu = strstr (dir, current_pd->libname))))
{
lgu[0] = '\0';
- FCLOSE (f);
+ fclose (f);
return GNUNET_strdup (dir);
}
}
- FCLOSE (f);
+ fclose (f);
return NULL;
}
@@ -666,7 +666,7 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
{
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR
- "%s" DIR_SEPARATOR_STR,
+ "%s" DIR_SEPARATOR_STR,
current_pd->project_dirname);
GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
}
@@ -674,7 +674,7 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
{
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR
- "%s" DIR_SEPARATOR_STR,
+ "%s" DIR_SEPARATOR_STR,
current_pd->project_dirname);
GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
}
@@ -696,22 +696,22 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
case GNUNET_OS_IPK_DATADIR:
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
- "%s" DIR_SEPARATOR_STR,
+ "%s" DIR_SEPARATOR_STR,
current_pd->project_dirname);
break;
case GNUNET_OS_IPK_LOCALEDIR:
dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
- "locale" DIR_SEPARATOR_STR);
+ "locale" DIR_SEPARATOR_STR);
break;
case GNUNET_OS_IPK_ICONDIR:
dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
- "icons" DIR_SEPARATOR_STR);
+ "icons" DIR_SEPARATOR_STR);
break;
case GNUNET_OS_IPK_DOCDIR:
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
- "doc" DIR_SEPARATOR_STR
- "%s" DIR_SEPARATOR_STR,
+ "doc" DIR_SEPARATOR_STR
+ "%s" DIR_SEPARATOR_STR,
current_pd->project_dirname);
break;
case GNUNET_OS_IPK_LIBEXECDIR:
@@ -719,7 +719,7 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
{
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR
- "libexec" DIR_SEPARATOR_STR,
+ "libexec" DIR_SEPARATOR_STR,
current_pd->project_dirname);
GNUNET_asprintf (&tmp,
"%s%s%s%s",
@@ -740,8 +740,8 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
{
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR
- "%s" DIR_SEPARATOR_STR
- "libexec" DIR_SEPARATOR_STR,
+ "%s" DIR_SEPARATOR_STR
+ "libexec" DIR_SEPARATOR_STR,
current_pd->project_dirname);
GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
}
@@ -749,8 +749,8 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
{
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR
- "%s" DIR_SEPARATOR_STR
- "libexec" DIR_SEPARATOR_STR,
+ "%s" DIR_SEPARATOR_STR
+ "libexec" DIR_SEPARATOR_STR,
current_pd->project_dirname);
GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
}
@@ -766,7 +766,7 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind)
}
GNUNET_asprintf (&dirname,
DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR
- "libexec" DIR_SEPARATOR_STR,
+ "libexec" DIR_SEPARATOR_STR,
current_pd->project_dirname);
break;
default:
@@ -844,14 +844,14 @@ GNUNET_OS_get_suid_binary_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
"PATHS",
"SUID_BINARY_PATH",
&path);
- if ((NULL == path)||(0 == strlen (path)))
+ if ((NULL == path) || (0 == strlen (path)))
return GNUNET_OS_get_libexec_binary_path (progname);
path_len = strlen (path);
GNUNET_asprintf (&binary,
"%s%s%s",
path,
(path[path_len - 1] == DIR_SEPARATOR) ? ""
- : DIR_SEPARATOR_STR,
+ : DIR_SEPARATOR_STR,
progname);
cache = path;
return binary;
@@ -926,7 +926,7 @@ GNUNET_OS_check_helper_binary (const char *binary,
binary);
return GNUNET_SYSERR;
}
- if (0 != ACCESS (p, X_OK))
+ if (0 != access (p, X_OK))
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", p);
GNUNET_free (p);
@@ -940,7 +940,7 @@ GNUNET_OS_check_helper_binary (const char *binary,
return GNUNET_YES;
}
#endif
- if (0 != STAT (p, &statbuf))
+ if (0 != stat (p, &statbuf))
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", p);
GNUNET_free (p);
@@ -973,16 +973,16 @@ GNUNET_OS_check_helper_binary (const char *binary,
// Start the child process.
if (! (CreateProcess (
- p, // current windows (2k3 and up can handle / instead of \ in paths))
- parameters, // execute dryrun/priviliege checking mode
- NULL, // Process handle not inheritable
- NULL, // Thread handle not inheritable
- FALSE, // Set handle inheritance to FALSE
- CREATE_DEFAULT_ERROR_MODE, // No creation flags
- NULL, // Use parent's environment block
- NULL, // Use parent's starting directory
- &start, // Pointer to STARTUPINFO structure
- &proc) // Pointer to PROCESS_INFORMATION structure
+ p, // current windows (2k3 and up can handle / instead of \ in paths))
+ parameters, // execute dryrun/priviliege checking mode
+ NULL, // Process handle not inheritable
+ NULL, // Thread handle not inheritable
+ FALSE, // Set handle inheritance to FALSE
+ CREATE_DEFAULT_ERROR_MODE, // No creation flags
+ NULL, // Use parent's environment block
+ NULL, // Use parent's starting directory
+ &start, // Pointer to STARTUPINFO structure
+ &proc) // Pointer to PROCESS_INFORMATION structure
))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index 03d4bde9e..17baa0df8 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -29,11 +29,13 @@
#include "disk.h"
#include <unistr.h>
-#define LOG(kind,...) GNUNET_log_from (kind, "util-os-priority", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-os-priority", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-os-priority", syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-os-priority", syscall)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-os-priority", syscall, filename)
+#define LOG_STRERROR_FILE(kind, syscall, filename) \
+ GNUNET_log_from_strerror_file (kind, "util-os-priority", syscall, filename)
#define GNUNET_OS_CONTROL_PIPE "GNUNET_OS_CONTROL_PIPE"
@@ -107,16 +109,12 @@ parent_control_handler (void *cls)
ssize_t ret;
pch = NULL;
- ret = GNUNET_DISK_file_read (control_pipe,
- &sig,
- sizeof (sig));
+ ret = GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig));
if (sizeof (sig) != ret)
{
if (-1 == ret)
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "GNUNET_DISK_file_read");
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Closing control pipe\n");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Closing control pipe\n");
GNUNET_DISK_file_close (control_pipe);
control_pipe = NULL;
GNUNET_SCHEDULER_cancel (spch);
@@ -124,16 +122,15 @@ parent_control_handler (void *cls)
return;
}
pipe_fd = getenv (GNUNET_OS_CONTROL_PIPE);
- GNUNET_assert ( (NULL == pipe_fd) ||
- (strlen (pipe_fd) <= 0) );
+ GNUNET_assert ((NULL == pipe_fd) || (strlen (pipe_fd) <= 0));
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Got control code %d from parent via pipe %s\n",
sig,
pipe_fd);
pch = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- control_pipe,
- &parent_control_handler,
- control_pipe);
+ control_pipe,
+ &parent_control_handler,
+ control_pipe);
GNUNET_SIGNAL_raise ((int) sig);
}
@@ -162,10 +159,10 @@ GNUNET_OS_install_parent_control_handler (void *cls)
return;
}
env_buf = getenv (GNUNET_OS_CONTROL_PIPE);
- if ( (NULL == env_buf) || (strlen (env_buf) <= 0) )
+ if ((NULL == env_buf) || (strlen (env_buf) <= 0))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Not installing a handler because $%s is empty\n",
+ "Not installing a handler because $%s is empty\n",
GNUNET_OS_CONTROL_PIPE);
putenv (GNUNET_OS_CONTROL_PIPE "=");
return;
@@ -174,35 +171,32 @@ GNUNET_OS_install_parent_control_handler (void *cls)
pipe_fd = strtoull (env_buf, &env_buf_end, 16);
if ((0 != errno) || (env_buf == env_buf_end))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "strtoull",
- env_buf);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "strtoull", env_buf);
putenv (GNUNET_OS_CONTROL_PIPE "=");
return;
}
-#if !defined (WINDOWS)
+#if ! defined(WINDOWS)
if (pipe_fd >= FD_SETSIZE)
#else
- if ((FILE_TYPE_UNKNOWN == GetFileType ((HANDLE) (uintptr_t) pipe_fd))
- && (0 != GetLastError ()))
+ if ((FILE_TYPE_UNKNOWN == GetFileType ((HANDLE) (uintptr_t) pipe_fd)) &&
+ (0 != GetLastError ()))
#endif
{
LOG (GNUNET_ERROR_TYPE_ERROR,
"GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n",
- env_buf);
+ env_buf);
putenv (GNUNET_OS_CONTROL_PIPE "=");
return;
}
#if WINDOWS
- control_pipe = GNUNET_DISK_get_handle_from_w32_handle ((HANDLE) (uintptr_t) pipe_fd);
+ control_pipe =
+ GNUNET_DISK_get_handle_from_w32_handle ((HANDLE) (uintptr_t) pipe_fd);
#else
control_pipe = GNUNET_DISK_get_handle_from_int_fd ((int) pipe_fd);
#endif
if (NULL == control_pipe)
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "open",
- env_buf);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
putenv (GNUNET_OS_CONTROL_PIPE "=");
return;
}
@@ -210,11 +204,10 @@ GNUNET_OS_install_parent_control_handler (void *cls)
"Adding parent control handler pipe `%s' to the scheduler\n",
env_buf);
pch = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- control_pipe,
- &parent_control_handler,
- control_pipe);
- spch = GNUNET_SCHEDULER_add_shutdown (&shutdown_pch,
+ control_pipe,
+ &parent_control_handler,
control_pipe);
+ spch = GNUNET_SCHEDULER_add_shutdown (&shutdown_pch, control_pipe);
putenv (GNUNET_OS_CONTROL_PIPE "=");
}
@@ -248,8 +241,7 @@ GNUNET_OS_process_current ()
* @return 0 on success, -1 on error
*/
int
-GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc,
- int sig)
+GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
{
int ret;
char csig;
@@ -258,19 +250,17 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc,
if (NULL != proc->control_pipe)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending signal %d to pid: %u via pipe\n",
- sig,
- proc->pid);
- ret = GNUNET_DISK_file_write (proc->control_pipe,
- &csig,
- sizeof (csig));
+ "Sending signal %d to pid: %u via pipe\n",
+ sig,
+ proc->pid);
+ ret = GNUNET_DISK_file_write (proc->control_pipe, &csig, sizeof (csig));
if (sizeof (csig) == ret)
return 0;
}
/* pipe failed or non-existent, try other methods */
switch (sig)
{
-#if !defined (WINDOWS)
+#if ! defined(WINDOWS)
case SIGHUP:
#endif
case SIGINT:
@@ -279,62 +269,62 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc,
#if (SIGTERM != GNUNET_TERM_SIG)
case GNUNET_TERM_SIG:
#endif
-#if defined(WINDOWS) && !defined(__CYGWIN__)
+#if defined(WINDOWS) && ! defined(__CYGWIN__)
+ {
+ DWORD exitcode;
+ int must_kill = GNUNET_YES;
+ if (0 != GetExitCodeProcess (proc->handle, &exitcode))
+ must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO;
+ if (GNUNET_YES == must_kill)
{
- DWORD exitcode;
- int must_kill = GNUNET_YES;
- if (0 != GetExitCodeProcess (proc->handle, &exitcode))
- must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO;
- if (GNUNET_YES == must_kill)
+ if (0 == SafeTerminateProcess (proc->handle, 0, 0))
{
- if (0 == SafeTerminateProcess (proc->handle, 0, 0))
+ DWORD error_code = GetLastError ();
+ if ((error_code != WAIT_TIMEOUT) &&
+ (error_code != ERROR_PROCESS_ABORTED))
{
- DWORD error_code = GetLastError ();
- if ( (error_code != WAIT_TIMEOUT) &&
- (error_code != ERROR_PROCESS_ABORTED) )
- {
- LOG ((error_code == ERROR_ACCESS_DENIED) ?
- GNUNET_ERROR_TYPE_INFO : GNUNET_ERROR_TYPE_WARNING,
- "SafeTermiateProcess failed with code %lu\n",
- error_code);
- /* The problem here is that a process that is already dying
+ LOG ((error_code == ERROR_ACCESS_DENIED) ? GNUNET_ERROR_TYPE_INFO
+ : GNUNET_ERROR_TYPE_WARNING,
+ "SafeTermiateProcess failed with code %lu\n",
+ error_code);
+ /* The problem here is that a process that is already dying
* might cause SafeTerminateProcess to fail with
* ERROR_ACCESS_DENIED, but the process WILL die eventually.
* If we really had a permissions problem, hanging up (which
* is what will happen in process_wait() in that case) is
* a valid option.
*/
- if (ERROR_ACCESS_DENIED == error_code)
- {
- errno = 0;
- }
- else
- {
- SetErrnoFromWinError (error_code);
- return -1;
- }
+ if (ERROR_ACCESS_DENIED == error_code)
+ {
+ errno = 0;
+ }
+ else
+ {
+ SetErrnoFromWinError (error_code);
+ return -1;
}
}
}
}
+ }
return 0;
#else
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Sending signal %d to pid: %u via system call\n",
sig,
proc->pid);
- return PLIBC_KILL (proc->pid, sig);
+ return kill (proc->pid, sig);
#endif
default:
-#if defined (WINDOWS)
+#if defined(WINDOWS)
errno = EINVAL;
return -1;
#else
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending signal %d to pid: %u via system call\n",
- sig,
- proc->pid);
- return PLIBC_KILL (proc->pid, sig);
+ "Sending signal %d to pid: %u via system call\n",
+ sig,
+ proc->pid);
+ return kill (proc->pid, sig);
#endif
}
}
@@ -348,7 +338,7 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc,
* @return the current process id
*/
pid_t
-GNUNET_OS_process_get_pid (struct GNUNET_OS_Process * proc)
+GNUNET_OS_process_get_pid (struct GNUNET_OS_Process *proc)
{
return proc->pid;
}
@@ -365,7 +355,7 @@ GNUNET_OS_process_destroy (struct GNUNET_OS_Process *proc)
{
if (NULL != proc->control_pipe)
GNUNET_DISK_file_close (proc->control_pipe);
-#if defined (WINDOWS)
+#if defined(WINDOWS)
if (NULL != proc->handle)
CloseHandle (proc->handle);
#endif
@@ -425,7 +415,8 @@ CreateCustomEnvTable (char **vars)
win32_env_table = GetEnvironmentStringsA ();
if (NULL == win32_env_table)
return NULL;
- for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++) ;
+ for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++)
+ ;
n_var = c;
index = GNUNET_malloc (sizeof (char *) * n_var);
for (c = 0; c < n_var; c++)
@@ -448,7 +439,7 @@ CreateCustomEnvTable (char **vars)
break;
}
}
- if (!found)
+ if (! found)
tablesize += len + 1;
ptr += len + 1;
}
@@ -476,7 +467,7 @@ CreateCustomEnvTable (char **vars)
break;
}
}
- if (!found)
+ if (! found)
{
strcpy (result_ptr, ptr);
result_ptr += len + 1;
@@ -519,17 +510,14 @@ CreateCustomEnvTable (char **vars)
* @param flags open flags (O_RDONLY, O_WRONLY)
*/
static void
-open_dev_null (int target_fd,
- int flags)
+open_dev_null (int target_fd, int flags)
{
int fd;
fd = open ("/dev/null", flags);
if (-1 == fd)
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "open",
- "/dev/null");
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", "/dev/null");
return;
}
if (fd == target_fd)
@@ -565,12 +553,12 @@ open_dev_null (int target_fd,
static struct GNUNET_OS_Process *
start_process (int pipe_control,
enum GNUNET_OS_InheritStdioFlags std_inheritance,
- struct GNUNET_DISK_PipeHandle *pipe_stdin,
- struct GNUNET_DISK_PipeHandle *pipe_stdout,
- struct GNUNET_DISK_PipeHandle *pipe_stderr,
- const SOCKTYPE *lsocks,
- const char *filename,
- char *const argv[])
+ struct GNUNET_DISK_PipeHandle *pipe_stdin,
+ struct GNUNET_DISK_PipeHandle *pipe_stdout,
+ struct GNUNET_DISK_PipeHandle *pipe_stderr,
+ const SOCKTYPE *lsocks,
+ const char *filename,
+ char *const argv[])
{
#ifndef MINGW
pid_t ret;
@@ -601,22 +589,19 @@ start_process (int pipe_control,
struct GNUNET_DISK_PipeHandle *childpipe;
int dup_childpipe_read_fd = -1;
- childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO,
- GNUNET_YES, GNUNET_NO);
+ childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
if (NULL == childpipe)
return NULL;
- childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe,
- GNUNET_DISK_PIPE_END_READ);
- childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe,
- GNUNET_DISK_PIPE_END_WRITE);
+ childpipe_read =
+ GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ);
+ childpipe_write =
+ GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE);
GNUNET_DISK_pipe_close (childpipe);
- if ( (NULL == childpipe_read) ||
- (NULL == childpipe_write) ||
- (GNUNET_OK !=
- GNUNET_DISK_internal_file_handle_ (childpipe_read,
- &childpipe_read_fd,
- sizeof (int))) ||
- (-1 == (dup_childpipe_read_fd = dup (childpipe_read_fd))))
+ if ((NULL == childpipe_read) || (NULL == childpipe_write) ||
+ (GNUNET_OK != GNUNET_DISK_internal_file_handle_ (childpipe_read,
+ &childpipe_read_fd,
+ sizeof (int))) ||
+ (-1 == (dup_childpipe_read_fd = dup (childpipe_read_fd))))
{
if (NULL != childpipe_read)
GNUNET_DISK_file_close (childpipe_read);
@@ -636,39 +621,48 @@ start_process (int pipe_control,
}
if (NULL != pipe_stdin)
{
- GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
- &fd_stdin_read, sizeof (int)));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE),
- &fd_stdin_write, sizeof (int)));
+ GNUNET_assert (
+ GNUNET_OK ==
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
+ &fd_stdin_read,
+ sizeof (int)));
+ GNUNET_assert (
+ GNUNET_OK ==
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE),
+ &fd_stdin_write,
+ sizeof (int)));
}
if (NULL != pipe_stdout)
{
- GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdout,
- GNUNET_DISK_PIPE_END_WRITE),
- &fd_stdout_write, sizeof (int)));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdout, GNUNET_DISK_PIPE_END_READ),
- &fd_stdout_read, sizeof (int)));
+ GNUNET_assert (
+ GNUNET_OK ==
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE),
+ &fd_stdout_write,
+ sizeof (int)));
+ GNUNET_assert (
+ GNUNET_OK ==
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_READ),
+ &fd_stdout_read,
+ sizeof (int)));
}
if (NULL != pipe_stderr)
{
- GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stderr,
- GNUNET_DISK_PIPE_END_READ),
- &fd_stderr_read, sizeof (int)));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stderr,
- GNUNET_DISK_PIPE_END_WRITE),
- &fd_stderr_write, sizeof (int)));
+ GNUNET_assert (
+ GNUNET_OK ==
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stderr, GNUNET_DISK_PIPE_END_READ),
+ &fd_stderr_read,
+ sizeof (int)));
+ GNUNET_assert (
+ GNUNET_OK ==
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stderr, GNUNET_DISK_PIPE_END_WRITE),
+ &fd_stderr_write,
+ sizeof (int)));
}
lscp = NULL;
ls = 0;
@@ -819,7 +813,7 @@ start_process (int pipe_control,
int argcount = 0;
struct GNUNET_OS_Process *gnunet_proc;
char path[MAX_PATH + 1];
- char *our_env[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+ char *our_env[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
char *env_block = NULL;
char *pathbuf;
DWORD pathbuf_len;
@@ -849,7 +843,8 @@ start_process (int pipe_control,
DWORD error_code;
DWORD create_no_window;
- if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename, GNUNET_NO, NULL))
+ if (GNUNET_SYSERR ==
+ GNUNET_OS_check_helper_binary (filename, GNUNET_NO, NULL))
return NULL; /* not executable */
/* Search in prefix dir (hopefully - the directory from which
@@ -861,9 +856,8 @@ start_process (int pipe_control,
pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0);
- alloc_len =
- pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
- strlen (libdir);
+ alloc_len = pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
+ strlen (libdir);
pathbuf = GNUNET_malloc (alloc_len * sizeof (char));
@@ -877,21 +871,23 @@ start_process (int pipe_control,
if (alloc_len != pathbuf_len - 1)
{
GNUNET_free (pathbuf);
- errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */
+ errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */
return NULL;
}
cmdlen = strlen (filename);
- if ( (cmdlen < 5) || (0 != strcmp (&filename[cmdlen - 4], ".exe")) )
+ if ((cmdlen < 5) || (0 != strcmp (&filename[cmdlen - 4], ".exe")))
GNUNET_asprintf (&non_const_filename, "%s.exe", filename);
else
GNUNET_asprintf (&non_const_filename, "%s", filename);
/* It could be in POSIX form, convert it to a DOS path early on */
- if (ERROR_SUCCESS != (lRet = plibc_conv_to_win_path (non_const_filename, win_path)))
+ if (ERROR_SUCCESS !=
+ (lRet = plibc_conv_to_win_path (non_const_filename, win_path)))
{
SetErrnoFromWinError (lRet);
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "plibc_conv_to_win_path",
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
+ "plibc_conv_to_win_path",
non_const_filename);
GNUNET_free (non_const_filename);
GNUNET_free (pathbuf);
@@ -899,7 +895,7 @@ start_process (int pipe_control,
}
GNUNET_free (non_const_filename);
non_const_filename = GNUNET_strdup (win_path);
- /* Check that this is the full path. If it isn't, search. */
+ /* Check that this is the full path. If it isn't, search. */
/* FIXME: convert it to wchar_t and use SearchPathW?
* Remember: arguments to _start_process() are technically in UTF-8...
*/
@@ -907,22 +903,27 @@ start_process (int pipe_control,
{
snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Using path `%s' as-is. PATH is %s\n", path, ptr);
+ "Using path `%s' as-is. PATH is %s\n",
+ path,
+ ptr);
}
- else if (!SearchPathA
- (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char),
- path, NULL))
+ else if (! SearchPathA (pathbuf,
+ non_const_filename,
+ NULL,
+ sizeof (path) / sizeof (char),
+ path,
+ NULL))
{
SetErrnoFromWinError (GetLastError ());
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
+ "SearchPath",
non_const_filename);
GNUNET_free (non_const_filename);
GNUNET_free (pathbuf);
return NULL;
}
else
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Found `%s' in PATH `%s'\n", path, pathbuf);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Found `%s' in PATH `%s'\n", path, pathbuf);
GNUNET_free (pathbuf);
GNUNET_free (non_const_filename);
@@ -966,8 +967,11 @@ start_process (int pipe_control,
while (*arg)
{
char arg_last_char = (*arg)[strlen (*arg) - 1];
- idx += sprintf (idx, "\"%s%s\"%s", *arg,
- arg_last_char == '\\' ? "\\" : "", *(arg + 1) ? " " : "");
+ idx += sprintf (idx,
+ "\"%s%s\"%s",
+ *arg,
+ arg_last_char == '\\' ? "\\" : "",
+ *(arg + 1) ? " " : "");
arg++;
}
@@ -984,9 +988,10 @@ start_process (int pipe_control,
GetHandleInformation (stdih, &stdif);
if (pipe_stdin != NULL)
{
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
- &stdin_handle, sizeof (HANDLE));
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
+ &stdin_handle,
+ sizeof (HANDLE));
start.hStdInput = stdin_handle;
}
else if (stdih)
@@ -1006,10 +1011,10 @@ start_process (int pipe_control,
GetHandleInformation (stdoh, &stdof);
if (NULL != pipe_stdout)
{
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdout,
- GNUNET_DISK_PIPE_END_WRITE),
- &stdout_handle, sizeof (HANDLE));
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (pipe_stdout, GNUNET_DISK_PIPE_END_WRITE),
+ &stdout_handle,
+ sizeof (HANDLE));
start.hStdOutput = stdout_handle;
}
else if (stdoh)
@@ -1043,12 +1048,15 @@ start_process (int pipe_control,
childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
if (NULL == childpipe)
return NULL;
- childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ);
- childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE);
+ childpipe_read =
+ GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ);
+ childpipe_write =
+ GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE);
GNUNET_DISK_pipe_close (childpipe);
if ((NULL == childpipe_read) || (NULL == childpipe_write) ||
(GNUNET_OK != GNUNET_DISK_internal_file_handle_ (childpipe_read,
- &childpipe_read_handle, sizeof (HANDLE))))
+ &childpipe_read_handle,
+ sizeof (HANDLE))))
{
if (childpipe_read)
GNUNET_DISK_file_close (childpipe_read);
@@ -1070,7 +1078,8 @@ start_process (int pipe_control,
if (lsocks != NULL && lsocks[0] != INVALID_SOCKET)
{
- lsocks_pipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
+ lsocks_pipe =
+ GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
if (lsocks_pipe == NULL)
{
@@ -1083,13 +1092,15 @@ start_process (int pipe_control,
}
return NULL;
}
- lsocks_write_fd = GNUNET_DISK_pipe_handle (lsocks_pipe,
- GNUNET_DISK_PIPE_END_WRITE);
+ lsocks_write_fd =
+ GNUNET_DISK_pipe_handle (lsocks_pipe, GNUNET_DISK_PIPE_END_WRITE);
GNUNET_DISK_internal_file_handle_ (lsocks_write_fd,
- &lsocks_write, sizeof (HANDLE));
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (lsocks_pipe, GNUNET_DISK_PIPE_END_READ),
- &lsocks_read, sizeof (HANDLE));
+ &lsocks_write,
+ sizeof (HANDLE));
+ GNUNET_DISK_internal_file_handle_ (
+ GNUNET_DISK_pipe_handle (lsocks_pipe, GNUNET_DISK_PIPE_END_READ),
+ &lsocks_read,
+ sizeof (HANDLE));
}
else
{
@@ -1103,7 +1114,7 @@ start_process (int pipe_control,
GNUNET_asprintf (&our_env[env_off++], "%s=", GNUNET_OS_CONTROL_PIPE);
GNUNET_asprintf (&our_env[env_off++], "%p", childpipe_read_handle);
}
- if ( (lsocks != NULL) && (lsocks[0] != INVALID_SOCKET))
+ if ((lsocks != NULL) && (lsocks[0] != INVALID_SOCKET))
{
/*This will tell the child that we're going to send lsocks over the pipe*/
GNUNET_asprintf (&our_env[env_off++], "%s=", "GNUNET_OS_READ_LSOCKS");
@@ -1115,10 +1126,14 @@ start_process (int pipe_control,
GNUNET_free_non_null (our_env[--env_off]);
wpath_len = 0;
- if (NULL == (wpath = u8_to_u16 ((uint8_t *) path, 1 + strlen (path), NULL, &wpath_len)))
+ if (NULL ==
+ (wpath =
+ u8_to_u16 ((uint8_t *) path, 1 + strlen (path), NULL, &wpath_len)))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to convert `%s' from UTF-8 to UTF-16: %d\n", path, errno);
+ "Failed to convert `%s' from UTF-8 to UTF-16: %d\n",
+ path,
+ errno);
GNUNET_free (env_block);
GNUNET_free (cmd);
if (lsocks_pipe)
@@ -1132,7 +1147,8 @@ start_process (int pipe_control,
}
wcmd_len = 0;
- if (NULL == (wcmd = u8_to_u16 ((uint8_t *) cmd, 1 + strlen (cmd), NULL, &wcmd_len)))
+ if (NULL ==
+ (wcmd = u8_to_u16 ((uint8_t *) cmd, 1 + strlen (cmd), NULL, &wcmd_len)))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Failed to convert `%s' from UTF-8 to UTF-16: %d\n",
@@ -1153,15 +1169,29 @@ start_process (int pipe_control,
create_no_window = 0;
{
- HANDLE console_input = CreateFile ("CONIN$", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+ HANDLE console_input = CreateFile ("CONIN$",
+ GENERIC_READ,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ 0,
+ NULL);
if (INVALID_HANDLE_VALUE == console_input)
create_no_window = CREATE_NO_WINDOW;
else
CloseHandle (console_input);
}
- bresult = CreateProcessW (wpath, wcmd, NULL, NULL, GNUNET_YES,
- create_no_window | CREATE_SUSPENDED, env_block, NULL, &start, &proc);
+ bresult = CreateProcessW (wpath,
+ wcmd,
+ NULL,
+ NULL,
+ GNUNET_YES,
+ create_no_window | CREATE_SUSPENDED,
+ env_block,
+ NULL,
+ &start,
+ &proc);
error_code = GetLastError ();
if ((NULL == pipe_stdin) && (stdih))
@@ -1174,7 +1204,7 @@ start_process (int pipe_control,
if (stdeh)
SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, stdef);
- if (!bresult)
+ if (! bresult)
LOG (GNUNET_ERROR_TYPE_ERROR,
"CreateProcess(%s, %s) failed: %lu\n",
path,
@@ -1190,7 +1220,7 @@ start_process (int pipe_control,
GNUNET_DISK_file_close (childpipe_read);
}
- if (!bresult)
+ if (! bresult)
{
if (GNUNET_YES == pipe_control)
{
@@ -1212,7 +1242,7 @@ start_process (int pipe_control,
ResumeThread (proc.hThread);
CloseHandle (proc.hThread);
- if ( (NULL == lsocks) || (INVALID_SOCKET == lsocks[0]) )
+ if ((NULL == lsocks) || (INVALID_SOCKET == lsocks[0]))
return gnunet_proc;
GNUNET_DISK_pipe_close_end (lsocks_pipe, GNUNET_DISK_PIPE_END_READ);
@@ -1227,25 +1257,29 @@ start_process (int pipe_control,
unsigned int i;
/* Tell the number of sockets */
- for (count = 0; lsocks && lsocks[count] != INVALID_SOCKET; count++);
+ for (count = 0; lsocks && lsocks[count] != INVALID_SOCKET; count++)
+ ;
wrote = GNUNET_DISK_file_write (lsocks_write_fd, &count, sizeof (count));
if (sizeof (count) != wrote)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to write %u count bytes to the child: %lu\n",
- sizeof (count), GetLastError ());
+ "Failed to write %u count bytes to the child: %lu\n",
+ sizeof (count),
+ GetLastError ());
break;
}
for (i = 0; lsocks && lsocks[i] != INVALID_SOCKET; i++)
{
WSAPROTOCOL_INFOA pi;
/* Get a socket duplication info */
- if (SOCKET_ERROR == WSADuplicateSocketA (lsocks[i], gnunet_proc->pid, &pi))
+ if (SOCKET_ERROR ==
+ WSADuplicateSocketA (lsocks[i], gnunet_proc->pid, &pi))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to duplicate an socket[%u]: %lu\n", i,
- GetLastError ());
+ "Failed to duplicate an socket[%u]: %lu\n",
+ i,
+ GetLastError ());
break;
}
/* Synchronous I/O is not nice, but we can't schedule this:
@@ -1261,8 +1295,10 @@ start_process (int pipe_control,
if (sizeof (size) != wrote)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to write %u size[%u] bytes to the child: %lu\n",
- sizeof (size), i, GetLastError ());
+ "Failed to write %u size[%u] bytes to the child: %lu\n",
+ sizeof (size),
+ i,
+ GetLastError ());
break;
}
/* Finally! Send the data */
@@ -1270,8 +1306,10 @@ start_process (int pipe_control,
if (sizeof (pi) != wrote)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to write %u socket[%u] bytes to the child: %lu\n",
- sizeof (pi), i, GetLastError ());
+ "Failed to write %u socket[%u] bytes to the child: %lu\n",
+ sizeof (pi),
+ i,
+ GetLastError ());
break;
}
}
@@ -1282,8 +1320,7 @@ start_process (int pipe_control,
*/
wrote = GNUNET_DISK_file_write (lsocks_write_fd, &count, sizeof (count));
fail = 0;
- }
- while (fail);
+ } while (fail);
GNUNET_DISK_file_sync (lsocks_write_fd);
GNUNET_DISK_pipe_close (lsocks_pipe);
@@ -1320,20 +1357,20 @@ start_process (int pipe_control,
struct GNUNET_OS_Process *
GNUNET_OS_start_process_vap (int pipe_control,
enum GNUNET_OS_InheritStdioFlags std_inheritance,
- struct GNUNET_DISK_PipeHandle *pipe_stdin,
- struct GNUNET_DISK_PipeHandle *pipe_stdout,
+ struct GNUNET_DISK_PipeHandle *pipe_stdin,
+ struct GNUNET_DISK_PipeHandle *pipe_stdout,
struct GNUNET_DISK_PipeHandle *pipe_stderr,
- const char *filename,
- char *const argv[])
+ const char *filename,
+ char *const argv[])
{
return start_process (pipe_control,
std_inheritance,
- pipe_stdin,
- pipe_stdout,
+ pipe_stdin,
+ pipe_stdout,
pipe_stderr,
- NULL,
- filename,
- argv);
+ NULL,
+ filename,
+ argv);
}
@@ -1352,10 +1389,11 @@ GNUNET_OS_start_process_vap (int pipe_control,
struct GNUNET_OS_Process *
GNUNET_OS_start_process_va (int pipe_control,
enum GNUNET_OS_InheritStdioFlags std_inheritance,
- struct GNUNET_DISK_PipeHandle *pipe_stdin,
+ struct GNUNET_DISK_PipeHandle *pipe_stdin,
struct GNUNET_DISK_PipeHandle *pipe_stdout,
struct GNUNET_DISK_PipeHandle *pipe_stderr,
- const char *filename, va_list va)
+ const char *filename,
+ va_list va)
{
struct GNUNET_OS_Process *ret;
va_list ap;
@@ -1375,11 +1413,11 @@ GNUNET_OS_start_process_va (int pipe_control,
va_end (ap);
ret = GNUNET_OS_start_process_vap (pipe_control,
std_inheritance,
- pipe_stdin,
- pipe_stdout,
+ pipe_stdin,
+ pipe_stdout,
pipe_stderr,
- filename,
- argv);
+ filename,
+ argv);
GNUNET_free (argv);
return ret;
}
@@ -1399,10 +1437,11 @@ GNUNET_OS_start_process_va (int pipe_control,
struct GNUNET_OS_Process *
GNUNET_OS_start_process (int pipe_control,
enum GNUNET_OS_InheritStdioFlags std_inheritance,
- struct GNUNET_DISK_PipeHandle *pipe_stdin,
+ struct GNUNET_DISK_PipeHandle *pipe_stdin,
struct GNUNET_DISK_PipeHandle *pipe_stdout,
struct GNUNET_DISK_PipeHandle *pipe_stderr,
- const char *filename, ...)
+ const char *filename,
+ ...)
{
struct GNUNET_OS_Process *ret;
va_list ap;
@@ -1411,7 +1450,7 @@ GNUNET_OS_start_process (int pipe_control,
ret = GNUNET_OS_start_process_va (pipe_control,
std_inheritance,
pipe_stdin,
- pipe_stdout,
+ pipe_stdout,
pipe_stderr,
filename,
ap);
@@ -1437,18 +1476,18 @@ GNUNET_OS_start_process (int pipe_control,
struct GNUNET_OS_Process *
GNUNET_OS_start_process_v (int pipe_control,
enum GNUNET_OS_InheritStdioFlags std_inheritance,
- const SOCKTYPE *lsocks,
+ const SOCKTYPE *lsocks,
const char *filename,
char *const argv[])
{
return start_process (pipe_control,
std_inheritance,
- NULL,
- NULL,
NULL,
- lsocks,
- filename,
- argv);
+ NULL,
+ NULL,
+ lsocks,
+ filename,
+ argv);
}
@@ -1473,8 +1512,9 @@ GNUNET_OS_start_process_v (int pipe_control,
struct GNUNET_OS_Process *
GNUNET_OS_start_process_s (int pipe_control,
unsigned int std_inheritance,
- const SOCKTYPE * lsocks,
- const char *filename, ...)
+ const SOCKTYPE *lsocks,
+ const char *filename,
+ ...)
{
va_list ap;
char **argv;
@@ -1502,29 +1542,28 @@ GNUNET_OS_start_process_s (int pipe_control,
{
if ('"' == *rpos)
{
- if (1 == quote_on)
- quote_on = 0;
- else
- quote_on = 1;
+ if (1 == quote_on)
+ quote_on = 0;
+ else
+ quote_on = 1;
}
- if ( (' ' == *rpos) && (0 == quote_on) )
+ if ((' ' == *rpos) && (0 == quote_on))
{
- if (NULL != last)
- argv_size++;
- last = NULL;
- rpos++;
- while (' ' == *rpos)
- rpos++;
+ if (NULL != last)
+ argv_size++;
+ last = NULL;
+ rpos++;
+ while (' ' == *rpos)
+ rpos++;
}
- if ( (NULL == last) && ('\0' != *rpos) ) // FIXME: == or !=?
- last = rpos;
+ if ((NULL == last) && ('\0' != *rpos)) // FIXME: == or !=?
+ last = rpos;
if ('\0' != *rpos)
- rpos++;
+ rpos++;
}
if (NULL != last)
argv_size++;
- }
- while (NULL != (arg = (va_arg (ap, const char*))));
+ } while (NULL != (arg = (va_arg (ap, const char *))));
va_end (ap);
argv = GNUNET_malloc (argv_size * sizeof (char *));
@@ -1541,47 +1580,49 @@ GNUNET_OS_start_process_s (int pipe_control,
{
if ('"' == *pos)
{
- if (1 == quote_on)
- quote_on = 0;
- else
- quote_on = 1;
+ if (1 == quote_on)
+ quote_on = 0;
+ else
+ quote_on = 1;
}
- if ( (' ' == *pos) && (0 == quote_on) )
+ if ((' ' == *pos) && (0 == quote_on))
{
- *pos = '\0';
- if (NULL != last)
- argv[argv_size++] = GNUNET_strdup (last);
- last = NULL;
- pos++;
- while (' ' == *pos)
- pos++;
+ *pos = '\0';
+ if (NULL != last)
+ argv[argv_size++] = GNUNET_strdup (last);
+ last = NULL;
+ pos++;
+ while (' ' == *pos)
+ pos++;
}
- if ( (NULL == last) && ('\0' != *pos)) // FIXME: == or !=?
- last = pos;
+ if ((NULL == last) && ('\0' != *pos)) // FIXME: == or !=?
+ last = pos;
if ('\0' != *pos)
- pos++;
+ pos++;
}
if (NULL != last)
argv[argv_size++] = GNUNET_strdup (last);
last = NULL;
GNUNET_free (cp);
- }
- while (NULL != (arg = (va_arg (ap, const char*))));
+ } while (NULL != (arg = (va_arg (ap, const char *))));
va_end (ap);
argv[argv_size] = NULL;
- for(i = 0; i < argv_size; i++)
+ for (i = 0; i < argv_size; i++)
{
len = strlen (argv[i]);
- if ( (argv[i][0] == '"') && (argv[i][len-1] == '"'))
+ if ((argv[i][0] == '"') && (argv[i][len - 1] == '"'))
{
memmove (&argv[i][0], &argv[i][1], len - 2);
- argv[i][len-2] = '\0';
+ argv[i][len - 2] = '\0';
}
}
binary_path = argv[0];
- proc = GNUNET_OS_start_process_v (pipe_control, std_inheritance, lsocks,
- binary_path, argv);
+ proc = GNUNET_OS_start_process_v (pipe_control,
+ std_inheritance,
+ lsocks,
+ binary_path,
+ argv);
while (argv_size > 0)
GNUNET_free (argv[--argv_size]);
GNUNET_free (argv);
@@ -1613,8 +1654,7 @@ process_status (struct GNUNET_OS_Process *proc,
ret = waitpid (proc->pid, &status, options);
if (ret < 0)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "waitpid");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
return GNUNET_SYSERR;
}
if (0 == ret)
@@ -1657,7 +1697,7 @@ process_status (struct GNUNET_OS_Process *proc,
}
#else
#ifndef WNOHANG
-#define WNOHANG 42 /* just a flag for W32, purely internal at this point */
+#define WNOHANG 42 /* just a flag for W32, purely internal at this point */
#endif
HANDLE h;
@@ -1669,7 +1709,8 @@ process_status (struct GNUNET_OS_Process *proc,
{
LOG (GNUNET_ERROR_TYPE_WARNING,
"Invalid process information {%d, %08X}\n",
- ret, h);
+ ret,
+ h);
return GNUNET_SYSERR;
}
if (h == NULL)
@@ -1720,10 +1761,7 @@ GNUNET_OS_process_status (struct GNUNET_OS_Process *proc,
enum GNUNET_OS_ProcessStatusType *type,
unsigned long *code)
{
- return process_status (proc,
- type,
- code,
- WNOHANG);
+ return process_status (proc, type, code, WNOHANG);
}
@@ -1741,10 +1779,7 @@ GNUNET_OS_process_wait_status (struct GNUNET_OS_Process *proc,
enum GNUNET_OS_ProcessStatusType *type,
unsigned long *code)
{
- return process_status (proc,
- type,
- code,
- 0);
+ return process_status (proc, type, code, 0);
}
@@ -1765,12 +1800,11 @@ GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc)
pid_t pid = proc->pid;
pid_t ret;
- while ( (pid != (ret = waitpid (pid, NULL, 0))) &&
- (EINTR == errno) ) ;
+ while ((pid != (ret = waitpid (pid, NULL, 0))) && (EINTR == errno))
+ ;
if (pid != ret)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "waitpid");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "waitpid");
return GNUNET_SYSERR;
}
return GNUNET_OK;
@@ -1782,7 +1816,8 @@ GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
"Invalid process information {%d, %08X}\n",
- proc->pid, h);
+ proc->pid,
+ h);
return GNUNET_SYSERR;
}
if (NULL == h)
@@ -1890,9 +1925,7 @@ cmd_read (void *cls)
cmd->rtask = NULL;
tc = GNUNET_SCHEDULER_get_task_context ();
- if (GNUNET_YES !=
- GNUNET_NETWORK_fdset_handle_isset (tc->read_ready,
- cmd->r))
+ if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r))
{
/* timeout */
proc = cmd->proc;
@@ -1901,8 +1934,8 @@ cmd_read (void *cls)
return;
}
ret = GNUNET_DISK_file_read (cmd->r,
- &cmd->buf[cmd->off],
- sizeof (cmd->buf) - cmd->off);
+ &cmd->buf[cmd->off],
+ sizeof (cmd->buf) - cmd->off);
if (ret <= 0)
{
if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf)))
@@ -1925,11 +1958,12 @@ cmd_read (void *cls)
cmd->off -= (end + 1 - cmd->buf);
end = memchr (cmd->buf, '\n', cmd->off);
}
- cmd->rtask
- = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
- (cmd->timeout),
- cmd->r,
- &cmd_read, cmd);
+ cmd->rtask =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining (
+ cmd->timeout),
+ cmd->r,
+ &cmd_read,
+ cmd);
}
@@ -1956,15 +1990,13 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc,
struct GNUNET_DISK_PipeHandle *opipe;
va_list ap;
- opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES,
- GNUNET_NO, GNUNET_YES);
+ opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
if (NULL == opipe)
return NULL;
va_start (ap, binary);
/* redirect stdout, don't inherit stderr/stdin */
- eip = GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL,
- opipe, NULL, binary,
- ap);
+ eip =
+ GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, opipe, NULL, binary, ap);
va_end (ap);
if (NULL == eip)
{
@@ -1978,12 +2010,8 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc,
cmd->opipe = opipe;
cmd->proc = proc;
cmd->proc_cls = proc_cls;
- cmd->r = GNUNET_DISK_pipe_handle (opipe,
- GNUNET_DISK_PIPE_END_READ);
- cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout,
- cmd->r,
- &cmd_read,
- cmd);
+ cmd->r = GNUNET_DISK_pipe_handle (opipe, GNUNET_DISK_PIPE_END_READ);
+ cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd);
return cmd;
}
diff --git a/src/util/perf_crypto_asymmetric.c b/src/util/perf_crypto_asymmetric.c
index a2cb3a6ce..f42706bda 100644
--- a/src/util/perf_crypto_asymmetric.c
+++ b/src/util/perf_crypto_asymmetric.c
@@ -49,7 +49,7 @@ log_duration (const char *cryptosystem,
sprintf (s, "%6s %15s", cryptosystem, description);
t = GNUNET_TIME_absolute_get_duration (start);
t = GNUNET_TIME_relative_divide (t, l);
- FPRINTF (stdout,
+ fprintf (stdout,
"%s: %10s\n",
s,
GNUNET_STRINGS_relative_time_to_string (t,
diff --git a/src/util/perf_crypto_ecc_dlog.c b/src/util/perf_crypto_ecc_dlog.c
index 59fa08d3a..2729241e2 100644
--- a/src/util/perf_crypto_ecc_dlog.c
+++ b/src/util/perf_crypto_ecc_dlog.c
@@ -130,7 +130,7 @@ main (int argc, char *argv[])
if (! gcry_check_version ("1.6.0"))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_
("libgcrypt has not the expected version (version %s is required).\n"),
"1.6.0");
diff --git a/src/util/plugin.c b/src/util/plugin.c
index 4b922340d..19169f070 100644
--- a/src/util/plugin.c
+++ b/src/util/plugin.c
@@ -28,7 +28,7 @@
#include <ltdl.h>
#include "gnunet_util_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util-plugin", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-plugin", __VA_ARGS__)
/**
* Linked list of active plugins.
@@ -82,8 +82,8 @@ plugin_init ()
err = lt_dlinit ();
if (err > 0)
{
- FPRINTF (stderr,
- _("Initialization of plugin mechanism failed: %s!\n"),
+ fprintf (stderr,
+ _ ("Initialization of plugin mechanism failed: %s!\n"),
lt_dlerror ());
return;
}
@@ -133,24 +133,21 @@ plugin_fini ()
* @return NULL if the symbol was not found
*/
static GNUNET_PLUGIN_Callback
-resolve_function (struct PluginList *plug,
- const char *name)
+resolve_function (struct PluginList *plug, const char *name)
{
char *initName;
void *mptr;
- GNUNET_asprintf (&initName,
- "_%s_%s",
- plug->name,
- name);
+ GNUNET_asprintf (&initName, "_%s_%s", plug->name, name);
mptr = lt_dlsym (plug->handle, &initName[1]);
if (NULL == mptr)
mptr = lt_dlsym (plug->handle, initName);
if (NULL == mptr)
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed to resolve method '%s' with error: %s\n"),
+ _ ("`%s' failed to resolve method '%s' with error: %s\n"),
"lt_dlsym",
- &initName[1], lt_dlerror ());
+ &initName[1],
+ lt_dlerror ());
GNUNET_free (initName);
return mptr;
}
@@ -214,7 +211,7 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg)
GNUNET_PLUGIN_Callback init;
void *ret;
- if (!initialized)
+ if (! initialized)
{
initialized = GNUNET_YES;
plugin_init ();
@@ -223,9 +220,10 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg)
if (libhandle == NULL)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' failed for library `%s' with error: %s\n"),
+ _ ("`%s' failed for library `%s' with error: %s\n"),
"lt_dlopenext",
- library_name, lt_dlerror ());
+ library_name,
+ lt_dlerror ());
return NULL;
}
plug = GNUNET_new (struct PluginList);
@@ -255,8 +253,7 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg)
* @return whatever the shutdown function returned
*/
void *
-GNUNET_PLUGIN_unload (const char *library_name,
- void *arg)
+GNUNET_PLUGIN_unload (const char *library_name, void *arg)
{
struct PluginList *pos;
struct PluginList *prev;
@@ -345,9 +342,9 @@ find_libraries (void *cls, const char *filename)
libname = slashpos + 1;
n = strlen (libname);
if (0 != strncmp (lac->basename, libname, strlen (lac->basename)))
- return GNUNET_OK; /* wrong name */
+ return GNUNET_OK; /* wrong name */
if ((n > 3) && (0 == strcmp (&libname[n - 3], ".la")))
- return GNUNET_OK; /* .la file */
+ return GNUNET_OK; /* .la file */
basename = GNUNET_strdup (libname);
if (NULL != (dot = strstr (basename, ".")))
*dot = '\0';
@@ -372,8 +369,10 @@ find_libraries (void *cls, const char *filename)
* @param cb_cls closure for @a cb
*/
void
-GNUNET_PLUGIN_load_all (const char *basename, void *arg,
- GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls)
+GNUNET_PLUGIN_load_all (const char *basename,
+ void *arg,
+ GNUNET_PLUGIN_LoaderCallback cb,
+ void *cb_cls)
{
struct LoadAllContext lac;
char *path;
@@ -382,7 +381,7 @@ GNUNET_PLUGIN_load_all (const char *basename, void *arg,
if (NULL == path)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not determine plugin installation path.\n"));
+ _ ("Could not determine plugin installation path.\n"));
return;
}
lac.basename = basename;
diff --git a/src/util/program.c b/src/util/program.c
index 73beb8d57..77f4ea3ae 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -201,18 +201,18 @@ GNUNET_PROGRAM_run2 (int argc,
/* prepare */
#if ENABLE_NLS
if (NULL != pd->gettext_domain)
+ {
+ setlocale (LC_ALL, "");
+ path = (NULL == pd->gettext_path)
+ ? GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR)
+ : GNUNET_strdup (pd->gettext_path);
+ if (NULL != path)
{
- setlocale (LC_ALL, "");
- path = (NULL == pd->gettext_path)
- ? GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR)
- : GNUNET_strdup (pd->gettext_path);
- if (NULL != path)
- {
- BINDTEXTDOMAIN (pd->gettext_domain, path);
- GNUNET_free (path);
- }
- textdomain (pd->gettext_domain);
+ bindtextdomain (pd->gettext_domain, path);
+ GNUNET_free (path);
}
+ textdomain (pd->gettext_domain);
+ }
#endif
cnt = 0;
while (NULL != options[cnt].name)
diff --git a/src/util/service.c b/src/util/service.c
index 73a73cbea..fba5a2f20 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -37,14 +37,13 @@
#endif
-#define LOG(kind,...) GNUNET_log_from (kind, "util-service", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-service", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, \
- "util-service", \
- syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-service", syscall)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file ( \
- kind, "util-service", syscall, filename)
+#define LOG_STRERROR_FILE(kind, syscall, filename) \
+ GNUNET_log_from_strerror_file (kind, "util-service", syscall, filename)
/**
@@ -77,7 +76,6 @@ struct ServiceListenContext
* Task scheduled to do the listening.
*/
struct GNUNET_SCHEDULER_Task *listen_task;
-
};
@@ -363,8 +361,7 @@ struct GNUNET_SERVICE_Client
static int
have_non_monitor_clients (struct GNUNET_SERVICE_Handle *sh)
{
- for (struct GNUNET_SERVICE_Client *client = sh->clients_head;
- NULL != client;
+ for (struct GNUNET_SERVICE_Client *client = sh->clients_head; NULL != client;
client = client->next)
{
if (client->is_monitor)
@@ -383,8 +380,7 @@ have_non_monitor_clients (struct GNUNET_SERVICE_Handle *sh)
* @param sr reason for suspending accepting connections
*/
static void
-do_suspend (struct GNUNET_SERVICE_Handle *sh,
- enum SuspendReason sr)
+do_suspend (struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
{
struct ServiceListenContext *slc;
@@ -426,8 +422,7 @@ service_shutdown (void *cls)
break;
case GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN:
if (0 == (sh->suspend_state & SUSPEND_STATE_SHUTDOWN))
- do_suspend (sh,
- SUSPEND_STATE_SHUTDOWN);
+ do_suspend (sh, SUSPEND_STATE_SHUTDOWN);
if (GNUNET_NO == have_non_monitor_clients (sh))
GNUNET_SERVICE_shutdown (sh);
break;
@@ -451,8 +446,7 @@ check_ipv4_listed (const struct GNUNET_STRINGS_IPv4NetworkPolicy *list,
if (NULL == list)
return GNUNET_NO;
i = 0;
- while ( (0 != list[i].network.s_addr) ||
- (0 != list[i].netmask.s_addr) )
+ while ((0 != list[i].network.s_addr) || (0 != list[i].netmask.s_addr))
{
if ((add->s_addr & list[i].netmask.s_addr) ==
(list[i].network.s_addr & list[i].netmask.s_addr))
@@ -480,7 +474,7 @@ check_ipv6_listed (const struct GNUNET_STRINGS_IPv6NetworkPolicy *list,
if (NULL == list)
return GNUNET_NO;
i = 0;
- NEXT:
+NEXT:
while (0 != GNUNET_is_zero (&list[i].network))
{
for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++)
@@ -518,22 +512,17 @@ do_send (void *cls)
client->send_task = NULL;
buf = (const char *) client->msg;
left = ntohs (client->msg->size) - client->msg_pos;
- ret = GNUNET_NETWORK_socket_send (client->sock,
- &buf[client->msg_pos],
- left);
+ ret = GNUNET_NETWORK_socket_send (client->sock, &buf[client->msg_pos], left);
GNUNET_assert (ret <= (ssize_t) left);
if (0 == ret)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "no data send");
- GNUNET_MQ_inject_error (client->mq,
- GNUNET_MQ_ERROR_WRITE);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "no data send");
+ GNUNET_MQ_inject_error (client->mq, GNUNET_MQ_ERROR_WRITE);
return;
}
if (-1 == ret)
{
- if ( (EAGAIN == errno) ||
- (EINTR == errno) )
+ if ((EAGAIN == errno) || (EINTR == errno))
{
/* ignore */
ret = 0;
@@ -541,13 +530,11 @@ do_send (void *cls)
else
{
if (EPIPE != errno)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "send");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
LOG (GNUNET_ERROR_TYPE_DEBUG,
"socket send returned with error code %i",
errno);
- GNUNET_MQ_inject_error (client->mq,
- GNUNET_MQ_ERROR_WRITE);
+ GNUNET_MQ_inject_error (client->mq, GNUNET_MQ_ERROR_WRITE);
return;
}
}
@@ -559,11 +546,11 @@ do_send (void *cls)
if (left > (size_t) ret)
{
GNUNET_assert (NULL == client->drop_task);
- client->send_task
- = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &do_send,
- client);
+ client->send_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ client->sock,
+ &do_send,
+ client);
return;
}
GNUNET_MQ_impl_send_continue (client->mq);
@@ -595,11 +582,11 @@ service_mq_send (struct GNUNET_MQ_Handle *mq,
ntohs (msg->size));
client->msg = msg;
client->msg_pos = 0;
- client->send_task
- = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &do_send,
- client);
+ client->send_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ client->sock,
+ &do_send,
+ client);
}
@@ -610,8 +597,7 @@ service_mq_send (struct GNUNET_MQ_Handle *mq,
* @param impl_state state specific to the implementation
*/
static void
-service_mq_cancel (struct GNUNET_MQ_Handle *mq,
- void *impl_state)
+service_mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
{
struct GNUNET_SERVICE_Client *client = impl_state;
@@ -633,14 +619,12 @@ service_mq_cancel (struct GNUNET_MQ_Handle *mq,
* @param error error code
*/
static void
-service_mq_error_handler (void *cls,
- enum GNUNET_MQ_Error error)
+service_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
{
struct GNUNET_SERVICE_Client *client = cls;
struct GNUNET_SERVICE_Handle *sh = client->sh;
- if ( (GNUNET_MQ_ERROR_NO_MATCH == error) &&
- (GNUNET_NO == sh->require_found) )
+ if ((GNUNET_MQ_ERROR_NO_MATCH == error) && (GNUNET_NO == sh->require_found))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"No handler for message of type %u found\n",
@@ -662,18 +646,20 @@ warn_no_client_continue (void *cls)
{
struct GNUNET_SERVICE_Client *client = cls;
- GNUNET_break (0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */
- client->warn_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &warn_no_client_continue,
- client);
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _ (
- "Processing code for message of type %u did not call `GNUNET_SERVICE_client_continue' after %s\n"),
- (unsigned int) client->warn_type,
- GNUNET_STRINGS_relative_time_to_string (
- GNUNET_TIME_absolute_get_duration (client->warn_start),
- GNUNET_YES));
+ GNUNET_break (
+ 0 !=
+ client->warn_type); /* type should never be 0 here, as we don't use 0 */
+ client->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &warn_no_client_continue,
+ client);
+ LOG (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "Processing code for message of type %u did not call `GNUNET_SERVICE_client_continue' after %s\n"),
+ (unsigned int) client->warn_type,
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (
+ client->warn_start),
+ GNUNET_YES));
}
@@ -689,8 +675,7 @@ warn_no_client_continue (void *cls)
* @return #GNUNET_OK on success, #GNUNET_SYSERR if the client was dropped
*/
static int
-service_client_mst_cb (void *cls,
- const struct GNUNET_MessageHeader *message)
+service_client_mst_cb (void *cls, const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVICE_Client *client = cls;
@@ -703,12 +688,10 @@ service_client_mst_cb (void *cls,
client->warn_type = ntohs (message->type);
client->warn_start = GNUNET_TIME_absolute_get ();
GNUNET_assert (NULL == client->warn_task);
- client->warn_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &warn_no_client_continue,
- client);
- GNUNET_MQ_inject_message (client->mq,
- message);
+ client->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &warn_no_client_continue,
+ client);
+ GNUNET_MQ_inject_message (client->mq, message);
if (NULL != client->drop_task)
return GNUNET_SYSERR;
return GNUNET_OK;
@@ -728,10 +711,7 @@ service_client_recv (void *cls)
int ret;
client->recv_task = NULL;
- ret = GNUNET_MST_read (client->mst,
- client->sock,
- GNUNET_NO,
- GNUNET_YES);
+ ret = GNUNET_MST_read (client->mst, client->sock, GNUNET_NO, GNUNET_YES);
if (GNUNET_SYSERR == ret)
{
/* client closed connection (or IO error) */
@@ -751,11 +731,11 @@ service_client_recv (void *cls)
if (NULL != client->recv_task)
return;
/* MST needs more data, re-schedule read job */
- client->recv_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &service_client_recv,
- client);
+ client->recv_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ client->sock,
+ &service_client_recv,
+ client);
}
@@ -773,9 +753,7 @@ start_client (struct GNUNET_SERVICE_Handle *sh,
struct GNUNET_SERVICE_Client *client;
client = GNUNET_new (struct GNUNET_SERVICE_Client);
- GNUNET_CONTAINER_DLL_insert (sh->clients_head,
- sh->clients_tail,
- client);
+ GNUNET_CONTAINER_DLL_insert (sh->clients_head, sh->clients_tail, client);
client->sh = sh;
client->sock = csock;
client->mq = GNUNET_MQ_queue_for_callbacks (&service_mq_send,
@@ -785,19 +763,15 @@ start_client (struct GNUNET_SERVICE_Handle *sh,
sh->handlers,
&service_mq_error_handler,
client);
- client->mst = GNUNET_MST_create (&service_client_mst_cb,
- client);
+ client->mst = GNUNET_MST_create (&service_client_mst_cb, client);
if (NULL != sh->connect_cb)
- client->user_context = sh->connect_cb (sh->cb_cls,
- client,
- client->mq);
- GNUNET_MQ_set_handlers_closure (client->mq,
- client->user_context);
- client->recv_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &service_client_recv,
- client);
+ client->user_context = sh->connect_cb (sh->cb_cls, client, client->mq);
+ GNUNET_MQ_set_handlers_closure (client->mq, client->user_context);
+ client->recv_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ client->sock,
+ &service_client_recv,
+ client);
}
@@ -830,11 +804,9 @@ accept_client (void *cls)
if (NULL == sock)
{
if (EMFILE == errno)
- do_suspend (sh,
- SUSPEND_STATE_EMFILE);
+ do_suspend (sh, SUSPEND_STATE_EMFILE);
else if (EAGAIN != errno)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "accept");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept");
break;
}
switch (sa.ss_family)
@@ -842,26 +814,22 @@ accept_client (void *cls)
case AF_INET:
GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
v4 = (const struct sockaddr_in *) &sa;
- ok = ( ( (NULL == sh->v4_allowed) ||
- (check_ipv4_listed (sh->v4_allowed,
- &v4->sin_addr))) &&
- ( (NULL == sh->v4_denied) ||
- (! check_ipv4_listed (sh->v4_denied,
- &v4->sin_addr)) ) );
+ ok = (((NULL == sh->v4_allowed) ||
+ (check_ipv4_listed (sh->v4_allowed, &v4->sin_addr))) &&
+ ((NULL == sh->v4_denied) ||
+ (! check_ipv4_listed (sh->v4_denied, &v4->sin_addr))));
break;
case AF_INET6:
GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
v6 = (const struct sockaddr_in6 *) &sa;
- ok = ( ( (NULL == sh->v6_allowed) ||
- (check_ipv6_listed (sh->v6_allowed,
- &v6->sin6_addr))) &&
- ( (NULL == sh->v6_denied) ||
- (! check_ipv6_listed (sh->v6_denied,
- &v6->sin6_addr)) ) );
+ ok = (((NULL == sh->v6_allowed) ||
+ (check_ipv6_listed (sh->v6_allowed, &v6->sin6_addr))) &&
+ ((NULL == sh->v6_denied) ||
+ (! check_ipv6_listed (sh->v6_denied, &v6->sin6_addr))));
break;
#ifndef WINDOWS
case AF_UNIX:
- ok = GNUNET_OK; /* controlled using file-system ACL now */
+ ok = GNUNET_OK; /* controlled using file-system ACL now */
break;
#endif
default:
@@ -874,26 +842,22 @@ accept_client (void *cls)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Service rejected incoming connection from %s due to policy.\n",
- GNUNET_a2s ((const struct sockaddr *) &sa,
- addrlen));
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (sock));
+ GNUNET_a2s ((const struct sockaddr *) &sa, addrlen));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
continue;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Service accepted incoming connection from %s.\n",
- GNUNET_a2s ((const struct sockaddr *) &sa,
- addrlen));
- start_client (slc->sh,
- sock);
+ GNUNET_a2s ((const struct sockaddr *) &sa, addrlen));
+ start_client (slc->sh, sock);
}
if (0 != sh->suspend_state)
return;
- slc->listen_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- slc->listen_socket,
- &accept_client,
- slc);
+ slc->listen_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ slc->listen_socket,
+ &accept_client,
+ slc);
}
@@ -905,24 +869,22 @@ accept_client (void *cls)
* or #SUSPEND_STATE_NONE on first startup
*/
static void
-do_resume (struct GNUNET_SERVICE_Handle *sh,
- enum SuspendReason sr)
+do_resume (struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
{
struct ServiceListenContext *slc;
- GNUNET_assert ( (SUSPEND_STATE_NONE == sr) ||
- (0 != (sh->suspend_state & sr)) );
+ GNUNET_assert ((SUSPEND_STATE_NONE == sr) || (0 != (sh->suspend_state & sr)));
sh->suspend_state -= sr;
if (SUSPEND_STATE_NONE != sh->suspend_state)
return;
for (slc = sh->slc_head; NULL != slc; slc = slc->next)
{
GNUNET_assert (NULL == slc->listen_task);
- slc->listen_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- slc->listen_socket,
- &accept_client,
- slc);
+ slc->listen_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ slc->listen_socket,
+ &accept_client,
+ slc);
}
}
@@ -940,22 +902,18 @@ service_main (void *cls)
struct GNUNET_SERVICE_Handle *sh = cls;
if (GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN != sh->options)
- GNUNET_SCHEDULER_add_shutdown (&service_shutdown,
- sh);
- do_resume (sh,
- SUSPEND_STATE_NONE);
+ GNUNET_SCHEDULER_add_shutdown (&service_shutdown, sh);
+ do_resume (sh, SUSPEND_STATE_NONE);
if (-1 != sh->ready_confirm_fd)
{
- GNUNET_break (1 == WRITE (sh->ready_confirm_fd, ".", 1));
- GNUNET_break (0 == CLOSE (sh->ready_confirm_fd));
+ GNUNET_break (1 == write (sh->ready_confirm_fd, ".", 1));
+ GNUNET_break (0 == close (sh->ready_confirm_fd));
sh->ready_confirm_fd = -1;
}
if (NULL != sh->service_init_cb)
- sh->service_init_cb (sh->cb_cls,
- sh->cfg,
- sh);
+ sh->service_init_cb (sh->cb_cls, sh->cfg, sh);
}
@@ -975,9 +933,7 @@ process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret,
{
char *opt;
- if (! GNUNET_CONFIGURATION_have_value (sh->cfg,
- sh->service_name,
- option))
+ if (! GNUNET_CONFIGURATION_have_value (sh->cfg, sh->service_name, option))
{
*ret = NULL;
return GNUNET_OK;
@@ -1018,9 +974,7 @@ process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret,
{
char *opt;
- if (! GNUNET_CONFIGURATION_have_value (sh->cfg,
- sh->service_name,
- option))
+ if (! GNUNET_CONFIGURATION_have_value (sh->cfg, sh->service_name, option))
{
*ret = NULL;
return GNUNET_OK;
@@ -1066,9 +1020,7 @@ add_unixpath (struct sockaddr **saddrs,
un = GNUNET_new (struct sockaddr_un);
un->sun_family = AF_UNIX;
- GNUNET_strlcpy (un->sun_path,
- unixpath,
- sizeof (un->sun_path));
+ GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path));
#ifdef LINUX
if (GNUNET_YES == abstract)
un->sun_path[0] = '\0';
@@ -1132,24 +1084,18 @@ get_server_addresses (const char *service_name,
*addr_lens = NULL;
desc = NULL;
disablev6 = GNUNET_NO;
- if ( (GNUNET_NO ==
- GNUNET_NETWORK_test_pf (PF_INET6)) ||
- (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- service_name,
- "DISABLEV6") ) )
+ if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
+ (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, service_name, "DISABLEV6")))
disablev6 = GNUNET_YES;
port = 0;
- if (GNUNET_CONFIGURATION_have_value (cfg,
- service_name,
- "PORT"))
+ if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- service_name,
- "PORT",
- &port))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
+ service_name,
+ "PORT",
+ &port))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_ ("Require valid port number for service `%s' in configuration!\n"),
@@ -1164,9 +1110,7 @@ get_server_addresses (const char *service_name,
}
}
- if (GNUNET_CONFIGURATION_have_value (cfg,
- service_name,
- "BINDTO"))
+ if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
{
GNUNET_break (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (cfg,
@@ -1181,14 +1125,11 @@ get_server_addresses (const char *service_name,
abstract = GNUNET_NO;
#ifdef AF_UNIX
if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (cfg,
- service_name,
- "UNIXPATH")) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- service_name,
- "UNIXPATH",
- &unixpath)) &&
+ GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
+ service_name,
+ "UNIXPATH",
+ &unixpath)) &&
(0 < strlen (unixpath)))
{
/* probe UNIX support */
@@ -1201,9 +1142,7 @@ get_server_addresses (const char *service_name,
unixpath,
(unsigned long long) sizeof (s_un.sun_path));
unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
- LOG (GNUNET_ERROR_TYPE_INFO,
- _ ("Using `%s' instead\n"),
- unixpath);
+ LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath);
}
#ifdef LINUX
abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
@@ -1212,27 +1151,19 @@ get_server_addresses (const char *service_name,
if (GNUNET_SYSERR == abstract)
abstract = GNUNET_NO;
#endif
- if ( (GNUNET_YES != abstract) &&
- (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (unixpath)) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "mkdir",
- unixpath);
+ if ((GNUNET_YES != abstract) &&
+ (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath);
}
if (NULL != unixpath)
{
- desc = GNUNET_NETWORK_socket_create (AF_UNIX,
- SOCK_STREAM,
- 0);
+ desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
if (NULL == desc)
{
- if ((ENOBUFS == errno) ||
- (ENOMEM == errno) ||
- (ENFILE == errno) ||
+ if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
(EACCES == errno))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "socket");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
GNUNET_free_non_null (hostname);
GNUNET_free (unixpath);
return GNUNET_SYSERR;
@@ -1241,14 +1172,13 @@ get_server_addresses (const char *service_name,
_ (
"Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
service_name,
- STRERROR (errno));
+ strerror (errno));
GNUNET_free (unixpath);
unixpath = NULL;
}
else
{
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (desc));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
desc = NULL;
}
}
@@ -1265,14 +1195,9 @@ get_server_addresses (const char *service_name,
}
if (0 == port)
{
- saddrs = GNUNET_new_array (2,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (2,
- socklen_t);
- add_unixpath (saddrs,
- saddrlens,
- unixpath,
- abstract);
+ saddrs = GNUNET_new_array (2, struct sockaddr *);
+ saddrlens = GNUNET_new_array (2, socklen_t);
+ add_unixpath (saddrs, saddrlens, unixpath, abstract);
GNUNET_free_non_null (unixpath);
GNUNET_free_non_null (hostname);
*addrs = saddrs;
@@ -1286,16 +1211,11 @@ get_server_addresses (const char *service_name,
"Resolving `%s' since that is where `%s' will bind to.\n",
hostname,
service_name);
- memset (&hints,
- 0,
- sizeof (struct addrinfo));
+ memset (&hints, 0, sizeof (struct addrinfo));
if (disablev6)
hints.ai_family = AF_INET;
hints.ai_protocol = IPPROTO_TCP;
- if ((0 != (ret = getaddrinfo (hostname,
- NULL,
- &hints,
- &res))) ||
+ if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
(NULL == res))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -1311,8 +1231,7 @@ get_server_addresses (const char *service_name,
while (NULL != (pos = next))
{
next = pos->ai_next;
- if ( (disablev6) &&
- (pos->ai_family == AF_INET6) )
+ if ((disablev6) && (pos->ai_family == AF_INET6))
continue;
i++;
}
@@ -1330,45 +1249,34 @@ get_server_addresses (const char *service_name,
resi = i;
if (NULL != unixpath)
resi++;
- saddrs = GNUNET_new_array (resi + 1,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (resi + 1,
- socklen_t);
+ saddrs = GNUNET_new_array (resi + 1, struct sockaddr *);
+ saddrlens = GNUNET_new_array (resi + 1, socklen_t);
i = 0;
if (NULL != unixpath)
{
- add_unixpath (saddrs,
- saddrlens,
- unixpath,
- abstract);
+ add_unixpath (saddrs, saddrlens, unixpath, abstract);
i++;
}
next = res;
while (NULL != (pos = next))
{
next = pos->ai_next;
- if ( (disablev6) &&
- (AF_INET6 == pos->ai_family) )
+ if ((disablev6) && (AF_INET6 == pos->ai_family))
continue;
- if ( (IPPROTO_TCP != pos->ai_protocol) &&
- (0 != pos->ai_protocol) )
- continue; /* not TCP */
- if ( (SOCK_STREAM != pos->ai_socktype) &&
- (0 != pos->ai_socktype) )
- continue; /* huh? */
+ if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
+ continue; /* not TCP */
+ if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
+ continue; /* huh? */
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Service `%s' will bind to `%s'\n",
service_name,
- GNUNET_a2s (pos->ai_addr,
- pos->ai_addrlen));
+ GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
if (AF_INET == pos->ai_family)
{
GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
saddrlens[i] = pos->ai_addrlen;
saddrs[i] = GNUNET_malloc (saddrlens[i]);
- GNUNET_memcpy (saddrs[i],
- pos->ai_addr,
- saddrlens[i]);
+ GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
}
else
@@ -1377,9 +1285,7 @@ get_server_addresses (const char *service_name,
GNUNET_assert (sizeof (struct sockaddr_in6) == pos->ai_addrlen);
saddrlens[i] = pos->ai_addrlen;
saddrs[i] = GNUNET_malloc (saddrlens[i]);
- GNUNET_memcpy (saddrs[i],
- pos->ai_addr,
- saddrlens[i]);
+ GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
}
i++;
@@ -1398,16 +1304,11 @@ get_server_addresses (const char *service_name,
if (NULL != unixpath)
resi++;
i = 0;
- saddrs = GNUNET_new_array (resi + 1,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (resi + 1,
- socklen_t);
+ saddrs = GNUNET_new_array (resi + 1, struct sockaddr *);
+ saddrlens = GNUNET_new_array (resi + 1, socklen_t);
if (NULL != unixpath)
{
- add_unixpath (saddrs,
- saddrlens,
- unixpath,
- abstract);
+ add_unixpath (saddrs, saddrlens, unixpath, abstract);
i++;
}
saddrlens[i] = sizeof (struct sockaddr_in);
@@ -1424,17 +1325,12 @@ get_server_addresses (const char *service_name,
resi = 2;
if (NULL != unixpath)
resi++;
- saddrs = GNUNET_new_array (resi + 1,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (resi + 1,
- socklen_t);
+ saddrs = GNUNET_new_array (resi + 1, struct sockaddr *);
+ saddrlens = GNUNET_new_array (resi + 1, socklen_t);
i = 0;
if (NULL != unixpath)
{
- add_unixpath (saddrs,
- saddrlens,
- unixpath,
- abstract);
+ add_unixpath (saddrs, saddrlens, unixpath, abstract);
i++;
}
saddrlens[i] = sizeof (struct sockaddr_in6);
@@ -1480,18 +1376,14 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
HANDLE lsocks_pipe;
env_buf = getenv ("GNUNET_OS_READ_LSOCKS");
- if ( (NULL == env_buf) ||
- (strlen (env_buf) <= 0) )
+ if ((NULL == env_buf) || (strlen (env_buf) <= 0))
return NULL;
/* Using W32 API directly here, because this pipe will
* never be used outside of this function, and it's just too much of a bother
* to create a GNUnet API that boxes a HANDLE (the way it is done with socks)
*/
- lsocks_pipe = (HANDLE) strtoul (env_buf,
- NULL,
- 10);
- if ( (0 == lsocks_pipe) ||
- (INVALID_HANDLE_VALUE == lsocks_pipe))
+ lsocks_pipe = (HANDLE) strtoul (env_buf, NULL, 10);
+ if ((0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe))
return NULL;
fail = 1;
do
@@ -1500,17 +1392,10 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
int fail2;
DWORD rd;
- ret = ReadFile (lsocks_pipe,
- &count,
- sizeof (count),
- &rd,
- NULL);
- if ( (0 == ret) ||
- (sizeof (count) != rd) ||
- (0 == count) )
+ ret = ReadFile (lsocks_pipe, &count, sizeof (count), &rd, NULL);
+ if ((0 == ret) || (sizeof (count) != rd) || (0 == count))
break;
- lsocks = GNUNET_new_array (count + 1,
- struct GNUNET_NETWORK_Handle *);
+ lsocks = GNUNET_new_array (count + 1, struct GNUNET_NETWORK_Handle *);
fail2 = 1;
for (i = 0; i < count; i++)
@@ -1519,22 +1404,11 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
uint64_t size;
SOCKET s;
- ret = ReadFile (lsocks_pipe,
- &size,
- sizeof (size),
- &rd,
- NULL);
- if ( (0 == ret) ||
- (sizeof (size) != rd) ||
- (sizeof (pi) != size) )
+ ret = ReadFile (lsocks_pipe, &size, sizeof (size), &rd, NULL);
+ if ((0 == ret) || (sizeof (size) != rd) || (sizeof (pi) != size))
break;
- ret = ReadFile (lsocks_pipe,
- &pi,
- sizeof (pi),
- &rd,
- NULL);
- if ( (0 == ret) ||
- (sizeof (pi) != rd))
+ ret = ReadFile (lsocks_pipe, &pi, sizeof (pi), &rd, NULL);
+ if ((0 == ret) || (sizeof (pi) != rd))
break;
s = WSASocketA (pi.iAddressFamily,
pi.iSocketType,
@@ -1552,8 +1426,7 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
break;
lsocks[count] = NULL;
fail = 0;
- }
- while (fail);
+ } while (fail);
CloseHandle (lsocks_pipe);
if (fail)
@@ -1561,8 +1434,7 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
LOG (GNUNET_ERROR_TYPE_ERROR,
_ ("Could not access a pre-bound socket, will try to bind myself\n"));
for (i = 0; (i < count) && (NULL != lsocks[i]); i++)
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (lsocks[i]));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (lsocks[i]));
GNUNET_free (lsocks);
return NULL;
}
@@ -1579,8 +1451,7 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
* @return NULL on error, otherwise the listen socket
*/
static struct GNUNET_NETWORK_Handle *
-open_listen_socket (const struct sockaddr *server_addr,
- socklen_t socklen)
+open_listen_socket (const struct sockaddr *server_addr, socklen_t socklen)
{
struct GNUNET_NETWORK_Handle *sock;
uint16_t port;
@@ -1602,20 +1473,15 @@ open_listen_socket (const struct sockaddr *server_addr,
port = 0;
break;
}
- sock = GNUNET_NETWORK_socket_create (server_addr->sa_family,
- SOCK_STREAM,
- 0);
+ sock = GNUNET_NETWORK_socket_create (server_addr->sa_family, SOCK_STREAM, 0);
if (NULL == sock)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "socket");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
errno = 0;
return NULL;
}
/* bind the socket */
- if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock,
- server_addr,
- socklen))
+ if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, server_addr, socklen))
{
eno = errno;
if (EADDRINUSE != errno)
@@ -1631,8 +1497,7 @@ open_listen_socket (const struct sockaddr *server_addr,
port,
(AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
else
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "bind");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
eno = 0;
}
else
@@ -1640,7 +1505,8 @@ open_listen_socket (const struct sockaddr *server_addr,
if (0 != port)
LOG (GNUNET_ERROR_TYPE_WARNING,
_ ("`%s' failed for port %d (%s): address already in use\n"),
- "bind", port,
+ "bind",
+ port,
(AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
else if (AF_UNIX == server_addr->sa_family)
{
@@ -1650,18 +1516,14 @@ open_listen_socket (const struct sockaddr *server_addr,
GNUNET_a2s (server_addr, socklen));
}
}
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (sock));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
errno = eno;
return NULL;
}
- if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock,
- 5))
+ if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "listen");
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (sock));
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "listen");
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
errno = 0;
return NULL;
}
@@ -1701,16 +1563,12 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
char dummy[2];
#endif
- if (GNUNET_CONFIGURATION_have_value
- (sh->cfg,
- sh->service_name,
- "TOLERANT"))
+ if (GNUNET_CONFIGURATION_have_value (sh->cfg, sh->service_name, "TOLERANT"))
{
if (GNUNET_SYSERR ==
- (tolerant =
- GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
- sh->service_name,
- "TOLERANT")))
+ (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
+ sh->service_name,
+ "TOLERANT")))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_ ("Specified value for `%s' of service `%s' is invalid\n"),
@@ -1725,25 +1583,16 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
lsocks = NULL;
#ifndef MINGW
errno = 0;
- if ( (NULL != (nfds = getenv ("LISTEN_FDS"))) &&
- (1 == SSCANF (nfds,
- "%u%1s",
- &cnt,
- dummy)) &&
- (cnt > 0) &&
- (cnt < FD_SETSIZE) &&
- (cnt + 4 < FD_SETSIZE) )
+ if ((NULL != (nfds = getenv ("LISTEN_FDS"))) &&
+ (1 == sscanf (nfds, "%u%1s", &cnt, dummy)) && (cnt > 0) &&
+ (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE))
{
- lsocks = GNUNET_new_array (cnt + 1,
- struct GNUNET_NETWORK_Handle *);
+ lsocks = GNUNET_new_array (cnt + 1, struct GNUNET_NETWORK_Handle *);
while (0 < cnt--)
{
- flags = fcntl (3 + cnt,
- F_GETFD);
- if ( (flags < 0) ||
- (0 != (flags & FD_CLOEXEC)) ||
- (NULL ==
- (lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
+ flags = fcntl (3 + cnt, F_GETFD);
+ if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
+ (NULL == (lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_ (
@@ -1780,9 +1629,7 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
slc = GNUNET_new (struct ServiceListenContext);
slc->sh = sh;
slc->listen_socket = *ls;
- GNUNET_CONTAINER_DLL_insert (sh->slc_head,
- sh->slc_tail,
- slc);
+ GNUNET_CONTAINER_DLL_insert (sh->slc_head, sh->slc_tail, slc);
}
GNUNET_free (lsocks);
}
@@ -1792,10 +1639,7 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
socklen_t *addrlens;
int num;
- num = get_server_addresses (sh->service_name,
- sh->cfg,
- &addrs,
- &addrlens);
+ num = get_server_addresses (sh->service_name, sh->cfg, &addrs, &addrlens);
if (GNUNET_SYSERR == num)
return GNUNET_SYSERR;
@@ -1805,54 +1649,40 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
slc = GNUNET_new (struct ServiceListenContext);
slc->sh = sh;
- slc->listen_socket = open_listen_socket (addrs[i],
- addrlens[i]);
+ slc->listen_socket = open_listen_socket (addrs[i], addrlens[i]);
GNUNET_free (addrs[i]);
if (NULL == slc->listen_socket)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "bind");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
GNUNET_free (slc);
continue;
}
- GNUNET_CONTAINER_DLL_insert (sh->slc_head,
- sh->slc_tail,
- slc);
+ GNUNET_CONTAINER_DLL_insert (sh->slc_head, sh->slc_tail, slc);
}
GNUNET_free_non_null (addrlens);
GNUNET_free_non_null (addrs);
- if ( (0 != num) &&
- (NULL == sh->slc_head) )
+ if ((0 != num) && (NULL == sh->slc_head))
{
/* All attempts to bind failed, hard failure */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ (
- "Could not bind to any of the ports I was supposed to, refusing to run!\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ (
+ "Could not bind to any of the ports I was supposed to, refusing to run!\n"));
return GNUNET_SYSERR;
}
}
sh->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
- sh->match_uid
- = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
- sh->service_name,
- "UNIX_MATCH_UID");
- sh->match_gid
- = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
- sh->service_name,
- "UNIX_MATCH_GID");
- process_acl4 (&sh->v4_denied,
- sh,
- "REJECT_FROM");
- process_acl4 (&sh->v4_allowed,
- sh,
- "ACCEPT_FROM");
- process_acl6 (&sh->v6_denied,
- sh,
- "REJECT_FROM6");
- process_acl6 (&sh->v6_allowed,
- sh,
- "ACCEPT_FROM6");
+ sh->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
+ sh->service_name,
+ "UNIX_MATCH_UID");
+ sh->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
+ sh->service_name,
+ "UNIX_MATCH_GID");
+ process_acl4 (&sh->v4_denied, sh, "REJECT_FROM");
+ process_acl4 (&sh->v4_allowed, sh, "ACCEPT_FROM");
+ process_acl6 (&sh->v6_denied, sh, "REJECT_FROM6");
+ process_acl6 (&sh->v6_allowed, sh, "ACCEPT_FROM6");
return GNUNET_OK;
}
@@ -1869,11 +1699,10 @@ get_user_name (struct GNUNET_SERVICE_Handle *sh)
{
char *un;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
- sh->service_name,
- "USERNAME",
- &un))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
+ sh->service_name,
+ "USERNAME",
+ &un))
return NULL;
return un;
}
@@ -1891,7 +1720,7 @@ set_user_id (struct GNUNET_SERVICE_Handle *sh)
char *user;
if (NULL == (user = get_user_name (sh)))
- return GNUNET_OK; /* keep */
+ return GNUNET_OK; /* keep */
#ifndef MINGW
struct passwd *pws;
@@ -1902,28 +1731,23 @@ set_user_id (struct GNUNET_SERVICE_Handle *sh)
LOG (GNUNET_ERROR_TYPE_ERROR,
_ ("Cannot obtain information about user `%s': %s\n"),
user,
- errno == 0 ? _ ("No such user") : STRERROR (errno));
+ errno == 0 ? _ ("No such user") : strerror (errno));
GNUNET_free (user);
return GNUNET_SYSERR;
}
- if ( (0 != setgid (pws->pw_gid)) ||
- (0 != setegid (pws->pw_gid)) ||
+ if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) ||
#if HAVE_INITGROUPS
- (0 != initgroups (user,
- pws->pw_gid)) ||
+ (0 != initgroups (user, pws->pw_gid)) ||
#endif
- (0 != setuid (pws->pw_uid)) ||
- (0 != seteuid (pws->pw_uid)))
+ (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid)))
{
- if ((0 != setregid (pws->pw_gid,
- pws->pw_gid)) ||
- (0 != setreuid (pws->pw_uid,
- pws->pw_uid)))
+ if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
+ (0 != setreuid (pws->pw_uid, pws->pw_uid)))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_ ("Cannot change user/group to `%s': %s\n"),
user,
- STRERROR (errno));
+ strerror (errno));
GNUNET_free (user);
return GNUNET_SYSERR;
}
@@ -1946,11 +1770,10 @@ get_pid_file_name (struct GNUNET_SERVICE_Handle *sh)
{
char *pif;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
- sh->service_name,
- "PIDFILE",
- &pif))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
+ sh->service_name,
+ "PIDFILE",
+ &pif))
return NULL;
return pif;
}
@@ -1967,11 +1790,9 @@ pid_file_delete (struct GNUNET_SERVICE_Handle *sh)
char *pif = get_pid_file_name (sh);
if (NULL == pif)
- return; /* no PID file */
- if (0 != UNLINK (pif))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- pif);
+ return; /* no PID file */
+ if (0 != unlink (pif))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif);
GNUNET_free (pif);
}
@@ -1990,17 +1811,15 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh)
int nullfd;
int filedes[2];
- if (0 != PIPE (filedes))
+ if (0 != pipe (filedes))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "pipe");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
return GNUNET_SYSERR;
}
pid = fork ();
if (pid < 0)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "fork");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
return GNUNET_SYSERR;
}
if (0 != pid)
@@ -2008,13 +1827,10 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh)
/* Parent */
char c;
- GNUNET_break (0 == CLOSE (filedes[1]));
+ GNUNET_break (0 == close (filedes[1]));
c = 'X';
- if (1 != READ (filedes[0],
- &c,
- sizeof (char)))
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "read");
+ if (1 != read (filedes[0], &c, sizeof (char)))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read");
fflush (stdout);
switch (c)
{
@@ -2033,30 +1849,26 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh)
_ ("Service process failed to report status\n"));
break;
}
- exit (1); /* child reported error */
+ exit (1); /* child reported error */
}
- GNUNET_break (0 == CLOSE (0));
- GNUNET_break (0 == CLOSE (1));
- GNUNET_break (0 == CLOSE (filedes[0]));
- nullfd = OPEN ("/dev/null",
- O_RDWR | O_APPEND);
+ GNUNET_break (0 == close (0));
+ GNUNET_break (0 == close (1));
+ GNUNET_break (0 == close (filedes[0]));
+ nullfd = open ("/dev/null", O_RDWR | O_APPEND);
if (nullfd < 0)
return GNUNET_SYSERR;
/* set stdin/stdout to /dev/null */
- if ( (dup2 (nullfd, 0) < 0) ||
- (dup2 (nullfd, 1) < 0) )
+ if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "dup2");
- (void) CLOSE (nullfd);
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
+ (void) close (nullfd);
return GNUNET_SYSERR;
}
- (void) CLOSE (nullfd);
+ (void) close (nullfd);
/* Detach from controlling terminal */
pid = setsid ();
if (-1 == pid)
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "setsid");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "setsid");
sh->ready_confirm_fd = filedes[1];
#else
/* FIXME: we probably need to do something else
@@ -2084,9 +1896,7 @@ teardown_service (struct GNUNET_SERVICE_Handle *sh)
GNUNET_free_non_null (sh->v6_allowed);
while (NULL != (slc = sh->slc_head))
{
- GNUNET_CONTAINER_DLL_remove (sh->slc_head,
- sh->slc_tail,
- slc);
+ GNUNET_CONTAINER_DLL_remove (sh->slc_head, sh->slc_tail, slc);
if (NULL != slc->listen_task)
GNUNET_SCHEDULER_cancel (slc->listen_task);
GNUNET_break (GNUNET_OK ==
@@ -2103,8 +1913,7 @@ teardown_service (struct GNUNET_SERVICE_Handle *sh)
* @param msg AGPL request
*/
static void
-return_agpl (void *cls,
- const struct GNUNET_MessageHeader *msg)
+return_agpl (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_SERVICE_Client *client = cls;
struct GNUNET_MQ_Handle *mq;
@@ -2114,15 +1923,10 @@ return_agpl (void *cls,
(void) msg;
slen = strlen (GNUNET_AGPL_URL) + 1;
- env = GNUNET_MQ_msg_extra (res,
- GNUNET_MESSAGE_TYPE_RESPONSE_AGPL,
- slen);
- memcpy (&res[1],
- GNUNET_AGPL_URL,
- slen);
+ env = GNUNET_MQ_msg_extra (res, GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, slen);
+ memcpy (&res[1], GNUNET_AGPL_URL, slen);
mq = GNUNET_SERVICE_client_get_mq (client);
- GNUNET_MQ_send (mq,
- env);
+ GNUNET_MQ_send (mq, env);
GNUNET_SERVICE_client_continue (client);
}
@@ -2179,17 +1983,14 @@ GNUNET_SERVICE_start (const char *service_name,
sh->connect_cb = connect_cb;
sh->disconnect_cb = disconnect_cb;
sh->cb_cls = cls;
- sh->handlers = GNUNET_MQ_copy_handlers2 (handlers,
- &return_agpl,
- NULL);
+ sh->handlers = GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL);
if (GNUNET_OK != setup_service (sh))
{
GNUNET_free_non_null (sh->handlers);
GNUNET_free (sh);
return NULL;
}
- do_resume (sh,
- SUSPEND_STATE_NONE);
+ do_resume (sh, SUSPEND_STATE_NONE);
return sh;
}
@@ -2279,24 +2080,21 @@ GNUNET_SERVICE_run_ (int argc,
int ret;
int err;
- struct GNUNET_GETOPT_CommandLineOption service_options[] = {
- GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
- GNUNET_GETOPT_option_flag ('d',
- "daemonize",
- gettext_noop (
- "do daemonize (detach from terminal)"),
- &do_daemonize),
- GNUNET_GETOPT_option_help (NULL),
- GNUNET_GETOPT_option_loglevel (&loglev),
- GNUNET_GETOPT_option_logfile (&logfile),
- GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption service_options[] =
+ {GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
+ GNUNET_GETOPT_option_flag ('d',
+ "daemonize",
+ gettext_noop (
+ "do daemonize (detach from terminal)"),
+ &do_daemonize),
+ GNUNET_GETOPT_option_help (NULL),
+ GNUNET_GETOPT_option_loglevel (&loglev),
+ GNUNET_GETOPT_option_logfile (&logfile),
+ GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
+ GNUNET_GETOPT_OPTION_END};
err = 1;
- memset (&sh,
- 0,
- sizeof (sh));
+ memset (&sh, 0, sizeof (sh));
xdg = getenv ("XDG_CONFIG_HOME");
if (NULL != xdg)
GNUNET_asprintf (&cfg_filename,
@@ -2305,8 +2103,8 @@ GNUNET_SERVICE_run_ (int argc,
DIR_SEPARATOR_STR,
GNUNET_OS_project_data_get ()->config_file);
else
- cfg_filename = GNUNET_strdup (
- GNUNET_OS_project_data_get ()->user_config_file);
+ cfg_filename =
+ GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
sh.ready_confirm_fd = -1;
sh.options = options;
sh.cfg = cfg = GNUNET_CONFIGURATION_create ();
@@ -2322,10 +2120,7 @@ GNUNET_SERVICE_run_ (int argc,
logfile = NULL;
opt_cfg_filename = NULL;
do_daemonize = 0;
- ret = GNUNET_GETOPT_run (service_name,
- service_options,
- argc,
- argv);
+ ret = GNUNET_GETOPT_run (service_name, service_options, argc, argv);
if (GNUNET_SYSERR == ret)
goto shutdown;
if (GNUNET_NO == ret)
@@ -2333,20 +2128,15 @@ GNUNET_SERVICE_run_ (int argc,
err = 0;
goto shutdown;
}
- if (GNUNET_OK != GNUNET_log_setup (service_name,
- loglev,
- logfile))
+ if (GNUNET_OK != GNUNET_log_setup (service_name, loglev, logfile))
{
GNUNET_break (0);
goto shutdown;
}
if (NULL != opt_cfg_filename)
{
- if ( (GNUNET_YES !=
- GNUNET_DISK_file_test (opt_cfg_filename)) ||
- (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
- opt_cfg_filename)) )
+ if ((GNUNET_YES != GNUNET_DISK_file_test (opt_cfg_filename)) ||
+ (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_filename)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_ ("Malformed configuration file `%s', exit ...\n"),
@@ -2356,12 +2146,9 @@ GNUNET_SERVICE_run_ (int argc,
}
else
{
- if (GNUNET_YES ==
- GNUNET_DISK_file_test (cfg_filename))
+ if (GNUNET_YES == GNUNET_DISK_file_test (cfg_filename))
{
- if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
- cfg_filename))
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_filename))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_ ("Malformed configuration file `%s', exit ...\n"),
@@ -2371,9 +2158,7 @@ GNUNET_SERVICE_run_ (int argc,
}
else
{
- if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
- NULL))
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_ ("Malformed configuration, exit ...\n"));
@@ -2383,8 +2168,7 @@ GNUNET_SERVICE_run_ (int argc,
}
if (GNUNET_OK != setup_service (&sh))
goto shutdown;
- if ( (1 == do_daemonize) &&
- (GNUNET_OK != detach_terminal (&sh)) )
+ if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal (&sh)))
{
GNUNET_break (0);
goto shutdown;
@@ -2395,64 +2179,51 @@ GNUNET_SERVICE_run_ (int argc,
"Service `%s' runs with configuration from `%s'\n",
service_name,
(NULL != opt_cfg_filename) ? opt_cfg_filename : cfg_filename);
- if ((GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (sh.cfg,
- "TESTING",
- "SKEW_OFFSET",
- &skew_offset)) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (sh.cfg,
- "TESTING",
- "SKEW_VARIANCE",
- &skew_variance)))
+ if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sh.cfg,
+ "TESTING",
+ "SKEW_OFFSET",
+ &skew_offset)) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sh.cfg,
+ "TESTING",
+ "SKEW_VARIANCE",
+ &skew_variance)))
{
clock_offset = skew_offset - skew_variance;
GNUNET_TIME_set_offset (clock_offset);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Skewing clock by %dll ms\n",
- clock_offset);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset);
}
GNUNET_RESOLVER_connect (sh.cfg);
/* actually run service */
err = 0;
- GNUNET_SCHEDULER_run (&service_main,
- &sh);
+ GNUNET_SCHEDULER_run (&service_main, &sh);
/* shutdown */
if (1 == do_daemonize)
pid_file_delete (&sh);
- shutdown:
+shutdown:
if (-1 != sh.ready_confirm_fd)
{
- if (1 != WRITE (sh.ready_confirm_fd,
- err ? "I" : "S",
- 1))
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "write");
- GNUNET_break (0 == CLOSE (sh.ready_confirm_fd));
+ if (1 != write (sh.ready_confirm_fd, err ? "I" : "S", 1))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write");
+ GNUNET_break (0 == close (sh.ready_confirm_fd));
}
#if HAVE_MALLINFO
{
char *counter;
- if ( (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (sh.cfg,
- service_name,
- "GAUGER_HEAP")) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (sh.cfg,
- service_name,
- "GAUGER_HEAP",
- &counter)) )
+ if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sh.cfg,
+ service_name,
+ "GAUGER_HEAP")) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sh.cfg,
+ service_name,
+ "GAUGER_HEAP",
+ &counter)))
{
struct mallinfo mi;
mi = mallinfo ();
- GAUGER (service_name,
- counter,
- mi.usmblks,
- "blocks");
+ GAUGER (service_name, counter, mi.usmblks, "blocks");
GNUNET_free (counter);
}
}
@@ -2479,8 +2250,7 @@ GNUNET_SERVICE_run_ (int argc,
void
GNUNET_SERVICE_suspend (struct GNUNET_SERVICE_Handle *sh)
{
- do_suspend (sh,
- SUSPEND_STATE_APP);
+ do_suspend (sh, SUSPEND_STATE_APP);
}
@@ -2492,8 +2262,7 @@ GNUNET_SERVICE_suspend (struct GNUNET_SERVICE_Handle *sh)
void
GNUNET_SERVICE_resume (struct GNUNET_SERVICE_Handle *sh)
{
- do_resume (sh,
- SUSPEND_STATE_APP);
+ do_resume (sh, SUSPEND_STATE_APP);
}
@@ -2511,8 +2280,7 @@ resume_client_receive (void *cls)
c->recv_task = NULL;
/* first, check if there is still something in the buffer */
- ret = GNUNET_MST_next (c->mst,
- GNUNET_YES);
+ ret = GNUNET_MST_next (c->mst, GNUNET_YES);
if (GNUNET_SYSERR == ret)
{
if (NULL == c->drop_task)
@@ -2527,11 +2295,10 @@ resume_client_receive (void *cls)
/* need to receive more data from the network first */
if (NULL != c->recv_task)
return;
- c->recv_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- c->sock,
- &service_client_recv,
- c);
+ c->recv_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ c->sock,
+ &service_client_recv,
+ c);
}
@@ -2553,9 +2320,7 @@ GNUNET_SERVICE_client_continue (struct GNUNET_SERVICE_Client *c)
GNUNET_SCHEDULER_cancel (c->warn_task);
c->warn_task = NULL;
}
- c->recv_task
- = GNUNET_SCHEDULER_add_now (&resume_client_receive,
- c);
+ c->recv_task = GNUNET_SCHEDULER_add_now (&resume_client_receive, c);
}
@@ -2598,20 +2363,18 @@ finish_client_drop (void *cls)
GNUNET_MQ_destroy (c->mq);
if (GNUNET_NO == c->persist)
{
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (c->sock));
- if ( (0 != (SUSPEND_STATE_EMFILE & sh->suspend_state)) &&
- (0 == (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)) )
- do_resume (sh,
- SUSPEND_STATE_EMFILE);
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (c->sock));
+ if ((0 != (SUSPEND_STATE_EMFILE & sh->suspend_state)) &&
+ (0 == (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)))
+ do_resume (sh, SUSPEND_STATE_EMFILE);
}
else
{
GNUNET_NETWORK_socket_free_memory_only_ (c->sock);
}
GNUNET_free (c);
- if ( (0 != (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)) &&
- (GNUNET_NO == have_non_monitor_clients (sh)) )
+ if ((0 != (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)) &&
+ (GNUNET_NO == have_non_monitor_clients (sh)))
GNUNET_SERVICE_shutdown (sh);
}
@@ -2640,8 +2403,7 @@ GNUNET_SERVICE_client_drop (struct GNUNET_SERVICE_Client *c)
void *backtrace_array[MAX_TRACE_DEPTH];
int num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
char **backtrace_strings =
- backtrace_symbols (backtrace_array,
- t->num_backtrace_strings);
+ backtrace_symbols (backtrace_array, t->num_backtrace_strings);
for (unsigned int i = 0; i < num_backtrace_strings; i++)
LOG (GNUNET_ERROR_TYPE_DEBUG,
"client drop trace %u: %s\n",
@@ -2655,13 +2417,9 @@ GNUNET_SERVICE_client_drop (struct GNUNET_SERVICE_Client *c)
GNUNET_assert (0);
return;
}
- GNUNET_CONTAINER_DLL_remove (sh->clients_head,
- sh->clients_tail,
- c);
+ GNUNET_CONTAINER_DLL_remove (sh->clients_head, sh->clients_tail, c);
if (NULL != sh->disconnect_cb)
- sh->disconnect_cb (sh->cb_cls,
- c,
- c->user_context);
+ sh->disconnect_cb (sh->cb_cls, c, c->user_context);
if (NULL != c->warn_task)
{
GNUNET_SCHEDULER_cancel (c->warn_task);
@@ -2677,8 +2435,7 @@ GNUNET_SERVICE_client_drop (struct GNUNET_SERVICE_Client *c)
GNUNET_SCHEDULER_cancel (c->send_task);
c->send_task = NULL;
}
- c->drop_task = GNUNET_SCHEDULER_add_now (&finish_client_drop,
- c);
+ c->drop_task = GNUNET_SCHEDULER_add_now (&finish_client_drop, c);
}
@@ -2693,8 +2450,7 @@ GNUNET_SERVICE_shutdown (struct GNUNET_SERVICE_Handle *sh)
struct GNUNET_SERVICE_Client *client;
if (0 == (sh->suspend_state & SUSPEND_STATE_SHUTDOWN))
- do_suspend (sh,
- SUSPEND_STATE_SHUTDOWN);
+ do_suspend (sh, SUSPEND_STATE_SHUTDOWN);
while (NULL != (client = sh->clients_head))
GNUNET_SERVICE_client_drop (client);
}
@@ -2716,8 +2472,8 @@ void
GNUNET_SERVICE_client_mark_monitor (struct GNUNET_SERVICE_Client *c)
{
c->is_monitor = GNUNET_YES;
- if ( ((0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state))&&
- (GNUNET_NO == have_non_monitor_clients (c->sh)) ) )
+ if (((0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state)) &&
+ (GNUNET_NO == have_non_monitor_clients (c->sh))))
GNUNET_SERVICE_shutdown (c->sh);
}
diff --git a/src/util/strings.c b/src/util/strings.c
index 8cd591288..ef9fdd693 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -34,9 +34,10 @@
#include <unistr.h>
#include <uniconv.h>
-#define LOG(kind,...) GNUNET_log_from (kind, "util-strings", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-strings", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-strings", syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-strings", syscall)
/**
@@ -105,15 +106,13 @@ GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids,
off = 0;
buf = GNUNET_malloc (plen);
- for (unsigned int i = 0;
- i < num_pids;
- i++)
+ for (unsigned int i = 0; i < num_pids; i++)
{
off += GNUNET_snprintf (&buf[off],
plen - off,
"%s%s",
GNUNET_i2s (&pids[i]),
- (i == num_pids -1) ? "" : "-");
+ (i == num_pids - 1) ? "" : "-");
}
return buf;
}
@@ -133,8 +132,10 @@ GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids,
* in the buffer, or 0 on error.
*/
unsigned int
-GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size,
- unsigned int count, ...)
+GNUNET_STRINGS_buffer_tokenize (const char *buffer,
+ size_t size,
+ unsigned int count,
+ ...)
{
unsigned int start;
unsigned int needed;
@@ -153,10 +154,10 @@ GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size,
if (needed == size)
{
va_end (ap);
- return 0; /* error */
+ return 0; /* error */
}
*r = &buffer[start];
- needed++; /* skip 0-termination */
+ needed++; /* skip 0-termination */
count--;
}
va_end (ap);
@@ -173,7 +174,7 @@ GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size,
char *
GNUNET_STRINGS_byte_size_fancy (unsigned long long size)
{
- const char *unit = _( /* size unit */ "b");
+ const char *unit = _ (/* size unit */ "b");
char *ret;
if (size > 5 * 1024)
@@ -215,7 +216,7 @@ GNUNET_STRINGS_byte_size_fancy (unsigned long long size)
* null byte
*/
size_t
-GNUNET_strlcpy(char *dst, const char *src, size_t n)
+GNUNET_strlcpy (char *dst, const char *src, size_t n)
{
size_t slen;
@@ -257,8 +258,8 @@ struct ConversionTable
*/
static int
convert_with_table (const char *input,
- const struct ConversionTable *table,
- unsigned long long *output)
+ const struct ConversionTable *table,
+ unsigned long long *output)
{
unsigned long long ret;
char *in;
@@ -290,7 +291,7 @@ convert_with_table (const char *input,
if ((0 != errno) || (endptr == tok))
{
GNUNET_free (in);
- return GNUNET_SYSERR; /* expected number */
+ return GNUNET_SYSERR; /* expected number */
}
if ('\0' == endptr[0])
break; /* next tok */
@@ -318,26 +319,22 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
unsigned long long *size)
{
static const struct ConversionTable table[] =
- {
- { "B", 1},
- { "KiB", 1024},
- { "kB", 1000},
- { "MiB", 1024 * 1024},
- { "MB", 1000 * 1000},
- { "GiB", 1024 * 1024 * 1024},
- { "GB", 1000 * 1000 * 1000},
- { "TiB", 1024LL * 1024LL * 1024LL * 1024LL},
- { "TB", 1000LL * 1000LL * 1000LL * 1024LL},
- { "PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
- { "PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL},
- { "EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
- { "EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL},
- { NULL, 0}
- };
-
- return convert_with_table (fancy_size,
- table,
- size);
+ {{"B", 1},
+ {"KiB", 1024},
+ {"kB", 1000},
+ {"MiB", 1024 * 1024},
+ {"MB", 1000 * 1000},
+ {"GiB", 1024 * 1024 * 1024},
+ {"GB", 1000 * 1000 * 1000},
+ {"TiB", 1024LL * 1024LL * 1024LL * 1024LL},
+ {"TB", 1000LL * 1000LL * 1000LL * 1024LL},
+ {"PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
+ {"PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL},
+ {"EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL},
+ {"EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL},
+ {NULL, 0}};
+
+ return convert_with_table (fancy_size, table, size);
}
@@ -354,31 +351,29 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
struct GNUNET_TIME_Relative *rtime)
{
static const struct ConversionTable table[] =
- {
- { "us", 1},
- { "ms", 1000 },
- { "s", 1000 * 1000LL },
- { "second", 1000 * 1000LL },
- { "seconds", 1000 * 1000LL },
- { "\"", 1000 * 1000LL },
- { "m", 60 * 1000 * 1000LL},
- { "min", 60 * 1000 * 1000LL},
- { "minute", 60 * 1000 * 1000LL},
- { "minutes", 60 * 1000 * 1000LL},
- { "'", 60 * 1000 * 1000LL},
- { "h", 60 * 60 * 1000 * 1000LL},
- { "hour", 60 * 60 * 1000 * 1000LL},
- { "hours", 60 * 60 * 1000 * 1000LL},
- { "d", 24 * 60 * 60 * 1000LL * 1000LL},
- { "day", 24 * 60 * 60 * 1000LL * 1000LL},
- { "days", 24 * 60 * 60 * 1000LL * 1000LL},
- { "week", 7 * 24 * 60 * 60 * 1000LL * 1000LL},
- { "weeks", 7 * 24 * 60 * 60 * 1000LL * 1000LL},
- { "year", 31536000000000LL /* year */ },
- { "years", 31536000000000LL /* year */ },
- { "a", 31536000000000LL /* year */ },
- { NULL, 0}
- };
+ {{"us", 1},
+ {"ms", 1000},
+ {"s", 1000 * 1000LL},
+ {"second", 1000 * 1000LL},
+ {"seconds", 1000 * 1000LL},
+ {"\"", 1000 * 1000LL},
+ {"m", 60 * 1000 * 1000LL},
+ {"min", 60 * 1000 * 1000LL},
+ {"minute", 60 * 1000 * 1000LL},
+ {"minutes", 60 * 1000 * 1000LL},
+ {"'", 60 * 1000 * 1000LL},
+ {"h", 60 * 60 * 1000 * 1000LL},
+ {"hour", 60 * 60 * 1000 * 1000LL},
+ {"hours", 60 * 60 * 1000 * 1000LL},
+ {"d", 24 * 60 * 60 * 1000LL * 1000LL},
+ {"day", 24 * 60 * 60 * 1000LL * 1000LL},
+ {"days", 24 * 60 * 60 * 1000LL * 1000LL},
+ {"week", 7 * 24 * 60 * 60 * 1000LL * 1000LL},
+ {"weeks", 7 * 24 * 60 * 60 * 1000LL * 1000LL},
+ {"year", 31536000000000LL /* year */},
+ {"years", 31536000000000LL /* year */},
+ {"a", 31536000000000LL /* year */},
+ {NULL, 0}};
int ret;
unsigned long long val;
@@ -387,9 +382,7 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
*rtime = GNUNET_TIME_UNIT_FOREVER_REL;
return GNUNET_OK;
}
- ret = convert_with_table (fancy_time,
- table,
- &val);
+ ret = convert_with_table (fancy_time, table, &val);
rtime->rel_value_us = (uint64_t) val;
return ret;
}
@@ -412,24 +405,23 @@ GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
time_t t;
const char *eos;
- if (0 == strcasecmp ("end of time",
- fancy_time))
+ if (0 == strcasecmp ("end of time", fancy_time))
{
*atime = GNUNET_TIME_UNIT_FOREVER_ABS;
return GNUNET_OK;
}
eos = &fancy_time[strlen (fancy_time)];
memset (&tv, 0, sizeof (tv));
- if ( (eos != strptime (fancy_time, "%a %b %d %H:%M:%S %Y", &tv)) &&
- (eos != strptime (fancy_time, "%c", &tv)) &&
- (eos != strptime (fancy_time, "%Ec", &tv)) &&
- (eos != strptime (fancy_time, "%Y-%m-%d %H:%M:%S", &tv)) &&
- (eos != strptime (fancy_time, "%Y-%m-%d %H:%M", &tv)) &&
- (eos != strptime (fancy_time, "%x", &tv)) &&
- (eos != strptime (fancy_time, "%Ex", &tv)) &&
- (eos != strptime (fancy_time, "%Y-%m-%d", &tv)) &&
- (eos != strptime (fancy_time, "%Y-%m", &tv)) &&
- (eos != strptime (fancy_time, "%Y", &tv)) )
+ if ((eos != strptime (fancy_time, "%a %b %d %H:%M:%S %Y", &tv)) &&
+ (eos != strptime (fancy_time, "%c", &tv)) &&
+ (eos != strptime (fancy_time, "%Ec", &tv)) &&
+ (eos != strptime (fancy_time, "%Y-%m-%d %H:%M:%S", &tv)) &&
+ (eos != strptime (fancy_time, "%Y-%m-%d %H:%M", &tv)) &&
+ (eos != strptime (fancy_time, "%x", &tv)) &&
+ (eos != strptime (fancy_time, "%Ex", &tv)) &&
+ (eos != strptime (fancy_time, "%Y-%m-%d", &tv)) &&
+ (eos != strptime (fancy_time, "%Y-%m", &tv)) &&
+ (eos != strptime (fancy_time, "%Y", &tv)))
return GNUNET_SYSERR;
t = mktime (&tv);
atime->abs_value_us = (uint64_t) ((uint64_t) t * 1000LL * 1000LL);
@@ -452,9 +444,9 @@ GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
*/
char *
GNUNET_STRINGS_conv (const char *input,
- size_t len,
- const char *input_charset,
- const char *output_charset)
+ size_t len,
+ const char *input_charset,
+ const char *output_charset)
{
char *ret;
uint8_t *u8_string;
@@ -463,10 +455,12 @@ GNUNET_STRINGS_conv (const char *input,
size_t encoded_string_length;
u8_string = u8_conv_from_encoding (input_charset,
- iconveh_error,
- input, len,
- NULL, NULL,
- &u8_string_length);
+ iconveh_error,
+ input,
+ len,
+ NULL,
+ NULL,
+ &u8_string_length);
if (NULL == u8_string)
{
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "u8_conv_from_encoding");
@@ -480,10 +474,13 @@ GNUNET_STRINGS_conv (const char *input,
free (u8_string);
return ret;
}
- encoded_string = u8_conv_to_encoding (output_charset, iconveh_error,
- u8_string, u8_string_length,
- NULL, NULL,
- &encoded_string_length);
+ encoded_string = u8_conv_to_encoding (output_charset,
+ iconveh_error,
+ u8_string,
+ u8_string_length,
+ NULL,
+ NULL,
+ &encoded_string_length);
free (u8_string);
if (NULL == encoded_string)
{
@@ -495,10 +492,11 @@ GNUNET_STRINGS_conv (const char *input,
ret[encoded_string_length] = '\0';
free (encoded_string);
return ret;
- fail:
+fail:
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Character sets requested were `%s'->`%s'\n"),
- "UTF-8", output_charset);
+ _ ("Character sets requested were `%s'->`%s'\n"),
+ "UTF-8",
+ output_charset);
ret = GNUNET_malloc (len + 1);
GNUNET_memcpy (ret, input, len);
ret[len] = '\0';
@@ -519,9 +517,7 @@ GNUNET_STRINGS_conv (const char *input,
* string is returned.
*/
char *
-GNUNET_STRINGS_to_utf8 (const char *input,
- size_t len,
- const char *charset)
+GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset)
{
return GNUNET_STRINGS_conv (input, len, charset, "UTF-8");
}
@@ -539,9 +535,7 @@ GNUNET_STRINGS_to_utf8 (const char *input,
* string is returned.
*/
char *
-GNUNET_STRINGS_from_utf8 (const char *input,
- size_t len,
- const char *charset)
+GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset)
{
return GNUNET_STRINGS_conv (input, len, "UTF-8", charset);
}
@@ -555,17 +549,20 @@ GNUNET_STRINGS_from_utf8 (const char *input,
* @param output output buffer
*/
void
-GNUNET_STRINGS_utf8_tolower (const char *input,
- char *output)
+GNUNET_STRINGS_utf8_tolower (const char *input, char *output)
{
uint8_t *tmp_in;
size_t len;
- tmp_in = u8_tolower ((uint8_t*)input, strlen ((char *) input),
- NULL, UNINORM_NFD, NULL, &len);
- GNUNET_memcpy(output, tmp_in, len);
+ tmp_in = u8_tolower ((uint8_t *) input,
+ strlen ((char *) input),
+ NULL,
+ UNINORM_NFD,
+ NULL,
+ &len);
+ GNUNET_memcpy (output, tmp_in, len);
output[len] = '\0';
- free(tmp_in);
+ free (tmp_in);
}
@@ -577,14 +574,17 @@ GNUNET_STRINGS_utf8_tolower (const char *input,
* @param output output buffer
*/
void
-GNUNET_STRINGS_utf8_toupper(const char *input,
- char *output)
+GNUNET_STRINGS_utf8_toupper (const char *input, char *output)
{
uint8_t *tmp_in;
size_t len;
- tmp_in = u8_toupper ((uint8_t*)input, strlen ((char *) input),
- NULL, UNINORM_NFD, NULL, &len);
+ tmp_in = u8_toupper ((uint8_t *) input,
+ strlen ((char *) input),
+ NULL,
+ UNINORM_NFD,
+ NULL,
+ &len);
GNUNET_memcpy (output, tmp_in, len);
output[len] = '\0';
free (tmp_in);
@@ -624,7 +624,7 @@ GNUNET_STRINGS_filename_expand (const char *fil)
if (fm == NULL)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to expand `$HOME': environment variable `HOME' not set"));
+ _ ("Failed to expand `$HOME': environment variable `HOME' not set"));
return NULL;
}
fm = GNUNET_strdup (fm);
@@ -660,20 +660,20 @@ GNUNET_STRINGS_filename_expand (const char *fil)
}
if (fm == NULL)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "getcwd");
- buffer = getenv ("PWD"); /* alternative */
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "getcwd");
+ buffer = getenv ("PWD"); /* alternative */
if (buffer != NULL)
fm = GNUNET_strdup (buffer);
}
if (fm == NULL)
- fm = GNUNET_strdup ("./"); /* give up */
+ fm = GNUNET_strdup ("./"); /* give up */
}
GNUNET_asprintf (&buffer,
"%s%s%s",
fm,
- (fm[strlen (fm) - 1] ==
- DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR, fil_ptr);
+ (fm[strlen (fm) - 1] == DIR_SEPARATOR) ? ""
+ : DIR_SEPARATOR_STR,
+ fil_ptr);
GNUNET_free (fm);
return buffer;
#else
@@ -682,29 +682,22 @@ GNUNET_STRINGS_filename_expand (const char *fil)
if ((lRet = plibc_conv_to_win_path (fil, fn)) != ERROR_SUCCESS)
{
SetErrnoFromWinError (lRet);
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "plibc_conv_to_win_path");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "plibc_conv_to_win_path");
return NULL;
}
/* is the path relative? */
- if ( (0 != strncmp (fn + 1, ":\\", 2)) &&
- (0 != strncmp (fn, "\\\\", 2)) )
+ if ((0 != strncmp (fn + 1, ":\\", 2)) && (0 != strncmp (fn, "\\\\", 2)))
{
char szCurDir[MAX_PATH + 1];
- lRet = GetCurrentDirectory (MAX_PATH + 1,
- szCurDir);
+ lRet = GetCurrentDirectory (MAX_PATH + 1, szCurDir);
if (lRet + strlen (fn) + 1 > (MAX_PATH + 1))
{
SetErrnoFromWinError (ERROR_BUFFER_OVERFLOW);
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "GetCurrentDirectory");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "GetCurrentDirectory");
return NULL;
}
- GNUNET_asprintf (&buffer,
- "%s\\%s",
- szCurDir,
- fn);
+ GNUNET_asprintf (&buffer, "%s\\%s", szCurDir, fn);
GNUNET_free (fn);
fn = buffer;
}
@@ -725,56 +718,46 @@ GNUNET_STRINGS_filename_expand (const char *fil)
*/
const char *
GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta,
- int do_round)
+ int do_round)
{
static char buf[128];
- const char *unit = _( /* time unit */ "µs");
+ const char *unit = _ (/* time unit */ "µs");
uint64_t dval = delta.rel_value_us;
if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == delta.rel_value_us)
- return _("forever");
+ return _ ("forever");
if (0 == delta.rel_value_us)
- return _("0 ms");
- if ( ( (GNUNET_YES == do_round) &&
- (dval > 5 * 1000) ) ||
- (0 == (dval % 1000) ))
+ return _ ("0 ms");
+ if (((GNUNET_YES == do_round) && (dval > 5 * 1000)) || (0 == (dval % 1000)))
{
dval = dval / 1000;
- unit = _( /* time unit */ "ms");
- if ( ( (GNUNET_YES == do_round) &&
- (dval > 5 * 1000) ) ||
- (0 == (dval % 1000) ))
+ unit = _ (/* time unit */ "ms");
+ if (((GNUNET_YES == do_round) && (dval > 5 * 1000)) || (0 == (dval % 1000)))
{
dval = dval / 1000;
- unit = _( /* time unit */ "s");
- if ( ( (GNUNET_YES == do_round) &&
- (dval > 5 * 60) ) ||
- (0 == (dval % 60) ) )
+ unit = _ (/* time unit */ "s");
+ if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60)))
{
- dval = dval / 60;
- unit = _( /* time unit */ "m");
- if ( ( (GNUNET_YES == do_round) &&
- (dval > 5 * 60) ) ||
- (0 == (dval % 60) ))
- {
- dval = dval / 60;
- unit = _( /* time unit */ "h");
- if ( ( (GNUNET_YES == do_round) &&
- (dval > 5 * 24) ) ||
- (0 == (dval % 24)) )
- {
- dval = dval / 24;
- if (1 == dval)
- unit = _( /* time unit */ "day");
- else
- unit = _( /* time unit */ "days");
- }
- }
+ dval = dval / 60;
+ unit = _ (/* time unit */ "m");
+ if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60)))
+ {
+ dval = dval / 60;
+ unit = _ (/* time unit */ "h");
+ if (((GNUNET_YES == do_round) && (dval > 5 * 24)) ||
+ (0 == (dval % 24)))
+ {
+ dval = dval / 24;
+ if (1 == dval)
+ unit = _ (/* time unit */ "day");
+ else
+ unit = _ (/* time unit */ "days");
+ }
+ }
}
}
}
- GNUNET_snprintf (buf, sizeof (buf),
- "%llu %s", dval, unit);
+ GNUNET_snprintf (buf, sizeof (buf), "%llu %s", dval, unit);
return buf;
}
@@ -796,7 +779,7 @@ GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t)
struct tm *tp;
if (t.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
- return _("end of time");
+ return _ ("end of time");
tt = t.abs_value_us / 1000LL / 1000LL;
tp = localtime (&tt);
/* This is hacky, but i don't know a way to detect libc character encoding.
@@ -813,12 +796,16 @@ GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t)
uint8_t *conved;
size_t ssize;
- wcsftime (wbuf, sizeof (wbuf) / sizeof (wchar_t),
- L"%a %b %d %H:%M:%S %Y", tp);
+ wcsftime (wbuf,
+ sizeof (wbuf) / sizeof (wchar_t),
+ L"%a %b %d %H:%M:%S %Y",
+ tp);
ssize = sizeof (buf);
- conved = u16_to_u8 (wbuf, sizeof (wbuf) / sizeof (wchar_t),
- (uint8_t *) buf, &ssize);
+ conved = u16_to_u8 (wbuf,
+ sizeof (wbuf) / sizeof (wchar_t),
+ (uint8_t *) buf,
+ &ssize);
if (conved != (uint8_t *) buf)
{
GNUNET_strlcpy (buf, (char *) conved, sizeof (buf));
@@ -847,8 +834,7 @@ GNUNET_STRINGS_get_short_name (const char *filename)
const char *short_fn = filename;
const char *ss;
- while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR))
- && (ss[1] != '\0'))
+ while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR)) && (ss[1] != '\0'))
short_fn = 1 + ss;
return short_fn;
}
@@ -890,7 +876,7 @@ getValue__ (unsigned char a)
return a - '0';
if ((a >= 'a') && (a <= 'z'))
a = toupper (a);
- /* return (a - 'a' + 10); */
+ /* return (a - 'a' + 10); */
dec = 0;
if ((a >= 'A') && (a <= 'Z'))
{
@@ -950,12 +936,12 @@ GNUNET_STRINGS_data_to_string (const void *data,
{
if ((rpos < size) && (vbit < 5))
{
- bits = (bits << 8) | udata[rpos++]; /* eat 8 more bits */
+ bits = (bits << 8) | udata[rpos++]; /* eat 8 more bits */
vbit += 8;
}
if (vbit < 5)
{
- bits <<= (5 - vbit); /* zero-padding */
+ bits <<= (5 - vbit); /* zero-padding */
GNUNET_assert (vbit == ((size * 8) % 5));
vbit = 5;
}
@@ -985,8 +971,7 @@ GNUNET_STRINGS_data_to_string (const void *data,
* @return freshly allocated, null-terminated string
*/
char *
-GNUNET_STRINGS_data_to_string_alloc (const void *buf,
- size_t size)
+GNUNET_STRINGS_data_to_string_alloc (const void *buf, size_t size)
{
char *str_buf;
size_t len = size * 8;
@@ -1018,8 +1003,10 @@ GNUNET_STRINGS_data_to_string_alloc (const void *buf,
* @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
*/
int
-GNUNET_STRINGS_string_to_data (const char *enc, size_t enclen,
- void *out, size_t out_size)
+GNUNET_STRINGS_string_to_data (const char *enc,
+ size_t enclen,
+ void *out,
+ size_t out_size)
{
unsigned int rpos;
unsigned int wpos;
@@ -1073,8 +1060,7 @@ GNUNET_STRINGS_string_to_data (const char *enc, size_t enclen,
vbit -= 8;
}
}
- if ( (0 != rpos) ||
- (0 != vbit) )
+ if ((0 != rpos) || (0 != vbit))
return GNUNET_SYSERR;
return GNUNET_OK;
}
@@ -1098,8 +1084,8 @@ GNUNET_STRINGS_string_to_data (const char *enc, size_t enclen,
*/
int
GNUNET_STRINGS_parse_uri (const char *path,
- char **scheme_part,
- const char **path_part)
+ char **scheme_part,
+ const char **path_part)
{
size_t len;
size_t i;
@@ -1107,19 +1093,20 @@ GNUNET_STRINGS_parse_uri (const char *path,
int pp_state = 0;
const char *post_scheme_part = NULL;
len = strlen (path);
- for (end = 0, i = 0; !end && i < len; i++)
+ for (end = 0, i = 0; ! end && i < len; i++)
{
switch (pp_state)
{
case 0:
- if ( (path[i] == ':') && (i > 0) )
+ if ((path[i] == ':') && (i > 0))
{
pp_state += 1;
continue;
}
- if (!((path[i] >= 'A' && path[i] <= 'Z') || (path[i] >= 'a' && path[i] <= 'z')
- || (path[i] >= '0' && path[i] <= '9') || path[i] == '+' || path[i] == '-'
- || (path[i] == '.')))
+ if (! ((path[i] >= 'A' && path[i] <= 'Z') ||
+ (path[i] >= 'a' && path[i] <= 'z') ||
+ (path[i] >= '0' && path[i] <= '9') || path[i] == '+' ||
+ path[i] == '-' || (path[i] == '.')))
end = 1;
break;
case 1:
@@ -1178,7 +1165,7 @@ GNUNET_STRINGS_path_is_absolute (const char *filename,
#endif
const char *post_scheme_path;
int is_uri;
- char * uri;
+ char *uri;
/* consider POSIX paths to be absolute too, even on W32,
* as plibc expansion will fix them for us.
*/
@@ -1196,14 +1183,17 @@ GNUNET_STRINGS_path_is_absolute (const char *filename,
else
GNUNET_free_non_null (uri);
#if WINDOWS
- len = strlen(post_scheme_path);
+ len = strlen (post_scheme_path);
/* Special check for file:///c:/blah
* We want to parse 'c:/', not '/c:/'
*/
if (post_scheme_path[0] == '/' && len >= 3 && post_scheme_path[2] == ':')
post_scheme_path = &post_scheme_path[1];
#endif
- return GNUNET_STRINGS_path_is_absolute (post_scheme_path, GNUNET_NO, NULL, NULL);
+ return GNUNET_STRINGS_path_is_absolute (post_scheme_path,
+ GNUNET_NO,
+ NULL,
+ NULL);
}
}
else
@@ -1214,18 +1204,18 @@ GNUNET_STRINGS_path_is_absolute (const char *filename,
#if WINDOWS
len = strlen (filename);
if (len >= 3 &&
- ((filename[0] >= 'A' && filename[0] <= 'Z')
- || (filename[0] >= 'a' && filename[0] <= 'z'))
- && filename[1] == ':' && (filename[2] == '/' || filename[2] == '\\'))
+ ((filename[0] >= 'A' && filename[0] <= 'Z') ||
+ (filename[0] >= 'a' && filename[0] <= 'z')) &&
+ filename[1] == ':' && (filename[2] == '/' || filename[2] == '\\'))
return GNUNET_YES;
#endif
return GNUNET_NO;
}
#if MINGW
-#define _IFMT 0170000 /* type of file */
-#define _IFLNK 0120000 /* symbolic link */
-#define S_ISLNK(m) (((m)&_IFMT) == _IFLNK)
+#define _IFMT 0170000 /* type of file */
+#define _IFLNK 0120000 /* symbolic link */
+#define S_ISLNK(m) (((m) &_IFMT) == _IFLNK)
#endif
@@ -1239,19 +1229,19 @@ GNUNET_STRINGS_path_is_absolute (const char *filename,
*/
int
GNUNET_STRINGS_check_filename (const char *filename,
- enum GNUNET_STRINGS_FilenameCheck checks)
+ enum GNUNET_STRINGS_FilenameCheck checks)
{
struct stat st;
- if ( (NULL == filename) || (filename[0] == '\0') )
+ if ((NULL == filename) || (filename[0] == '\0'))
return GNUNET_SYSERR;
if (0 != (checks & GNUNET_STRINGS_CHECK_IS_ABSOLUTE))
- if (!GNUNET_STRINGS_path_is_absolute (filename, GNUNET_NO, NULL, NULL))
+ if (! GNUNET_STRINGS_path_is_absolute (filename, GNUNET_NO, NULL, NULL))
return GNUNET_NO;
- if (0 != (checks & (GNUNET_STRINGS_CHECK_EXISTS
- | GNUNET_STRINGS_CHECK_IS_DIRECTORY
- | GNUNET_STRINGS_CHECK_IS_LINK)))
+ if (0 != (checks &
+ (GNUNET_STRINGS_CHECK_EXISTS | GNUNET_STRINGS_CHECK_IS_DIRECTORY |
+ GNUNET_STRINGS_CHECK_IS_LINK)))
{
- if (0 != STAT (filename, &st))
+ if (0 != stat (filename, &st))
{
if (0 != (checks & GNUNET_STRINGS_CHECK_EXISTS))
return GNUNET_NO;
@@ -1260,10 +1250,10 @@ GNUNET_STRINGS_check_filename (const char *filename,
}
}
if (0 != (checks & GNUNET_STRINGS_CHECK_IS_DIRECTORY))
- if (!S_ISDIR (st.st_mode))
+ if (! S_ISDIR (st.st_mode))
return GNUNET_NO;
if (0 != (checks & GNUNET_STRINGS_CHECK_IS_LINK))
- if (!S_ISLNK (st.st_mode))
+ if (! S_ISLNK (st.st_mode))
return GNUNET_NO;
return GNUNET_YES;
}
@@ -1283,8 +1273,8 @@ GNUNET_STRINGS_check_filename (const char *filename,
*/
int
GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
- uint16_t addrlen,
- struct sockaddr_in6 *r_buf)
+ uint16_t addrlen,
+ struct sockaddr_in6 *r_buf)
{
char zbuf[addrlen + 1];
int ret;
@@ -1298,7 +1288,7 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
if ('[' != zbuf[0])
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("IPv6 address did not start with `['\n"));
+ _ ("IPv6 address did not start with `['\n"));
return GNUNET_SYSERR;
}
zbuf[addrlen] = '\0';
@@ -1306,34 +1296,33 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
if (NULL == port_colon)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("IPv6 address did contain ':' to separate port number\n"));
+ _ ("IPv6 address did contain ':' to separate port number\n"));
return GNUNET_SYSERR;
}
if (']' != *(port_colon - 1))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("IPv6 address did contain ']' before ':' to separate port number\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ ("IPv6 address did contain ']' before ':' to separate port number\n"));
return GNUNET_SYSERR;
}
- ret = SSCANF (port_colon,
- ":%u%1s",
- &port,
- dummy);
- if ( (1 != ret) || (port > 65535) )
+ ret = sscanf (port_colon, ":%u%1s", &port, dummy);
+ if ((1 != ret) || (port > 65535))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("IPv6 address did contain a valid port number after the last ':'\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ ("IPv6 address did contain a valid port number after the last ':'\n"));
return GNUNET_SYSERR;
}
- *(port_colon-1) = '\0';
+ *(port_colon - 1) = '\0';
memset (r_buf, 0, sizeof (struct sockaddr_in6));
ret = inet_pton (AF_INET6, &zbuf[1], &r_buf->sin6_addr);
if (ret <= 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid IPv6 address `%s': %s\n"),
- &zbuf[1],
- STRERROR (errno));
+ _ ("Invalid IPv6 address `%s': %s\n"),
+ &zbuf[1],
+ strerror (errno));
return GNUNET_SYSERR;
}
r_buf->sin6_port = htons (port);
@@ -1358,8 +1347,8 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
*/
int
GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
- uint16_t addrlen,
- struct sockaddr_in *r_buf)
+ uint16_t addrlen,
+ struct sockaddr_in *r_buf)
{
unsigned int temps[4];
unsigned int port;
@@ -1368,14 +1357,14 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
if (addrlen < 9)
return GNUNET_SYSERR;
- cnt = SSCANF (zt_addr,
- "%u.%u.%u.%u:%u%1s",
- &temps[0],
- &temps[1],
- &temps[2],
- &temps[3],
- &port,
- dummy);
+ cnt = sscanf (zt_addr,
+ "%u.%u.%u.%u:%u%1s",
+ &temps[0],
+ &temps[1],
+ &temps[2],
+ &temps[3],
+ &port,
+ dummy);
if (5 != cnt)
return GNUNET_SYSERR;
for (cnt = 0; cnt < 4; cnt++)
@@ -1385,8 +1374,8 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
return GNUNET_SYSERR;
r_buf->sin_family = AF_INET;
r_buf->sin_port = htons (port);
- r_buf->sin_addr.s_addr = htonl ((temps[0] << 24) + (temps[1] << 16) +
- (temps[2] << 8) + temps[3]);
+ r_buf->sin_addr.s_addr =
+ htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) + temps[3]);
#if HAVE_SOCKADDR_IN_SIN_LEN
r_buf->sin_len = (u_char) sizeof (struct sockaddr_in);
#endif
@@ -1407,8 +1396,8 @@ GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
*/
int
GNUNET_STRINGS_to_address_ip (const char *addr,
- uint16_t addrlen,
- struct sockaddr_storage *r_buf)
+ uint16_t addrlen,
+ struct sockaddr_storage *r_buf)
{
if (addr[0] == '[')
return GNUNET_STRINGS_to_address_ipv6 (addr,
@@ -1431,8 +1420,8 @@ GNUNET_STRINGS_to_address_ip (const char *addr,
*/
size_t
GNUNET_STRINGS_parse_socket_addr (const char *addr,
- uint8_t *af,
- struct sockaddr **sa)
+ uint8_t *af,
+ struct sockaddr **sa)
{
char *cp = GNUNET_strdup (addr);
@@ -1442,9 +1431,9 @@ GNUNET_STRINGS_parse_socket_addr (const char *addr,
/* IPv6 */
*sa = GNUNET_malloc (sizeof (struct sockaddr_in6));
if (GNUNET_OK !=
- GNUNET_STRINGS_to_address_ipv6 (cp,
- strlen (cp),
- (struct sockaddr_in6 *) *sa))
+ GNUNET_STRINGS_to_address_ipv6 (cp,
+ strlen (cp),
+ (struct sockaddr_in6 *) *sa))
{
GNUNET_free (*sa);
*sa = NULL;
@@ -1460,9 +1449,9 @@ GNUNET_STRINGS_parse_socket_addr (const char *addr,
/* IPv4 */
*sa = GNUNET_malloc (sizeof (struct sockaddr_in));
if (GNUNET_OK !=
- GNUNET_STRINGS_to_address_ipv4 (cp,
- strlen (cp),
- (struct sockaddr_in *) *sa))
+ GNUNET_STRINGS_to_address_ipv4 (cp,
+ strlen (cp),
+ (struct sockaddr_in *) *sa))
{
GNUNET_free (*sa);
*sa = NULL;
@@ -1481,8 +1470,7 @@ GNUNET_STRINGS_parse_socket_addr (const char *addr,
* freed with a single call to GNUNET_free();
*/
static char *const *
-_make_continuous_arg_copy (int argc,
- char *const *argv)
+_make_continuous_arg_copy (int argc, char *const *argv)
{
size_t argvsize = 0;
int i;
@@ -1519,9 +1507,9 @@ _make_continuous_arg_copy (int argc,
*/
int
GNUNET_STRINGS_get_utf8_args (int argc,
- char *const *argv,
- int *u8argc,
- char *const **u8argv)
+ char *const *argv,
+ int *u8argc,
+ char *const **u8argv)
{
#if WINDOWS
wchar_t *wcmd;
@@ -1543,7 +1531,8 @@ GNUNET_STRINGS_get_utf8_args (int argc,
{
size_t strl;
/* Hopefully it will allocate us NUL-terminated strings... */
- split_u8argv[i] = (char *) u16_to_u8 (wargv[i], wcslen (wargv[i]) + 1, NULL, &strl);
+ split_u8argv[i] =
+ (char *) u16_to_u8 (wargv[i], wcslen (wargv[i]) + 1, NULL, &strl);
if (NULL == split_u8argv[i])
{
int j;
@@ -1563,7 +1552,8 @@ GNUNET_STRINGS_get_utf8_args (int argc,
free (split_u8argv);
return GNUNET_OK;
#else
- char *const *new_argv = (char *const *) _make_continuous_arg_copy (argc, argv);
+ char *const *new_argv =
+ (char *const *) _make_continuous_arg_copy (argc, argv);
*u8argv = new_argv;
*u8argc = argc;
return GNUNET_OK;
@@ -1595,35 +1585,22 @@ parse_port_policy (const char *port_policy,
pp->negate_portrange = GNUNET_YES;
pos++;
}
- if (2 == sscanf (pos,
- "%u-%u%1s",
- &s,
- &e,
- eol))
+ if (2 == sscanf (pos, "%u-%u%1s", &s, &e, eol))
{
- if ( (0 == s) ||
- (s > 0xFFFF) ||
- (e < s) ||
- (e > 0xFFFF) )
+ if ((0 == s) || (s > 0xFFFF) || (e < s) || (e > 0xFFFF))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Port not in range\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Port not in range\n"));
return GNUNET_SYSERR;
}
pp->start_port = (uint16_t) s;
pp->end_port = (uint16_t) e;
return GNUNET_OK;
}
- if (1 == sscanf (pos,
- "%u%1s",
- &s,
- eol))
+ if (1 == sscanf (pos, "%u%1s", &s, eol))
{
- if ( (0 == s) ||
- (s > 0xFFFF) )
+ if ((0 == s) || (s > 0xFFFF))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Port not in range\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Port not in range\n"));
return GNUNET_SYSERR;
}
@@ -1632,7 +1609,7 @@ parse_port_policy (const char *port_policy,
return GNUNET_OK;
}
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Malformed port policy `%s'\n"),
+ _ ("Malformed port policy `%s'\n"),
port_policy);
return GNUNET_SYSERR;
}
@@ -1666,7 +1643,7 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX)
int end;
char *routeList;
char dummy[2];
-
+
if (NULL == routeListX)
return NULL;
len = strlen (routeListX);
@@ -1677,14 +1654,14 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX)
for (i = 0; i < len; i++)
if (routeList[i] == ';')
count++;
- result = GNUNET_malloc (sizeof (struct GNUNET_STRINGS_IPv4NetworkPolicy) * (count + 1));
+ result = GNUNET_malloc (sizeof (struct GNUNET_STRINGS_IPv4NetworkPolicy) *
+ (count + 1));
i = 0;
pos = 0;
while (i < count)
{
for (colon = pos; ':' != routeList[colon]; colon++)
- if ( (';' == routeList[colon]) ||
- ('\0' == routeList[colon]) )
+ if ((';' == routeList[colon]) || ('\0' == routeList[colon]))
break;
for (end = colon; ';' != routeList[end]; end++)
if ('\0' == routeList[end])
@@ -1695,76 +1672,70 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX)
if (':' == routeList[colon])
{
routeList[colon] = '\0';
- if (GNUNET_OK != parse_port_policy (&routeList[colon + 1],
- &result[i].pp))
+ if (GNUNET_OK != parse_port_policy (&routeList[colon + 1], &result[i].pp))
break;
}
- cnt =
- SSCANF (&routeList[pos],
- "%u.%u.%u.%u/%u.%u.%u.%u%1s",
- &temps[0],
- &temps[1],
- &temps[2],
- &temps[3],
- &temps[4],
- &temps[5],
- &temps[6],
- &temps[7],
- dummy);
+ cnt = sscanf (&routeList[pos],
+ "%u.%u.%u.%u/%u.%u.%u.%u%1s",
+ &temps[0],
+ &temps[1],
+ &temps[2],
+ &temps[3],
+ &temps[4],
+ &temps[5],
+ &temps[6],
+ &temps[7],
+ dummy);
if (8 == cnt)
{
for (j = 0; j < 8; j++)
if (temps[j] > 0xFF)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid format for IP: `%s'\n"),
+ _ ("Invalid format for IP: `%s'\n"),
&routeList[pos]);
GNUNET_free (result);
GNUNET_free (routeList);
return NULL;
}
- result[i].network.s_addr =
- htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
- temps[3]);
- result[i].netmask.s_addr =
- htonl ((temps[4] << 24) + (temps[5] << 16) + (temps[6] << 8) +
- temps[7]);
+ result[i].network.s_addr = htonl ((temps[0] << 24) + (temps[1] << 16) +
+ (temps[2] << 8) + temps[3]);
+ result[i].netmask.s_addr = htonl ((temps[4] << 24) + (temps[5] << 16) +
+ (temps[6] << 8) + temps[7]);
pos = end + 1;
i++;
continue;
}
/* try second notation */
- cnt =
- SSCANF (&routeList[pos],
- "%u.%u.%u.%u/%u%1s",
- &temps[0],
- &temps[1],
- &temps[2],
- &temps[3],
- &slash,
- dummy);
+ cnt = sscanf (&routeList[pos],
+ "%u.%u.%u.%u/%u%1s",
+ &temps[0],
+ &temps[1],
+ &temps[2],
+ &temps[3],
+ &slash,
+ dummy);
if (5 == cnt)
{
for (j = 0; j < 4; j++)
if (temps[j] > 0xFF)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid format for IP: `%s'\n"),
+ _ ("Invalid format for IP: `%s'\n"),
&routeList[pos]);
GNUNET_free (result);
GNUNET_free (routeList);
return NULL;
}
- result[i].network.s_addr =
- htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
- temps[3]);
+ result[i].network.s_addr = htonl ((temps[0] << 24) + (temps[1] << 16) +
+ (temps[2] << 8) + temps[3]);
if ((slash <= 32) && (slash >= 0))
{
result[i].netmask.s_addr = 0;
while (slash > 0)
{
result[i].netmask.s_addr =
- (result[i].netmask.s_addr >> 1) + 0x80000000;
+ (result[i].netmask.s_addr >> 1) + 0x80000000;
slash--;
}
result[i].netmask.s_addr = htonl (result[i].netmask.s_addr);
@@ -1775,38 +1746,36 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX)
else
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."),
+ _ ("Invalid network notation ('/%d' is not legal in IPv4 CIDR)."),
slash);
GNUNET_free (result);
- GNUNET_free (routeList);
- return NULL; /* error */
+ GNUNET_free (routeList);
+ return NULL; /* error */
}
}
/* try third notation */
slash = 32;
- cnt =
- SSCANF (&routeList[pos],
- "%u.%u.%u.%u%1s",
- &temps[0],
- &temps[1],
- &temps[2],
- &temps[3],
- dummy);
+ cnt = sscanf (&routeList[pos],
+ "%u.%u.%u.%u%1s",
+ &temps[0],
+ &temps[1],
+ &temps[2],
+ &temps[3],
+ dummy);
if (4 == cnt)
{
for (j = 0; j < 4; j++)
if (temps[j] > 0xFF)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid format for IP: `%s'\n"),
+ _ ("Invalid format for IP: `%s'\n"),
&routeList[pos]);
GNUNET_free (result);
GNUNET_free (routeList);
return NULL;
}
- result[i].network.s_addr =
- htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
- temps[3]);
+ result[i].network.s_addr = htonl ((temps[0] << 24) + (temps[1] << 16) +
+ (temps[2] << 8) + temps[3]);
result[i].netmask.s_addr = 0;
while (slash > 0)
{
@@ -1819,23 +1788,23 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX)
continue;
}
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid format for IP: `%s'\n"),
+ _ ("Invalid format for IP: `%s'\n"),
&routeList[pos]);
GNUNET_free (result);
GNUNET_free (routeList);
- return NULL; /* error */
+ return NULL; /* error */
}
if (pos < strlen (routeList))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid format: `%s'\n"),
+ _ ("Invalid format: `%s'\n"),
&routeListX[pos]);
GNUNET_free (result);
GNUNET_free (routeList);
- return NULL; /* oops */
+ return NULL; /* oops */
}
GNUNET_free (routeList);
- return result; /* ok */
+ return result; /* ok */
}
@@ -1867,7 +1836,7 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
int save;
int colon;
char dummy[2];
-
+
if (NULL == routeListX)
return NULL;
len = strlen (routeListX);
@@ -1881,13 +1850,14 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
if (';' != routeList[len - 1])
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Invalid network notation (does not end with ';': `%s')\n"),
+ _ ("Invalid network notation (does not end with ';': `%s')\n"),
routeList);
GNUNET_free (routeList);
return NULL;
}
- result = GNUNET_malloc (sizeof (struct GNUNET_STRINGS_IPv6NetworkPolicy) * (count + 1));
+ result = GNUNET_malloc (sizeof (struct GNUNET_STRINGS_IPv6NetworkPolicy) *
+ (count + 1));
i = 0;
pos = 0;
while (i < count)
@@ -1901,9 +1871,7 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
if (slash < start)
{
- memset (&result[i].netmask,
- 0xFF,
- sizeof (struct in6_addr));
+ memset (&result[i].netmask, 0xFF, sizeof (struct in6_addr));
slash = pos;
}
else
@@ -1915,8 +1883,8 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
if (':' == routeList[colon])
{
routeList[colon] = '\0';
- if (GNUNET_OK != parse_port_policy (&routeList[colon + 1],
- &result[i].pp))
+ if (GNUNET_OK !=
+ parse_port_policy (&routeList[colon + 1], &result[i].pp))
{
GNUNET_free (result);
GNUNET_free (routeList);
@@ -1927,15 +1895,12 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
if (ret <= 0)
{
save = errno;
- if ( (1 != SSCANF (&routeList[slash + 1],
- "%u%1s",
- &bits,
- dummy)) ||
- (bits > 128) )
+ if ((1 != sscanf (&routeList[slash + 1], "%u%1s", &bits, dummy)) ||
+ (bits > 128))
{
if (0 == ret)
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Wrong format `%s' for netmask\n"),
+ _ ("Wrong format `%s' for netmask\n"),
&routeList[slash + 1]);
else
{
@@ -1955,7 +1920,7 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
while (bits > 0)
{
result[i].netmask.s6_addr[off] =
- (result[i].netmask.s6_addr[off] >> 1) + 0x80;
+ (result[i].netmask.s6_addr[off] >> 1) + 0x80;
bits--;
}
}
@@ -1966,11 +1931,10 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
{
if (0 == ret)
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Wrong format `%s' for network\n"),
+ _ ("Wrong format `%s' for network\n"),
&routeList[slash + 1]);
else
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "inet_pton");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "inet_pton");
GNUNET_free (result);
GNUNET_free (routeList);
return NULL;
@@ -1983,12 +1947,12 @@ GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX)
}
-
/** ******************** Base64 encoding ***********/
#define FILLCHAR '='
-static char *cvt =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/";
+static char *cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789+/";
/**
@@ -2001,9 +1965,7 @@ static char *cvt =
* @return the size of the output
*/
size_t
-GNUNET_STRINGS_base64_encode (const void *in,
- size_t len,
- char **output)
+GNUNET_STRINGS_base64_encode (const void *in, size_t len, char **output)
{
const char *data = in;
size_t ret;
@@ -2047,11 +2009,14 @@ GNUNET_STRINGS_base64_encode (const void *in,
return ret;
}
-#define cvtfind(a)( (((a) >= 'A')&&((a) <= 'Z'))? (a)-'A'\
- :(((a)>='a')&&((a)<='z')) ? (a)-'a'+26\
- :(((a)>='0')&&((a)<='9')) ? (a)-'0'+52\
- :((a) == '+') ? 62\
- :((a) == '/') ? 63 : -1)
+#define cvtfind(a) \
+ ((((a) >= 'A') && ((a) <= 'Z')) \
+ ? (a) - 'A' \
+ : (((a) >= 'a') && ((a) <= 'z')) \
+ ? (a) - 'a' + 26 \
+ : (((a) >= '0') && ((a) <= '9')) \
+ ? (a) - '0' + 52 \
+ : ((a) == '+') ? 62 : ((a) == '/') ? 63 : -1)
/**
@@ -2064,18 +2029,20 @@ GNUNET_STRINGS_base64_encode (const void *in,
* @return the size of the output
*/
size_t
-GNUNET_STRINGS_base64_decode (const char *data,
- size_t len,
- void **out)
+GNUNET_STRINGS_base64_decode (const char *data, size_t len, void **out)
{
char *output;
size_t ret = 0;
-#define CHECK_CRLF while (data[i] == '\r' || data[i] == '\n') {\
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "ignoring CR/LF\n"); \
- i++; \
- if (i >= len) goto END; \
- }
+#define CHECK_CRLF \
+ while (data[i] == '\r' || data[i] == '\n') \
+ { \
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, \
+ "ignoring CR/LF\n"); \
+ i++; \
+ if (i >= len) \
+ goto END; \
+ }
output = GNUNET_malloc ((len * 3 / 4) + 8);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/util/test_common_allocation.c b/src/util/test_common_allocation.c
index 476934b3f..fcc453d6b 100644
--- a/src/util/test_common_allocation.c
+++ b/src/util/test_common_allocation.c
@@ -144,7 +144,7 @@ main (int argc, char *argv[])
NULL);
ret = check ();
if (ret != 0)
- FPRINTF (stderr,
+ fprintf (stderr,
"ERROR %d.\n",
ret);
return ret;
diff --git a/src/util/test_common_logging.c b/src/util/test_common_logging.c
index 396bf3966..6ae50b36b 100644
--- a/src/util/test_common_logging.c
+++ b/src/util/test_common_logging.c
@@ -44,7 +44,7 @@ main (int argc, char *argv[])
unsigned int logs = 0;
if (0 != putenv ("GNUNET_FORCE_LOG="))
- FPRINTF (stderr, "Failed to putenv: %s\n", strerror (errno));
+ fprintf (stderr, "Failed to putenv: %s\n", strerror (errno));
GNUNET_log_setup ("test-common-logging", "DEBUG", "/dev/null");
GNUNET_logger_add (&my_log, &logs);
GNUNET_logger_add (&my_log, &logs);
@@ -60,7 +60,7 @@ main (int argc, char *argv[])
GNUNET_logger_remove (&my_log, &logs);
if (logs != 4)
{
- FPRINTF (stdout, "Expected 4 log calls, got %u\n", logs);
+ fprintf (stdout, "Expected 4 log calls, got %u\n", logs);
failureCount++;
}
GNUNET_break (0 ==
@@ -84,13 +84,13 @@ main (int argc, char *argv[])
GNUNET_logger_remove (&my_log, &logs);
if (logs != 1)
{
- FPRINTF (stdout, "Expected 1 log call, got %u\n", logs);
+ fprintf (stdout, "Expected 1 log call, got %u\n", logs);
failureCount++;
}
if (failureCount != 0)
{
- FPRINTF (stdout, "%u TESTS FAILED!\n", failureCount);
+ fprintf (stdout, "%u TESTS FAILED!\n", failureCount);
return -1;
}
return 0;
diff --git a/src/util/test_common_logging_dummy.c b/src/util/test_common_logging_dummy.c
index 5c3709206..d3c6e3452 100644
--- a/src/util/test_common_logging_dummy.c
+++ b/src/util/test_common_logging_dummy.c
@@ -51,7 +51,7 @@ my_log (void *ctx,
(void) date;
if (strncmp ("test-common-logging-dummy", component, 25) != 0)
return;
- FPRINTF (stdout, "%s", msg);
+ fprintf (stdout, "%s", msg);
fflush (stdout);
}
diff --git a/src/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c
index 7c72acf7d..8da808760 100644
--- a/src/util/test_common_logging_runtime_loglevels.c
+++ b/src/util/test_common_logging_runtime_loglevels.c
@@ -237,7 +237,7 @@ read_call (void *cls)
buf_ptr += rd;
bytes += rd;
#if VERBOSE
- FPRINTF (stderr, "got %d bytes, reading more\n", rd);
+ fprintf (stderr, "got %d bytes, reading more\n", rd);
#endif
read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
stdout_read_handle,
@@ -247,7 +247,7 @@ read_call (void *cls)
}
#if VERBOSE
- FPRINTF (stderr, "bytes is %d:%s\n", bytes, buf);
+ fprintf (stderr, "bytes is %d:%s\n", bytes, buf);
#endif
/* +------CHILD OUTPUT--
@@ -334,7 +334,7 @@ read_call (void *cls)
&bytes, &delays[7], level)))
{
if (bytes == LOG_BUFFER_SIZE)
- FPRINTF (stderr, "%s", "Ran out of buffer space!\n");
+ fprintf (stderr, "%s", "Ran out of buffer space!\n");
GNUNET_break (0);
ok = 2;
GNUNET_SCHEDULER_cancel (die_task);
diff --git a/src/util/test_configuration.c b/src/util/test_configuration.c
index 96f13eefe..67e532f40 100644
--- a/src/util/test_configuration.c
+++ b/src/util/test_configuration.c
@@ -236,14 +236,14 @@ checkDiffs (struct GNUNET_CONFIGURATION_Handle *cfg_default, int option)
GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData);
if (1 == (ret = cbData.status))
{
- FPRINTF (stderr, "%s",
+ fprintf (stderr, "%s",
"Incorrect Configuration Diffs: Diffs may contain data not actually edited\n");
goto housekeeping;
}
cbData.cfgDiffs = cfg;
GNUNET_CONFIGURATION_iterate (cfgDiffs, diffsCallBack, &cbData);
if ((ret = cbData.status) == 1)
- FPRINTF (stderr, "%s",
+ fprintf (stderr, "%s",
"Incorrect Configuration Diffs: Data may be missing in diffs\n");
housekeeping:
@@ -273,7 +273,7 @@ testConfig ()
return 1;
if (0 != strcmp ("b", c))
{
- FPRINTF (stderr, "Got `%s'\n", c);
+ fprintf (stderr, "Got `%s'\n", c);
GNUNET_free (c);
return 2;
}
@@ -466,7 +466,7 @@ main (int argc, char *argv[])
if (GNUNET_OK !=
GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf"))
{
- FPRINTF (stderr, "%s", "Failed to parse configuration file\n");
+ fprintf (stderr, "%s", "Failed to parse configuration file\n");
GNUNET_CONFIGURATION_destroy (cfg);
return 1;
}
@@ -480,12 +480,12 @@ main (int argc, char *argv[])
if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf"))
{
- FPRINTF (stderr, "%s", "Failed to write configuration file\n");
+ fprintf (stderr, "%s", "Failed to write configuration file\n");
GNUNET_CONFIGURATION_destroy (cfg);
return 1;
}
GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf"));
+ GNUNET_assert (0 == unlink ("/tmp/gnunet-test.conf"));
cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_OK !=
@@ -542,7 +542,7 @@ main (int argc, char *argv[])
error:
if (failureCount != 0)
{
- FPRINTF (stderr, "Test failed: %u\n", failureCount);
+ fprintf (stderr, "Test failed: %u\n", failureCount);
return 1;
}
return 0;
diff --git a/src/util/test_container_bloomfilter.c b/src/util/test_container_bloomfilter.c
index 42849af97..043eacafd 100644
--- a/src/util/test_container_bloomfilter.c
+++ b/src/util/test_container_bloomfilter.c
@@ -35,13 +35,13 @@
* Generate a random hashcode.
*/
static void
-nextHC (struct GNUNET_HashCode * hc)
+nextHC (struct GNUNET_HashCode *hc)
{
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, hc);
}
static int
-add_iterator (void *cls, struct GNUNET_HashCode * next)
+add_iterator (void *cls, struct GNUNET_HashCode *next)
{
int *ret = cls;
struct GNUNET_HashCode pos;
@@ -68,8 +68,8 @@ main (int argc, char *argv[])
GNUNET_log_setup ("test-container-bloomfilter", "WARNING", NULL);
GNUNET_CRYPTO_seed_weak_random (1);
- if (0 == STAT (TESTFILE, &sbuf))
- if (0 != UNLINK (TESTFILE))
+ if (0 == stat (TESTFILE, &sbuf))
+ if (0 != unlink (TESTFILE))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "unlink", TESTFILE);
bf = GNUNET_CONTAINER_bloomfilter_load (TESTFILE, SIZE, K);
@@ -88,7 +88,9 @@ main (int argc, char *argv[])
}
if (ok1 != 200)
{
- printf ("Got %d elements out of" "200 expected after insertion.\n", ok1);
+ printf ("Got %d elements out of"
+ "200 expected after insertion.\n",
+ ok1);
GNUNET_CONTAINER_bloomfilter_free (bf);
return -1;
}
@@ -118,7 +120,9 @@ main (int argc, char *argv[])
}
if (ok1 != 200)
{
- printf ("Got %d elements out of 200 " "expected after reloading.\n", ok1);
+ printf ("Got %d elements out of 200 "
+ "expected after reloading.\n",
+ ok1);
GNUNET_CONTAINER_bloomfilter_free (bf);
GNUNET_CONTAINER_bloomfilter_free (bfi);
return -1;
@@ -126,7 +130,8 @@ main (int argc, char *argv[])
if (ok2 != 200)
{
- printf ("Got %d elements out of 200 " "expected after initialization.\n",
+ printf ("Got %d elements out of 200 "
+ "expected after initialization.\n",
ok2);
GNUNET_CONTAINER_bloomfilter_free (bf);
GNUNET_CONTAINER_bloomfilter_free (bfi);
@@ -157,7 +162,8 @@ main (int argc, char *argv[])
if (ok1 != 100)
{
printf ("Expected 100 elements in loaded filter"
- " after adding 200 and deleting 100, got %d\n", ok1);
+ " after adding 200 and deleting 100, got %d\n",
+ ok1);
GNUNET_CONTAINER_bloomfilter_free (bf);
GNUNET_CONTAINER_bloomfilter_free (bfi);
return -1;
@@ -220,7 +226,8 @@ main (int argc, char *argv[])
if (ok1 != 20)
{
printf ("Expected 20 elements in resized file-backed filter"
- " after adding 20, got %d\n", ok1);
+ " after adding 20, got %d\n",
+ ok1);
GNUNET_CONTAINER_bloomfilter_free (bf);
GNUNET_CONTAINER_bloomfilter_free (bfi);
return -1;
@@ -228,7 +235,8 @@ main (int argc, char *argv[])
if (ok2 != 20)
{
printf ("Expected 20 elements in resized filter"
- " after adding 20, got %d\n", ok2);
+ " after adding 20, got %d\n",
+ ok2);
GNUNET_CONTAINER_bloomfilter_free (bf);
GNUNET_CONTAINER_bloomfilter_free (bfi);
return -1;
@@ -238,6 +246,6 @@ main (int argc, char *argv[])
GNUNET_CONTAINER_bloomfilter_free (bf);
GNUNET_CONTAINER_bloomfilter_free (bfi);
- GNUNET_break (0 == UNLINK (TESTFILE));
+ GNUNET_break (0 == unlink (TESTFILE));
return 0;
}
diff --git a/src/util/test_crypto_ecc_dlog.c b/src/util/test_crypto_ecc_dlog.c
index 0b0b8d57c..c0828c354 100644
--- a/src/util/test_crypto_ecc_dlog.c
+++ b/src/util/test_crypto_ecc_dlog.c
@@ -172,7 +172,7 @@ main (int argc, char *argv[])
if (! gcry_check_version ("1.6.0"))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_
("libgcrypt has not the expected version (version %s is required).\n"),
"1.6.0");
diff --git a/src/util/test_crypto_ecdh_eddsa.c b/src/util/test_crypto_ecdh_eddsa.c
index 721f831d0..00f85033e 100644
--- a/src/util/test_crypto_ecdh_eddsa.c
+++ b/src/util/test_crypto_ecdh_eddsa.c
@@ -74,7 +74,7 @@ main (int argc, char *argv[])
{
if (! gcry_check_version ("1.6.0"))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_("libgcrypt has not the expected version (version %s is required).\n"),
"1.6.0");
return 0;
diff --git a/src/util/test_crypto_ecdhe.c b/src/util/test_crypto_ecdhe.c
index c4392ca5a..71fe9b570 100644
--- a/src/util/test_crypto_ecdhe.c
+++ b/src/util/test_crypto_ecdhe.c
@@ -40,7 +40,7 @@ main (int argc, char *argv[])
if (! gcry_check_version ("1.6.0"))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_
("libgcrypt has not the expected version (version %s is required).\n"),
"1.6.0");
diff --git a/src/util/test_crypto_ecdsa.c b/src/util/test_crypto_ecdsa.c
index 8fa5eb486..00cc72af4 100644
--- a/src/util/test_crypto_ecdsa.c
+++ b/src/util/test_crypto_ecdsa.c
@@ -46,7 +46,7 @@ testSignVerify ()
struct GNUNET_TIME_Absolute start;
int ok = GNUNET_OK;
- FPRINTF (stderr, "%s", "W");
+ fprintf (stderr, "%s", "W");
GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey);
start = GNUNET_TIME_absolute_get ();
purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
@@ -54,10 +54,10 @@ testSignVerify ()
for (i = 0; i < ITER; i++)
{
- FPRINTF (stderr, "%s", "."); fflush (stderr);
+ fprintf (stderr, "%s", "."); fflush (stderr);
if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (key, &purp, &sig))
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
"GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n");
ok = GNUNET_SYSERR;
@@ -103,7 +103,7 @@ testDeriveSignVerify ()
if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (dpriv, &purp, &sig))
{
- FPRINTF (stderr, "%s", "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n");
+ fprintf (stderr, "%s", "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n");
GNUNET_free (dpriv);
return GNUNET_SYSERR;
}
@@ -151,15 +151,15 @@ testSignPerformance ()
purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
- FPRINTF (stderr, "%s", "W");
+ fprintf (stderr, "%s", "W");
GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey);
start = GNUNET_TIME_absolute_get ();
for (i = 0; i < ITER; i++)
{
- FPRINTF (stderr, "%s", "."); fflush (stderr);
+ fprintf (stderr, "%s", "."); fflush (stderr);
if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (key, &purp, &sig))
{
- FPRINTF (stderr, "%s",
+ fprintf (stderr, "%s",
"GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n");
ok = GNUNET_SYSERR;
continue;
@@ -180,7 +180,7 @@ perf_keygen ()
struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
int i;
- FPRINTF (stderr, "%s", "W");
+ fprintf (stderr, "%s", "W");
start = GNUNET_TIME_absolute_get ();
for (i=0;i<10;i++)
{
@@ -203,7 +203,7 @@ main (int argc, char *argv[])
if (! gcry_check_version ("1.6.0"))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_
("libgcrypt has not the expected version (version %s is required).\n"),
"1.6.0");
diff --git a/src/util/test_crypto_eddsa.c b/src/util/test_crypto_eddsa.c
index e738f7e6c..acb5fbdf5 100644
--- a/src/util/test_crypto_eddsa.c
+++ b/src/util/test_crypto_eddsa.c
@@ -48,7 +48,7 @@ testSignVerify ()
struct GNUNET_TIME_Absolute start;
int ok = GNUNET_OK;
- FPRINTF (stderr, "%s", "W");
+ fprintf (stderr, "%s", "W");
GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey);
start = GNUNET_TIME_absolute_get ();
purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
@@ -56,10 +56,10 @@ testSignVerify ()
for (i = 0; i < ITER; i++)
{
- FPRINTF (stderr, "%s", "."); fflush (stderr);
+ fprintf (stderr, "%s", "."); fflush (stderr);
if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign (key, &purp, &sig))
{
- FPRINTF (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n");
+ fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n");
ok = GNUNET_SYSERR;
continue;
}
@@ -99,15 +99,15 @@ testSignPerformance ()
purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
- FPRINTF (stderr, "%s", "W");
+ fprintf (stderr, "%s", "W");
GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey);
start = GNUNET_TIME_absolute_get ();
for (i = 0; i < ITER; i++)
{
- FPRINTF (stderr, "%s", "."); fflush (stderr);
+ fprintf (stderr, "%s", "."); fflush (stderr);
if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign (key, &purp, &sig))
{
- FPRINTF (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n");
+ fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n");
ok = GNUNET_SYSERR;
continue;
}
@@ -135,7 +135,7 @@ testCreateFromFile ()
GNUNET_CRYPTO_eddsa_key_get_public (key, &p2);
GNUNET_assert (0 == memcmp (&p1, &p2, sizeof (p1)));
GNUNET_free (key);
- GNUNET_assert (0 == UNLINK (KEYFILE));
+ GNUNET_assert (0 == unlink (KEYFILE));
key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE);
GNUNET_assert (NULL != key);
GNUNET_CRYPTO_eddsa_key_get_public (key, &p2);
@@ -152,7 +152,7 @@ perf_keygen ()
struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
int i;
- FPRINTF (stderr, "%s", "W");
+ fprintf (stderr, "%s", "W");
start = GNUNET_TIME_absolute_get ();
for (i=0;i<10;i++)
{
@@ -175,7 +175,7 @@ main (int argc, char *argv[])
if (! gcry_check_version ("1.6.0"))
{
- FPRINTF (stderr,
+ fprintf (stderr,
_("libgcrypt has not the expected version (version %s is required).\n"),
"1.6.0");
return 0;
@@ -193,7 +193,7 @@ main (int argc, char *argv[])
GNUNET_free (key);
if (GNUNET_OK != testCreateFromFile ())
failure_count++;
- GNUNET_assert (0 == UNLINK (KEYFILE));
+ GNUNET_assert (0 == unlink (KEYFILE));
perf_keygen ();
if (0 != failure_count)
diff --git a/src/util/test_crypto_hash.c b/src/util/test_crypto_hash.c
index 52e24718d..e08348e53 100644
--- a/src/util/test_crypto_hash.c
+++ b/src/util/test_crypto_hash.c
@@ -130,12 +130,12 @@ testFileHash ()
memset (block, 42, sizeof (block) / 2);
memset (&block[sizeof (block) / 2], 43, sizeof (block) / 2);
- GNUNET_assert (NULL != (f = FOPEN (FILENAME, "w+")));
+ GNUNET_assert (NULL != (f = fopen (FILENAME, "w+")));
GNUNET_break (sizeof (block) == fwrite (block, 1, sizeof (block), f));
- GNUNET_break (0 == FCLOSE (f));
+ GNUNET_break (0 == fclose (f));
ret = 1;
GNUNET_SCHEDULER_run (&file_hasher, &ret);
- GNUNET_break (0 == UNLINK (FILENAME));
+ GNUNET_break (0 == unlink (FILENAME));
return ret;
}
diff --git a/src/util/test_crypto_random.c b/src/util/test_crypto_random.c
index dec58086a..6386c79db 100644
--- a/src/util/test_crypto_random.c
+++ b/src/util/test_crypto_random.c
@@ -42,7 +42,7 @@ test (enum GNUNET_CRYPTO_Quality mode)
b2 = GNUNET_CRYPTO_random_permute (mode, 1024);
if (0 == memcmp (b2, buf, sizeof (buf)))
{
- FPRINTF (stderr, "%s", "!");
+ fprintf (stderr, "%s", "!");
GNUNET_free (b2);
continue;
}
diff --git a/src/util/test_disk.c b/src/util/test_disk.c
index 267d4d4f9..5746aa96e 100644
--- a/src/util/test_disk.c
+++ b/src/util/test_disk.c
@@ -45,13 +45,13 @@ testReadWrite ()
ret = GNUNET_DISK_fn_read (".testfile", tmp, sizeof (tmp) - 1);
if (ret < 0)
{
- FPRINTF (stderr, "Error reading file `%s' in testReadWrite\n", ".testfile");
+ fprintf (stderr, "Error reading file `%s' in testReadWrite\n", ".testfile");
return 1;
}
tmp[ret] = '\0';
if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1))
{
- FPRINTF (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
+ fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
TESTSTRING, ".testfile");
return 1;
}
@@ -60,20 +60,20 @@ testReadWrite ()
ret = GNUNET_DISK_fn_read (".testfile2", tmp, sizeof (tmp) - 1);
if (ret < 0)
{
- FPRINTF (stderr, "Error reading file `%s' in testReadWrite\n",
+ fprintf (stderr, "Error reading file `%s' in testReadWrite\n",
".testfile2");
return 1;
}
tmp[ret] = '\0';
if (0 != memcmp (tmp, TESTSTRING, strlen (TESTSTRING) + 1))
{
- FPRINTF (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
+ fprintf (stderr, "Error in testReadWrite: *%s* != *%s* for file %s\n", tmp,
TESTSTRING, ".testfile2");
return 1;
}
- GNUNET_break (0 == UNLINK (".testfile"));
- GNUNET_break (0 == UNLINK (".testfile2"));
+ GNUNET_break (0 == unlink (".testfile"));
+ GNUNET_break (0 == unlink (".testfile2"));
if (GNUNET_NO != GNUNET_DISK_file_test (".testfile"))
return 1;
@@ -99,7 +99,7 @@ testOpenClose ()
GNUNET_DISK_file_size (".testfile", &size, GNUNET_NO, GNUNET_YES));
if (size != 5)
return 1;
- GNUNET_break (0 == UNLINK (".testfile"));
+ GNUNET_break (0 == unlink (".testfile"));
return 0;
}
@@ -281,7 +281,7 @@ main (int argc, char *argv[])
failureCount += testDirMani ();
if (0 != failureCount)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"\n%u TESTS FAILED!\n",
failureCount);
return -1;
diff --git a/src/util/test_getopt.c b/src/util/test_getopt.c
index 4294117a6..d9dd7121f 100644
--- a/src/util/test_getopt.c
+++ b/src/util/test_getopt.c
@@ -28,13 +28,9 @@
static int
testMinimal ()
{
- char *const emptyargv[] = {
- "test",
- NULL
- };
+ char *const emptyargv[] = {"test", NULL};
const struct GNUNET_GETOPT_CommandLineOption emptyoptionlist[] = {
- GNUNET_GETOPT_OPTION_END
- };
+ GNUNET_GETOPT_OPTION_END};
if (1 != GNUNET_GETOPT_run ("test", emptyoptionlist, 1, emptyargv))
return 1;
@@ -46,19 +42,11 @@ testMinimal ()
static int
testVerbose ()
{
- char *const myargv[] = {
- "test",
- "-V",
- "-V",
- "more",
- NULL
- };
+ char *const myargv[] = {"test", "-V", "-V", "more", NULL};
unsigned int vflags = 0;
- const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] = {
- GNUNET_GETOPT_option_verbose (&vflags),
- GNUNET_GETOPT_OPTION_END
- };
+ const struct GNUNET_GETOPT_CommandLineOption verboseoptionlist[] =
+ {GNUNET_GETOPT_option_verbose (&vflags), GNUNET_GETOPT_OPTION_END};
if (3 != GNUNET_GETOPT_run ("test", verboseoptionlist, 4, myargv))
{
@@ -77,15 +65,10 @@ testVerbose ()
static int
testVersion ()
{
- char *const myargv[] = {
- "test_getopt",
- "-v",
- NULL
- };
- const struct GNUNET_GETOPT_CommandLineOption versionoptionlist[] = {
- GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
- GNUNET_GETOPT_OPTION_END
- };
+ char *const myargv[] = {"test_getopt", "-v", NULL};
+ const struct GNUNET_GETOPT_CommandLineOption versionoptionlist[] =
+ {GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
+ GNUNET_GETOPT_OPTION_END};
if (0 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv))
{
@@ -99,15 +82,9 @@ testVersion ()
static int
testAbout ()
{
- char *const myargv[] = {
- "test_getopt",
- "-h",
- NULL
- };
- const struct GNUNET_GETOPT_CommandLineOption aboutoptionlist[] = {
- GNUNET_GETOPT_option_help ("Testing"),
- GNUNET_GETOPT_OPTION_END
- };
+ char *const myargv[] = {"test_getopt", "-h", NULL};
+ const struct GNUNET_GETOPT_CommandLineOption aboutoptionlist[] =
+ {GNUNET_GETOPT_option_help ("Testing"), GNUNET_GETOPT_OPTION_END};
if (0 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv))
{
@@ -121,31 +98,23 @@ testAbout ()
static int
testLogOpts ()
{
- char *const myargv[] = {
- "test_getopt",
- "-l", "filename",
- "-L", "WARNING",
- NULL
- };
+ char *const myargv[] =
+ {"test_getopt", "-l", "filename", "-L", "WARNING", NULL};
char *level = GNUNET_strdup ("stuff");
char *fn = NULL;
- const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
- GNUNET_GETOPT_option_logfile (&fn),
- GNUNET_GETOPT_option_loglevel (&level),
- GNUNET_GETOPT_OPTION_END
- };
+ const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] =
+ {GNUNET_GETOPT_option_logfile (&fn),
+ GNUNET_GETOPT_option_loglevel (&level),
+ GNUNET_GETOPT_OPTION_END};
- if (5 != GNUNET_GETOPT_run ("test_getopt",
- logoptionlist,
- 5, myargv))
+ if (5 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 5, myargv))
{
GNUNET_break (0);
return 1;
}
GNUNET_assert (NULL != fn);
- if ( (0 != strcmp (level, "WARNING")) ||
- (NULL == strstr (fn, "/filename")) )
+ if ((0 != strcmp (level, "WARNING")) || (NULL == strstr (fn, "/filename")))
{
GNUNET_break (0);
GNUNET_free (level);
@@ -161,47 +130,23 @@ testLogOpts ()
static int
testFlagNum ()
{
- char *const myargv[] = {
- "test_getopt",
- "-f",
- "-n", "42",
- "-N", "42",
- NULL
- };
+ char *const myargv[] = {"test_getopt", "-f", "-n", "42", "-N", "42", NULL};
int flag = 0;
unsigned int num = 0;
unsigned long long lnum = 0;
- const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] = {
- GNUNET_GETOPT_option_flag ('f',
- "--flag",
- "helptext",
- &flag),
- GNUNET_GETOPT_option_uint ('n',
- "--num",
- "ARG",
- "helptext",
- &num),
- GNUNET_GETOPT_option_ulong ('N',
- "--lnum",
- "ARG",
- "helptext",
- &lnum),
- GNUNET_GETOPT_OPTION_END
- };
-
- if (6 !=
- GNUNET_GETOPT_run ("test_getopt",
- logoptionlist,
- 6,
- myargv))
+ const struct GNUNET_GETOPT_CommandLineOption logoptionlist[] =
+ {GNUNET_GETOPT_option_flag ('f', "--flag", "helptext", &flag),
+ GNUNET_GETOPT_option_uint ('n', "--num", "ARG", "helptext", &num),
+ GNUNET_GETOPT_option_ulong ('N', "--lnum", "ARG", "helptext", &lnum),
+ GNUNET_GETOPT_OPTION_END};
+
+ if (6 != GNUNET_GETOPT_run ("test_getopt", logoptionlist, 6, myargv))
{
GNUNET_break (0);
return 1;
}
- if ( (1 != flag) ||
- (42 != num) ||
- (42 != lnum))
+ if ((1 != flag) || (42 != num) || (42 != lnum))
{
GNUNET_break (0);
return 1;
@@ -215,12 +160,10 @@ main (int argc, char *argv[])
{
int errCnt = 0;
- GNUNET_log_setup ("test_getopt",
- "WARNING",
- NULL);
+ GNUNET_log_setup ("test_getopt", "WARNING", NULL);
/* suppress output from -h, -v options */
#ifndef MINGW
- GNUNET_break (0 == CLOSE (1));
+ GNUNET_break (0 == close (1));
#endif
if (0 != testMinimal ())
errCnt++;
diff --git a/src/util/test_peer.c b/src/util/test_peer.c
index 248836b4c..b059f2cf3 100644
--- a/src/util/test_peer.c
+++ b/src/util/test_peer.c
@@ -65,7 +65,7 @@ check ()
pid = GNUNET_PEER_intern (&pidArr[i]);
if (pid != (i + 1))
{
- FPRINTF (stderr, "%s", "Unexpected Peer ID returned by intern function\n");
+ fprintf (stderr, "%s", "Unexpected Peer ID returned by intern function\n");
return 1;
}
}
@@ -76,7 +76,7 @@ check ()
pid = GNUNET_PEER_intern (&pidArr[i]);
if (pid != (i + 1))
{
- FPRINTF (stderr, "%s", "Unexpected Peer ID returned by intern function\n");
+ fprintf (stderr, "%s", "Unexpected Peer ID returned by intern function\n");
return 1;
}
}
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c
index 686301694..f4184aa84 100644
--- a/src/util/test_resolver_api.c
+++ b/src/util/test_resolver_api.c
@@ -229,7 +229,7 @@ run (void *cls, char *const *args, const char *cfgfile,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("gethostbyname() could not lookup IP address: %s\n"),
hstrerror (h_errno));
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
"System seems to be off-line, will not run all DNS tests\n");
*ok = 0; /* mark test as passing anyway */
@@ -373,7 +373,7 @@ main (int argc, char *argv[])
GNUNET_OS_process_destroy (proc);
proc = NULL;
if (0 != ok)
- FPRINTF (stderr, "Missed some resolutions: %u\n", ok);
+ fprintf (stderr, "Missed some resolutions: %u\n", ok);
return ok;
}
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c
index c38af8a0a..234a2aae1 100644
--- a/src/util/test_scheduler.c
+++ b/src/util/test_scheduler.c
@@ -224,7 +224,7 @@ taskSig (void *cls)
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
&taskNeverRun,
NULL);
- GNUNET_break (0 == PLIBC_KILL (getpid (),
+ GNUNET_break (0 == kill (getpid (),
GNUNET_TERM_SIG));
}
diff --git a/src/util/test_scheduler_delay.c b/src/util/test_scheduler_delay.c
index 6c25531f2..1ec86c647 100644
--- a/src/util/test_scheduler_delay.c
+++ b/src/util/test_scheduler_delay.c
@@ -55,10 +55,10 @@ test_task (void *cls)
target =
GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MICROSECONDS, i));
- FPRINTF (stderr, "%s", ".");
+ fprintf (stderr, "%s", ".");
if (i > MAXV)
{
- FPRINTF (stderr, "%s", "\n");
+ fprintf (stderr, "%s", "\n");
return;
}
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
@@ -77,17 +77,17 @@ main (int argc, char *argv[])
NULL);
target = GNUNET_TIME_absolute_get ();
GNUNET_SCHEDULER_run (&test_task, NULL);
- FPRINTF (stdout,
+ fprintf (stdout,
"Sleep precision: %llu microseconds (average delta). ",
cumDelta / (MAXV / INCR));
if (cumDelta <= 500 * MAXV / INCR)
- FPRINTF (stdout, "%s", "Timer precision is excellent.\n");
+ fprintf (stdout, "%s", "Timer precision is excellent.\n");
else if (cumDelta <= 5000 * MAXV / INCR) /* 5 ms average deviation */
- FPRINTF (stdout, "%s", "Timer precision is good.\n");
+ fprintf (stdout, "%s", "Timer precision is good.\n");
else if (cumDelta > 25000 * MAXV / INCR)
- FPRINTF (stdout, "%s", "Timer precision is awful.\n");
+ fprintf (stdout, "%s", "Timer precision is awful.\n");
else
- FPRINTF (stdout, "%s", "Timer precision is acceptable.\n");
+ fprintf (stdout, "%s", "Timer precision is acceptable.\n");
return 0;
}
diff --git a/src/util/test_service.c b/src/util/test_service.c
index 72bd1f371..dc8bc59c1 100644
--- a/src/util/test_service.c
+++ b/src/util/test_service.c
@@ -222,7 +222,7 @@ main (int argc,
"socket");
return 1;
}
- FPRINTF (stderr,
+ fprintf (stderr,
"IPv6 support seems to not be available (%s), not testing it!\n",
strerror (errno));
}
diff --git a/src/util/test_strings.c b/src/util/test_strings.c
index 652c3be23..9e4e808ef 100644
--- a/src/util/test_strings.c
+++ b/src/util/test_strings.c
@@ -93,7 +93,7 @@ main (int argc, char *argv[])
* however, the "0:05 19" should always be there; hence: */
if (NULL == strstr (bc, "0:05 19"))
{
- FPRINTF (stderr, "Got %s\n", bc);
+ fprintf (stderr, "Got %s\n", bc);
GNUNET_break (0);
return 1;
}
diff --git a/src/util/time.c b/src/util/time.c
index 758921718..85a781aff 100644
--- a/src/util/time.c
+++ b/src/util/time.c
@@ -37,7 +37,7 @@
#endif
#endif
-#define LOG(kind,...) GNUNET_log_from (kind, "util-time", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-time", __VA_ARGS__)
/**
* Variable used to simulate clock skew. Used for testing, never in production.
@@ -120,10 +120,10 @@ GNUNET_TIME_absolute_get ()
struct GNUNET_TIME_Absolute ret;
struct timeval tv;
- GETTIMEOFDAY (&tv, NULL);
- ret.abs_value_us =
- (uint64_t) (((uint64_t) tv.tv_sec * 1000LL * 1000LL) +
- ((uint64_t) tv.tv_usec)) + timestamp_offset;
+ gettimeofday (&tv, NULL);
+ ret.abs_value_us = (uint64_t) (((uint64_t) tv.tv_sec * 1000LL * 1000LL) +
+ ((uint64_t) tv.tv_usec)) +
+ timestamp_offset;
return ret;
}
@@ -158,7 +158,7 @@ GNUNET_TIME_absolute_get_zero_ ()
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_get_unit_ ()
{
- static struct GNUNET_TIME_Relative one = { 1 };
+ static struct GNUNET_TIME_Relative one = {1};
return one;
}
@@ -170,7 +170,7 @@ GNUNET_TIME_relative_get_unit_ ()
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_get_millisecond_ ()
{
- static struct GNUNET_TIME_Relative one = { 1000 };
+ static struct GNUNET_TIME_Relative one = {1000};
return one;
}
@@ -182,7 +182,7 @@ GNUNET_TIME_relative_get_millisecond_ ()
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_get_second_ ()
{
- static struct GNUNET_TIME_Relative one = { 1000 * 1000LL };
+ static struct GNUNET_TIME_Relative one = {1000 * 1000LL};
return one;
}
@@ -194,7 +194,7 @@ GNUNET_TIME_relative_get_second_ ()
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_get_minute_ ()
{
- static struct GNUNET_TIME_Relative one = { 60 * 1000 * 1000LL };
+ static struct GNUNET_TIME_Relative one = {60 * 1000 * 1000LL};
return one;
}
@@ -206,7 +206,7 @@ GNUNET_TIME_relative_get_minute_ ()
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_get_hour_ ()
{
- static struct GNUNET_TIME_Relative one = { 60 * 60 * 1000 * 1000LL };
+ static struct GNUNET_TIME_Relative one = {60 * 60 * 1000 * 1000LL};
return one;
}
@@ -218,7 +218,7 @@ GNUNET_TIME_relative_get_hour_ ()
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_get_forever_ ()
{
- static struct GNUNET_TIME_Relative forever = { UINT64_MAX };
+ static struct GNUNET_TIME_Relative forever = {UINT64_MAX};
return forever;
}
@@ -230,7 +230,7 @@ GNUNET_TIME_relative_get_forever_ ()
struct GNUNET_TIME_Absolute
GNUNET_TIME_absolute_get_forever_ ()
{
- static struct GNUNET_TIME_Absolute forever = { UINT64_MAX };
+ static struct GNUNET_TIME_Absolute forever = {UINT64_MAX};
return forever;
}
@@ -252,7 +252,7 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel)
if (rel.rel_value_us + now.abs_value_us < rel.rel_value_us)
{
- GNUNET_break (0); /* overflow... */
+ GNUNET_break (0); /* overflow... */
return GNUNET_TIME_UNIT_FOREVER_ABS;
}
ret.abs_value_us = rel.rel_value_us + now.abs_value_us;
@@ -290,7 +290,6 @@ GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1,
}
-
/**
* Return the minimum of two relative time values.
*
@@ -395,7 +394,8 @@ GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start,
{
struct GNUNET_TIME_Absolute ret;
- if ((start.abs_value_us == UINT64_MAX) || (duration.rel_value_us == UINT64_MAX))
+ if ((start.abs_value_us == UINT64_MAX) ||
+ (duration.rel_value_us == UINT64_MAX))
return GNUNET_TIME_UNIT_FOREVER_ABS;
if (start.abs_value_us + duration.rel_value_us < start.abs_value_us)
{
@@ -462,8 +462,7 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel,
* @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
*/
struct GNUNET_TIME_Relative
-relative_multiply_double (struct GNUNET_TIME_Relative rel,
- double factor)
+relative_multiply_double (struct GNUNET_TIME_Relative rel, double factor)
{
struct GNUNET_TIME_Relative out;
double m;
@@ -546,7 +545,8 @@ GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel,
* assuming it continues at the same speed
*/
struct GNUNET_TIME_Relative
-GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, uint64_t finished,
+GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start,
+ uint64_t finished,
uint64_t total)
{
struct GNUNET_TIME_Relative dur;
@@ -673,7 +673,6 @@ GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a)
ret.abs_value_us = GNUNET_ntohll (a.abs_value_us__);
return ret;
-
}
@@ -706,12 +705,11 @@ GNUNET_TIME_time_to_year (struct GNUNET_TIME_Absolute at)
struct tm *t;
time_t tp;
- tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */
+ tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */
t = gmtime (&tp);
if (t == NULL)
return 0;
return t->tm_year + 1900;
-
}
@@ -740,8 +738,8 @@ GNUNET_TIME_year_to_time (unsigned int year)
t.tm_wday = 1;
t.tm_yday = 1;
tp = mktime (&t);
- GNUNET_break (tp != (time_t) - 1);
- ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */
+ GNUNET_break (tp != (time_t) -1);
+ ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */
return ret;
}
@@ -756,16 +754,16 @@ GNUNET_TIME_year_to_time (unsigned int year)
* @return the next backoff time
*/
struct GNUNET_TIME_Relative
-GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt, struct GNUNET_TIME_Relative threshold)
+GNUNET_TIME_randomized_backoff (struct GNUNET_TIME_Relative rt,
+ struct GNUNET_TIME_Relative threshold)
{
- double r = (rand() % 500) / 1000.0;
+ double r = (rand () % 500) / 1000.0;
struct GNUNET_TIME_Relative t;
- t = relative_multiply_double (GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS,
- rt),
- 2 + r);
- return GNUNET_TIME_relative_min (threshold,
- t);
+ t = relative_multiply_double (
+ GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, rt),
+ 2 + r);
+ return GNUNET_TIME_relative_min (threshold, t);
}
@@ -778,10 +776,9 @@ GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt, struct GNUNET_TIM
struct GNUNET_TIME_Relative
GNUNET_TIME_randomize (struct GNUNET_TIME_Relative r)
{
- double d = ((rand() % 1001) - 500) / 1000.0;
+ double d = ((rand () % 1001) - 500) / 1000.0;
- return relative_multiply_double (r,
- d);
+ return relative_multiply_double (r, d);
}
@@ -804,7 +801,8 @@ GNUNET_TIME_randomize (struct GNUNET_TIME_Relative r)
* @return monotonically increasing time
*/
struct GNUNET_TIME_Absolute
-GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cfg)
+GNUNET_TIME_absolute_get_monotonic (
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static const struct GNUNET_CONFIGURATION_Handle *last_cfg;
static struct GNUNET_TIME_Absolute last_time;
@@ -825,23 +823,26 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
map = NULL;
last_cfg = cfg;
- if ( (NULL != cfg) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "util",
- "MONOTONIC_TIME_FILENAME",
- &filename)) )
+ if ((NULL != cfg) &&
+ (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "util",
+ "MONOTONIC_TIME_FILENAME",
+ &filename)))
{
struct GNUNET_DISK_FileHandle *fh;
fh = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE,
- GNUNET_DISK_PERM_USER_WRITE | GNUNET_DISK_PERM_GROUP_WRITE |
- GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_GROUP_READ);
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_WRITE |
+ GNUNET_DISK_PERM_GROUP_WRITE |
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_GROUP_READ);
if (NULL == fh)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to map `%s', cannot assure monotonic time!\n"),
+ _ ("Failed to map `%s', cannot assure monotonic time!\n"),
filename);
}
else
@@ -849,18 +850,13 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
off_t size;
size = 0;
- GNUNET_break (GNUNET_OK ==
- GNUNET_DISK_file_handle_size (fh,
- &size));
+ GNUNET_break (GNUNET_OK == GNUNET_DISK_file_handle_size (fh, &size));
if (size < (off_t) sizeof (*map))
{
struct GNUNET_TIME_AbsoluteNBO o;
-
+
o = GNUNET_TIME_absolute_hton (now);
- if (sizeof (o) !=
- GNUNET_DISK_file_write (fh,
- &o,
- sizeof (o)))
+ if (sizeof (o) != GNUNET_DISK_file_write (fh, &o, sizeof (o)))
size = 0;
else
size = sizeof (o);
@@ -873,14 +869,17 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
sizeof (*map));
if (NULL == map)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to map `%s', cannot assure monotonic time!\n"),
+ _ (
+ "Failed to map `%s', cannot assure monotonic time!\n"),
filename);
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"),
- filename);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"),
+ filename);
}
}
GNUNET_DISK_file_close (fh);
@@ -900,11 +899,11 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
#else
mt.abs_value_us__ = atomic_load (map);
#endif
- last_time = GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_ntoh (mt),
- last_time);
+ last_time =
+ GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_ntoh (mt), last_time);
}
if (now.abs_value_us <= last_time.abs_value_us)
- now.abs_value_us = last_time.abs_value_us+1;
+ now.abs_value_us = last_time.abs_value_us + 1;
last_time = now;
if (NULL != map)
{
@@ -913,11 +912,10 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
#if __GNUC__
(void) __sync_lock_test_and_set (map, val);
#else
- *map = val; /* godspeed, pray this is atomic */
+ *map = val; /* godspeed, pray this is atomic */
#endif
#else
- atomic_store (map,
- val);
+ atomic_store (map, val);
#endif
}
return now;
@@ -927,8 +925,7 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
/**
* Destructor
*/
-void __attribute__ ((destructor))
-GNUNET_util_time_fini ()
+void __attribute__ ((destructor)) GNUNET_util_time_fini ()
{
(void) GNUNET_TIME_absolute_get_monotonic (NULL);
}