GNUnet  0.11.x
rps-test_util.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C)
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
28 #ifndef RPS_TEST_UTIL_H
29 #define RPS_TEST_UTIL_H
30 
31 #define TO_FILE 0
32 
33 
34 char *
36 
38 string_to_auth_key (const char *str);
39 
40 
51 get_file_handle (const char *name);
52 
58 int
60 
64 #ifdef TO_FILE
65 #define to_file(file_name, ...) do { \
66  char tmp_buf[512] = ""; \
67  int size; \
68  if (NULL == file_name) break; \
69  size = GNUNET_snprintf (tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \
70  if (0 > size) \
71  { \
72  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \
73  "Failed to create tmp_buf\n"); \
74  break; \
75  } \
76  (void) strncat (tmp_buf, "\n", 512); \
77  GNUNET_DISK_file_write (get_file_handle (file_name), \
78  tmp_buf, \
79  strnlen (tmp_buf, 512)); \
80 } while (0);
81 
82 
83 #define to_file_w_len(file_name, len, ...) do { char tmp_buf [len]; \
84  int size; \
85  memset (tmp_buf, 0, len); \
86  size = GNUNET_snprintf (tmp_buf, \
87  sizeof( \
88  tmp_buf), \
89  __VA_ARGS__); \
90  if (0 > size) \
91  { \
92  GNUNET_log ( \
93  GNUNET_ERROR_TYPE_WARNING, \
94  "Failed to create tmp_buf\n"); \
95  break; \
96  } \
97  (void) strncat (tmp_buf, "\n", \
98  len); \
99  GNUNET_DISK_file_write ( \
100  get_file_handle (file_name), \
101  tmp_buf, \
102  strnlen ( \
103  tmp_buf, len)); \
104 } while (0);
105 #else /* TO_FILE */
106 # define to_file(file_name, ...)
107 # define to_file_w_len(file_name, len, ...)
108 #endif /* TO_FILE */
109 
110 char *
111 store_prefix_file_name (const unsigned int index,
112  const char *prefix);
113 
114 void
115 to_file_raw (const char *file_name, const char *buf, size_t size_buf);
116 
117 void
118 to_file_raw_unaligned (const char *file_name,
119  const char *buf,
120  size_t size_buf,
121  unsigned bits_needed);
122 
123 
131 uint32_t fac (uint32_t x);
132 
133 
142 uint32_t binom (uint32_t n, uint32_t k);
143 
144 #endif /* RPS_TEST_UTIL_H */
145 /* end of gnunet-service-rps.c */
struct GNUNET_CRYPTO_AuthKey string_to_auth_key(const char *str)
static char * file_name
Dump file name.
static unsigned bits_needed
numer of bits required to represent the largest peer id
void to_file_raw(const char *file_name, const char *buf, size_t size_buf)
struct GNUNET_DISK_FileHandle * get_file_handle(const char *name)
Get file handle.
Definition: rps-test_util.c:74
static char buf[2048]
char * store_prefix_file_name(const unsigned int index, const char *prefix)
const char * name
uint32_t binom(uint32_t n, uint32_t k)
Binomial coefficient (n choose k)
int close_all_files()
Close all files that were opened with get_file_handle.
void to_file_raw_unaligned(const char *file_name, const char *buf, size_t size_buf, unsigned bits_needed)
uint32_t fac(uint32_t x)
Factorial.
Handle used to access files (and pipes).
char * auth_key_to_string(struct GNUNET_CRYPTO_AuthKey auth_key)
type for (message) authentication keys