diff options
Diffstat (limited to 'src/rps/rps-test_util.c')
-rw-r--r-- | src/rps/rps-test_util.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c index 817967e0c..869170a8a 100644 --- a/src/rps/rps-test_util.c +++ b/src/rps/rps-test_util.c | |||
@@ -208,4 +208,55 @@ create_file (const char *name) | |||
208 | 208 | ||
209 | #endif /* TO_FILE */ | 209 | #endif /* TO_FILE */ |
210 | 210 | ||
211 | /** | ||
212 | * @brief Try to ensure that `/tmp/rps` exists. | ||
213 | * | ||
214 | * @return #GNUNET_YES on success | ||
215 | * #GNUNET_SYSERR on failure | ||
216 | */ | ||
217 | static int ensure_folder_exist (void) | ||
218 | { | ||
219 | if (GNUNET_NO == GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO)) | ||
220 | { | ||
221 | GNUNET_DISK_directory_create ("/tmp/rps"); | ||
222 | } | ||
223 | if (GNUNET_YES != GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO)) | ||
224 | { | ||
225 | return GNUNET_SYSERR; | ||
226 | } | ||
227 | return GNUNET_YES; | ||
228 | } | ||
229 | |||
230 | const char * | ||
231 | store_prefix_file_name (const struct GNUNET_PeerIdentity *peer, | ||
232 | const char *prefix) | ||
233 | { | ||
234 | unsigned int len_file_name; | ||
235 | unsigned int out_size; | ||
236 | char *file_name; | ||
237 | const char *pid_long; | ||
238 | |||
239 | if (GNUNET_SYSERR == ensure_folder_exist()) return NULL; | ||
240 | pid_long = GNUNET_i2s_full (peer); | ||
241 | len_file_name = (strlen (prefix) + | ||
242 | strlen (pid_long) + | ||
243 | 11) | ||
244 | * sizeof (char); | ||
245 | file_name = GNUNET_malloc (len_file_name); | ||
246 | out_size = GNUNET_snprintf (file_name, | ||
247 | len_file_name, | ||
248 | "/tmp/rps/%s-%s", | ||
249 | prefix, | ||
250 | pid_long); | ||
251 | if (len_file_name < out_size || | ||
252 | 0 > out_size) | ||
253 | { | ||
254 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
255 | "Failed to write string to buffer (size: %i, out_size: %i)\n", | ||
256 | len_file_name, | ||
257 | out_size); | ||
258 | } | ||
259 | return file_name; | ||
260 | } | ||
261 | |||
211 | /* end of gnunet-service-rps.c */ | 262 | /* end of gnunet-service-rps.c */ |