From c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 5 Oct 2019 15:09:28 +0200 Subject: global reindent, now with uncrustify hook enabled --- src/rps/rps-test_util.c | 584 ++++++++++++++++++++++++------------------------ 1 file changed, 292 insertions(+), 292 deletions(-) (limited to 'src/rps/rps-test_util.c') diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c index 8680494f8..66f93d86f 100644 --- a/src/rps/rps-test_util.c +++ b/src/rps/rps-test_util.c @@ -32,7 +32,7 @@ #include -#define LOG(kind, ...) GNUNET_log_from(kind, "rps-test_util", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "rps-test_util", __VA_ARGS__) #define B2B_PAT "%c%c%c%c%c%c%c%c" #define B2B(byte) \ @@ -72,43 +72,43 @@ static struct GNUNET_CONTAINER_MultiHashMap *open_files; * @return File handle */ struct GNUNET_DISK_FileHandle * -get_file_handle(const char *name) +get_file_handle (const char *name) { struct GNUNET_HashCode hash; struct GNUNET_DISK_FileHandle *fh; if (NULL == open_files) - { - open_files = GNUNET_CONTAINER_multihashmap_create(16, - GNUNET_NO); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Created map of open files.\n"); - } - GNUNET_CRYPTO_hash(name, - strlen(name), - &hash); - if (NULL != (fh = GNUNET_CONTAINER_multihashmap_get(open_files, - &hash))) + { + open_files = GNUNET_CONTAINER_multihashmap_create (16, + GNUNET_NO); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Created map of open files.\n"); + } + GNUNET_CRYPTO_hash (name, + strlen (name), + &hash); + if (NULL != (fh = GNUNET_CONTAINER_multihashmap_get (open_files, + &hash))) return fh; - fh = GNUNET_DISK_file_open(name, - GNUNET_DISK_OPEN_WRITE | - GNUNET_DISK_OPEN_CREATE | - GNUNET_DISK_OPEN_APPEND, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ); + fh = GNUNET_DISK_file_open (name, + GNUNET_DISK_OPEN_WRITE + | GNUNET_DISK_OPEN_CREATE + | GNUNET_DISK_OPEN_APPEND, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE + | GNUNET_DISK_PERM_GROUP_READ); if (NULL == fh) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Opening file `%s' failed.\n", - name); - GNUNET_assert(0); - } - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multihashmap_put(open_files, - &hash, - fh, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Opening file `%s' failed.\n", + name); + GNUNET_assert (0); + } + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_put (open_files, + &hash, + fh, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); return fh; } @@ -127,18 +127,18 @@ get_file_handle(const char *name) * #GNUNET_NO if not. */ int -close_files_iter(void *cls, - const struct GNUNET_HashCode *key, - void *value) +close_files_iter (void *cls, + const struct GNUNET_HashCode *key, + void *value) { - (void)cls; - (void)key; + (void) cls; + (void) key; struct GNUNET_DISK_FileHandle *fh = value; if (NULL != fh) - { - GNUNET_DISK_file_close(fh); - } + { + GNUNET_DISK_file_close (fh); + } return GNUNET_YES; } @@ -149,14 +149,14 @@ close_files_iter(void *cls, * @return Success of iterating over files */ int -close_all_files() +close_all_files () { int ret; - ret = GNUNET_CONTAINER_multihashmap_iterate(open_files, - close_files_iter, - NULL); - GNUNET_CONTAINER_multihashmap_destroy(open_files); + ret = GNUNET_CONTAINER_multihashmap_iterate (open_files, + close_files_iter, + NULL); + GNUNET_CONTAINER_multihashmap_destroy (open_files); open_files = NULL; return ret; } @@ -164,58 +164,58 @@ close_all_files() void -to_file_raw(const char *file_name, const char *buf, size_t size_buf) +to_file_raw (const char *file_name, const char *buf, size_t size_buf) { struct GNUNET_DISK_FileHandle *f; size_t size_written; - if (NULL == (f = GNUNET_DISK_file_open(file_name, - GNUNET_DISK_OPEN_APPEND | - GNUNET_DISK_OPEN_WRITE | - GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ | - GNUNET_DISK_PERM_OTHER_READ))) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Not able to open file %s\n", - file_name); - return; - } - - size_written = GNUNET_DISK_file_write(f, buf, size_buf); + if (NULL == (f = GNUNET_DISK_file_open (file_name, + GNUNET_DISK_OPEN_APPEND + | GNUNET_DISK_OPEN_WRITE + | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE + | GNUNET_DISK_PERM_GROUP_READ + | GNUNET_DISK_PERM_OTHER_READ))) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Not able to open file %s\n", + file_name); + return; + } + + size_written = GNUNET_DISK_file_write (f, buf, size_buf); if (size_buf != size_written) - { - LOG(GNUNET_ERROR_TYPE_WARNING, - "Unable to write to file! (Size: %u, size_written: %u)\n", - size_buf, - size_written); - - if (GNUNET_YES != GNUNET_DISK_file_close(f)) - LOG(GNUNET_ERROR_TYPE_WARNING, - "Unable to close file\n"); - - return; - } - LOG(GNUNET_ERROR_TYPE_WARNING, - "Wrote %u bytes raw.\n", - size_written); - if (GNUNET_YES != GNUNET_DISK_file_close(f)) - LOG(GNUNET_ERROR_TYPE_WARNING, - "Unable to close file\n"); + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Unable to write to file! (Size: %u, size_written: %u)\n", + size_buf, + size_written); + + if (GNUNET_YES != GNUNET_DISK_file_close (f)) + LOG (GNUNET_ERROR_TYPE_WARNING, + "Unable to close file\n"); + + return; + } + LOG (GNUNET_ERROR_TYPE_WARNING, + "Wrote %u bytes raw.\n", + size_written); + if (GNUNET_YES != GNUNET_DISK_file_close (f)) + LOG (GNUNET_ERROR_TYPE_WARNING, + "Unable to close file\n"); } void -to_file_raw_unaligned(const char *file_name, - const char *buf, - size_t size_buf, - unsigned bits_needed) +to_file_raw_unaligned (const char *file_name, + const char *buf, + size_t size_buf, + unsigned bits_needed) { // TODO endianness! - GNUNET_assert(size_buf >= (bits_needed / 8)); - //if (0 == num_bits_buf_unaligned) - //{ + GNUNET_assert (size_buf >= (bits_needed / 8)); + // if (0 == num_bits_buf_unaligned) + // { // if (0 == (bits_needed % 8)) // { // to_file_raw (file_name, buf, size_buf); @@ -225,9 +225,9 @@ to_file_raw_unaligned(const char *file_name, // buf_unaligned = buf[size_buf - 1]; // num_bits_buf_unaligned = bits_needed % 8; // return; - //} - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Was asked to write %u bits\n", bits_needed); + // } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Was asked to write %u bits\n", bits_needed); char buf_write[size_buf + 1]; const unsigned bytes_iter = (0 != bits_needed % 8 ? @@ -235,145 +235,145 @@ to_file_raw_unaligned(const char *file_name, bits_needed / 8); // TODO what if no iteration happens? unsigned size_buf_write = 0; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "num_bits_buf_unaligned: %u\n", - num_bits_buf_unaligned); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "ua args: size_buf: %u, bits_needed: %u -> iter: %u\n", - size_buf, - bits_needed, - bytes_iter); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "num_bits_buf_unaligned: %u\n", + num_bits_buf_unaligned); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "ua args: size_buf: %u, bits_needed: %u -> iter: %u\n", + size_buf, + bits_needed, + bytes_iter); buf_write[0] = buf_unaligned; /* Iterate over input bytes */ for (unsigned i = 0; i < bytes_iter; i++) + { + /* Number of bits needed in this iteration - 8 for all except last iter */ + unsigned num_bits_needed_iter; + /* Mask for bits to actually use */ + unsigned mask_bits_needed_iter; + char byte_input; + /* Number of bits needed to align unaligned byte */ + unsigned num_bits_to_align; + /* Number of bits that are to be moved */ + unsigned num_bits_to_move; + /* Mask for bytes to be moved */ + char mask_input_to_move; + /* Masked bits to be moved */ + char bits_to_move; + /* The amount of bits needed to fit the bits to shift to the nearest spot */ + unsigned distance_shift_bits; + /* Shifted bits on the move */ + char bits_moving; + /* (unaligned) byte being filled with bits */ + char byte_to_fill; + /* mask for needed bits of the input byte that have not been moved */ + char mask_input_leftover; + /* needed bits of the input byte that have not been moved */ + char byte_input_leftover; + unsigned num_bits_leftover; + // unsigned num_bits_discard; + char byte_unaligned_new; + + if ((bits_needed - (i * 8)) <= 8) + { + /* last iteration */ + num_bits_needed_iter = bits_needed - (i * 8); + } + else + { + num_bits_needed_iter = 8; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "number of bits needed in this iteration: %u\n", + num_bits_needed_iter); + mask_bits_needed_iter = ((char) 1 << num_bits_needed_iter) - 1; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "mask needed bits (current iter): "B2B_PAT "\n", + B2B (mask_bits_needed_iter)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Unaligned byte: "B2B_PAT " (%u bits)\n", + B2B (buf_unaligned), + num_bits_buf_unaligned); + byte_input = buf[i]; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "next whole input byte: "B2B_PAT "\n", + B2B (byte_input)); + byte_input &= mask_bits_needed_iter; + num_bits_to_align = 8 - num_bits_buf_unaligned; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "input byte, needed bits: "B2B_PAT "\n", + B2B (byte_input)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "number of bits needed to align unaligned bit: %u\n", + num_bits_to_align); + num_bits_to_move = GNUNET_MIN (num_bits_to_align, num_bits_needed_iter); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "number of bits of new byte to move: %u\n", + num_bits_to_move); + mask_input_to_move = ((char) 1 << num_bits_to_move) - 1; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "mask of bits of new byte to take for moving: "B2B_PAT "\n", + B2B (mask_input_to_move)); + bits_to_move = byte_input & mask_input_to_move; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "masked bits of new byte to take for moving: "B2B_PAT "\n", + B2B (bits_to_move)); + distance_shift_bits = num_bits_buf_unaligned; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "distance needed to shift bits to their correct spot: %u\n", + distance_shift_bits); + bits_moving = bits_to_move << distance_shift_bits; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "shifted, masked bits of new byte being moved: "B2B_PAT "\n", + B2B (bits_moving)); + byte_to_fill = buf_unaligned | bits_moving; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "byte being filled: "B2B_PAT "\n", + B2B (byte_to_fill)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "pending bytes: %u\n", + num_bits_buf_unaligned + num_bits_needed_iter); + if (num_bits_buf_unaligned + num_bits_needed_iter >= 8) { - /* Number of bits needed in this iteration - 8 for all except last iter */ - unsigned num_bits_needed_iter; - /* Mask for bits to actually use */ - unsigned mask_bits_needed_iter; - char byte_input; - /* Number of bits needed to align unaligned byte */ - unsigned num_bits_to_align; - /* Number of bits that are to be moved */ - unsigned num_bits_to_move; - /* Mask for bytes to be moved */ - char mask_input_to_move; - /* Masked bits to be moved */ - char bits_to_move; - /* The amount of bits needed to fit the bits to shift to the nearest spot */ - unsigned distance_shift_bits; - /* Shifted bits on the move */ - char bits_moving; - /* (unaligned) byte being filled with bits */ - char byte_to_fill; - /* mask for needed bits of the input byte that have not been moved */ - char mask_input_leftover; - /* needed bits of the input byte that have not been moved */ - char byte_input_leftover; - unsigned num_bits_leftover; - //unsigned num_bits_discard; - char byte_unaligned_new; - - if ((bits_needed - (i * 8)) <= 8) - { - /* last iteration */ - num_bits_needed_iter = bits_needed - (i * 8); - } - else - { - num_bits_needed_iter = 8; - } - LOG(GNUNET_ERROR_TYPE_DEBUG, - "number of bits needed in this iteration: %u\n", - num_bits_needed_iter); - mask_bits_needed_iter = ((char)1 << num_bits_needed_iter) - 1; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "mask needed bits (current iter): "B2B_PAT "\n", - B2B(mask_bits_needed_iter)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Unaligned byte: "B2B_PAT " (%u bits)\n", - B2B(buf_unaligned), - num_bits_buf_unaligned); - byte_input = buf[i]; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "next whole input byte: "B2B_PAT "\n", - B2B(byte_input)); - byte_input &= mask_bits_needed_iter; - num_bits_to_align = 8 - num_bits_buf_unaligned; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "input byte, needed bits: "B2B_PAT "\n", - B2B(byte_input)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "number of bits needed to align unaligned bit: %u\n", - num_bits_to_align); - num_bits_to_move = GNUNET_MIN(num_bits_to_align, num_bits_needed_iter); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "number of bits of new byte to move: %u\n", - num_bits_to_move); - mask_input_to_move = ((char)1 << num_bits_to_move) - 1; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "mask of bits of new byte to take for moving: "B2B_PAT "\n", - B2B(mask_input_to_move)); - bits_to_move = byte_input & mask_input_to_move; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "masked bits of new byte to take for moving: "B2B_PAT "\n", - B2B(bits_to_move)); - distance_shift_bits = num_bits_buf_unaligned; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "distance needed to shift bits to their correct spot: %u\n", - distance_shift_bits); - bits_moving = bits_to_move << distance_shift_bits; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "shifted, masked bits of new byte being moved: "B2B_PAT "\n", - B2B(bits_moving)); - byte_to_fill = buf_unaligned | bits_moving; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "byte being filled: "B2B_PAT "\n", - B2B(byte_to_fill)); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "pending bytes: %u\n", - num_bits_buf_unaligned + num_bits_needed_iter); - if (num_bits_buf_unaligned + num_bits_needed_iter >= 8) - { - /* buf_unaligned was aligned by filling - * -> can be written to storage */ - buf_write[i] = byte_to_fill; - size_buf_write++; - - /* store the leftover, unaligned bits in buffer */ - mask_input_leftover = mask_bits_needed_iter & (~mask_input_to_move); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "mask of leftover bits of new byte: "B2B_PAT "\n", - B2B(mask_input_leftover)); - byte_input_leftover = byte_input & mask_input_leftover; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "masked, leftover bits of new byte: "B2B_PAT "\n", - B2B(byte_input_leftover)); - num_bits_leftover = num_bits_needed_iter - num_bits_to_move; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "number of unaligned bits left: %u\n", - num_bits_leftover); - //num_bits_discard = 8 - num_bits_needed_iter; - byte_unaligned_new = byte_input_leftover >> num_bits_to_move; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "new unaligned byte: "B2B_PAT "\n", - B2B(byte_unaligned_new)); - buf_unaligned = byte_unaligned_new; - num_bits_buf_unaligned = num_bits_leftover % 8; - } - else - { - /* unaligned buffer still unaligned but 'fuller' */ - buf_unaligned = byte_to_fill; - num_bits_buf_unaligned = (num_bits_buf_unaligned + bits_needed) % 8; - } + /* buf_unaligned was aligned by filling + * -> can be written to storage */ + buf_write[i] = byte_to_fill; + size_buf_write++; + + /* store the leftover, unaligned bits in buffer */ + mask_input_leftover = mask_bits_needed_iter & (~mask_input_to_move); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "mask of leftover bits of new byte: "B2B_PAT "\n", + B2B (mask_input_leftover)); + byte_input_leftover = byte_input & mask_input_leftover; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "masked, leftover bits of new byte: "B2B_PAT "\n", + B2B (byte_input_leftover)); + num_bits_leftover = num_bits_needed_iter - num_bits_to_move; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "number of unaligned bits left: %u\n", + num_bits_leftover); + // num_bits_discard = 8 - num_bits_needed_iter; + byte_unaligned_new = byte_input_leftover >> num_bits_to_move; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "new unaligned byte: "B2B_PAT "\n", + B2B (byte_unaligned_new)); + buf_unaligned = byte_unaligned_new; + num_bits_buf_unaligned = num_bits_leftover % 8; } - to_file_raw(file_name, buf_write, size_buf_write); - LOG(GNUNET_ERROR_TYPE_DEBUG, "\n"); + else + { + /* unaligned buffer still unaligned but 'fuller' */ + buf_unaligned = byte_to_fill; + num_bits_buf_unaligned = (num_bits_buf_unaligned + bits_needed) % 8; + } + } + to_file_raw (file_name, buf_write, size_buf_write); + LOG (GNUNET_ERROR_TYPE_DEBUG, "\n"); } char * -auth_key_to_string(struct GNUNET_CRYPTO_AuthKey auth_key) +auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key) { int size; size_t name_buf_size; @@ -383,33 +383,33 @@ auth_key_to_string(struct GNUNET_CRYPTO_AuthKey auth_key) size_t keylen = (sizeof(struct GNUNET_CRYPTO_AuthKey)) * 8; name_buf_size = 512 * sizeof(char); - name_buf = GNUNET_malloc(name_buf_size); + name_buf = GNUNET_malloc (name_buf_size); if (keylen % 5 > 0) keylen += 5 - keylen % 5; keylen /= 5; - buf = GNUNET_malloc(keylen + 1); + buf = GNUNET_malloc (keylen + 1); - end = GNUNET_STRINGS_data_to_string(&(auth_key.key), - sizeof(struct GNUNET_CRYPTO_AuthKey), - buf, - keylen); + end = GNUNET_STRINGS_data_to_string (&(auth_key.key), + sizeof(struct GNUNET_CRYPTO_AuthKey), + buf, + keylen); if (NULL == end) - { - GNUNET_free(buf); - GNUNET_break(0); - } + { + GNUNET_free (buf); + GNUNET_break (0); + } else - { - *end = '\0'; - } + { + *end = '\0'; + } - size = GNUNET_snprintf(name_buf, name_buf_size, "sampler_el-%s", buf); + size = GNUNET_snprintf (name_buf, name_buf_size, "sampler_el-%s", buf); if (0 > size) - LOG(GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n"); + LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n"); - GNUNET_free(buf); + GNUNET_free (buf); return name_buf; } @@ -418,18 +418,18 @@ auth_key_to_string(struct GNUNET_CRYPTO_AuthKey auth_key) struct GNUNET_CRYPTO_AuthKey -string_to_auth_key(const char *str) +string_to_auth_key (const char *str) { struct GNUNET_CRYPTO_AuthKey auth_key; if (GNUNET_OK != - GNUNET_STRINGS_string_to_data(str, - strlen(str), - &auth_key.key, - sizeof(struct GNUNET_CRYPTO_AuthKey))) - { - LOG(GNUNET_ERROR_TYPE_WARNING, "Failed to convert string to data\n"); - } + GNUNET_STRINGS_string_to_data (str, + strlen (str), + &auth_key.key, + sizeof(struct GNUNET_CRYPTO_AuthKey))) + { + LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to convert string to data\n"); + } return auth_key; } @@ -442,60 +442,60 @@ string_to_auth_key(const char *str) * #GNUNET_SYSERR on failure */ static int -ensure_folder_exist(void) +ensure_folder_exist (void) { if (GNUNET_OK != - GNUNET_DISK_directory_create("/tmp/rps")) - { - LOG(GNUNET_ERROR_TYPE_ERROR, - "Could not create directory `/tmp/rps'\n"); - return GNUNET_SYSERR; - } + GNUNET_DISK_directory_create ("/tmp/rps")) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "Could not create directory `/tmp/rps'\n"); + return GNUNET_SYSERR; + } return GNUNET_YES; } char * -store_prefix_file_name(const unsigned int index, - const char *prefix) +store_prefix_file_name (const unsigned int index, + const char *prefix) { int len_file_name; int out_size; char *file_name; char index_str[64]; - if (GNUNET_SYSERR == ensure_folder_exist()) + if (GNUNET_SYSERR == ensure_folder_exist ()) return NULL; - out_size = GNUNET_snprintf(index_str, - 64, - "%u", - index); - if (64 < out_size || - 0 > out_size) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Failed to write string to buffer (size: %i, out_size: %i)\n", - 64, - out_size); - } - len_file_name = (strlen(prefix) + - strlen(index_str) + - 11) + out_size = GNUNET_snprintf (index_str, + 64, + "%u", + index); + if ((64 < out_size)|| + (0 > out_size) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to write string to buffer (size: %i, out_size: %i)\n", + 64, + out_size); + } + len_file_name = (strlen (prefix) + + strlen (index_str) + + 11) * sizeof(char); - file_name = GNUNET_malloc(len_file_name); - out_size = GNUNET_snprintf(file_name, - len_file_name, - "/tmp/rps/%s-%s", - prefix, - index_str); - if (len_file_name < out_size || - 0 > out_size) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Failed to write string to buffer (size: %i, out_size: %i)\n", - len_file_name, - out_size); - } + file_name = GNUNET_malloc (len_file_name); + out_size = GNUNET_snprintf (file_name, + len_file_name, + "/tmp/rps/%s-%s", + prefix, + index_str); + if ((len_file_name < out_size)|| + (0 > out_size) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to write string to buffer (size: %i, out_size: %i)\n", + len_file_name, + out_size); + } return file_name; } @@ -507,13 +507,13 @@ store_prefix_file_name(const unsigned int index, * * @return Factorial of @a x */ -uint32_t fac(uint32_t x) +uint32_t fac (uint32_t x) { if (1 >= x) - { - return x; - } - return x * fac(x - 1); + { + return x; + } + return x * fac (x - 1); } /** @@ -524,18 +524,18 @@ uint32_t fac(uint32_t x) * * @return Binomial coefficient of @a n and @a k */ -uint32_t binom(uint32_t n, uint32_t k) +uint32_t binom (uint32_t n, uint32_t k) { - //GNUNET_assert (n >= k); + // GNUNET_assert (n >= k); if (k > n) return 0; /* if (0 > n) return 0; - always false */ /* if (0 > k) return 0; - always false */ if (0 == k) return 1; - return fac(n) + return fac (n) / - fac(k) * fac(n - k); + fac (k) * fac (n - k); } -- cgit v1.2.3