diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/strings.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/util/strings.c b/src/util/strings.c index 2cbdb640b..d69244e83 100644 --- a/src/util/strings.c +++ b/src/util/strings.c | |||
@@ -203,6 +203,36 @@ GNUNET_STRINGS_byte_size_fancy (unsigned long long size) | |||
203 | 203 | ||
204 | 204 | ||
205 | /** | 205 | /** |
206 | * Like strlcpy but portable. The given string @a src is copied in full length | ||
207 | * (until its null byte). The destination buffer is guaranteed to be | ||
208 | * null-terminated. | ||
209 | * | ||
210 | * to a destination buffer | ||
211 | * and ensures that the destination string is null-terminated. | ||
212 | * | ||
213 | * @param dst destination of the copy | ||
214 | * @param src source of the copy, must be null-terminated | ||
215 | * @param n the length of the string to copy, including its terminating null | ||
216 | * byte | ||
217 | * @return the length of the string that was copied, excluding the terminating | ||
218 | * null byte | ||
219 | */ | ||
220 | size_t | ||
221 | GNUNET_strlcpy(char *dst, const char *src, size_t n) | ||
222 | { | ||
223 | size_t ret; | ||
224 | size_t slen; | ||
225 | |||
226 | GNUNET_assert (0 != n); | ||
227 | ret = strlen (src); | ||
228 | slen = GNUNET_MIN (ret, n - 1); | ||
229 | memcpy (dst, src, slen); | ||
230 | dst[slen] = '\0'; | ||
231 | return ret; | ||
232 | } | ||
233 | |||
234 | |||
235 | /** | ||
206 | * Unit conversion table entry for 'convert_with_table'. | 236 | * Unit conversion table entry for 'convert_with_table'. |
207 | */ | 237 | */ |
208 | struct ConversionTable | 238 | struct ConversionTable |