diff options
Diffstat (limited to 'src/util/strings.c')
-rw-r--r-- | src/util/strings.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/util/strings.c b/src/util/strings.c index 2b51d3e52..d3268f4d9 100644 --- a/src/util/strings.c +++ b/src/util/strings.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2005-2013 GNUnet e.V. | 3 | Copyright (C) 2005-2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -17,7 +17,6 @@ | |||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. |
19 | */ | 19 | */ |
20 | |||
21 | /** | 20 | /** |
22 | * @file util/strings.c | 21 | * @file util/strings.c |
23 | * @brief string functions | 22 | * @brief string functions |
@@ -35,9 +34,9 @@ | |||
35 | #include <unistr.h> | 34 | #include <unistr.h> |
36 | #include <uniconv.h> | 35 | #include <uniconv.h> |
37 | 36 | ||
38 | #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) | 37 | #define LOG(kind,...) GNUNET_log_from (kind, "util-strings", __VA_ARGS__) |
39 | 38 | ||
40 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall) | 39 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-strings", syscall) |
41 | 40 | ||
42 | 41 | ||
43 | /** | 42 | /** |
@@ -90,6 +89,37 @@ GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count, ...) | |||
90 | 89 | ||
91 | 90 | ||
92 | /** | 91 | /** |
92 | * Convert a peer path to a human-readable string. | ||
93 | * | ||
94 | * @param pids array of PIDs to convert to a string | ||
95 | * @param num_pids length of the @a pids array | ||
96 | * @return string representing the array of @a pids | ||
97 | */ | ||
98 | char * | ||
99 | GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids, | ||
100 | unsigned int num_pids) | ||
101 | { | ||
102 | char *buf; | ||
103 | size_t off; | ||
104 | size_t plen = num_pids * 5 + 1; | ||
105 | |||
106 | off = 0; | ||
107 | buf = GNUNET_malloc (plen); | ||
108 | for (unsigned int i = 0; | ||
109 | i < num_pids; | ||
110 | i++) | ||
111 | { | ||
112 | off += GNUNET_snprintf (&buf[off], | ||
113 | plen - off, | ||
114 | "%s%s", | ||
115 | GNUNET_i2s (&pids[i]), | ||
116 | (i == num_pids -1) ? "" : "-"); | ||
117 | } | ||
118 | return buf; | ||
119 | } | ||
120 | |||
121 | |||
122 | /** | ||
93 | * Given a buffer of a given size, find "count" | 123 | * Given a buffer of a given size, find "count" |
94 | * 0-terminated strings in the buffer and assign | 124 | * 0-terminated strings in the buffer and assign |
95 | * the count (varargs) of type "const char**" to the | 125 | * the count (varargs) of type "const char**" to the |