diff options
-rw-r--r-- | src/include/gnunet_strings_lib.h | 20 | ||||
-rw-r--r-- | src/util/strings.c | 30 |
2 files changed, 49 insertions, 1 deletions
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h index f43567611..db657f54e 100644 --- a/src/include/gnunet_strings_lib.h +++ b/src/include/gnunet_strings_lib.h | |||
@@ -541,6 +541,25 @@ GNUNET_STRINGS_get_utf8_args (int argc, | |||
541 | char *const **u8argv); | 541 | char *const **u8argv); |
542 | 542 | ||
543 | 543 | ||
544 | /** | ||
545 | * Like strlcpy but portable. The given string @a src is copied in full length | ||
546 | * (until its null byte). The destination buffer is guaranteed to be | ||
547 | * null-terminated. | ||
548 | * | ||
549 | * to a destination buffer | ||
550 | * and ensures that the destination string is null-terminated. | ||
551 | * | ||
552 | * @param dst destination of the copy | ||
553 | * @param src source of the copy, must be null-terminated | ||
554 | * @param n the length of the string to copy, including its terminating null | ||
555 | * byte | ||
556 | * @return the length of the string that was copied, excluding the terminating | ||
557 | * null byte | ||
558 | */ | ||
559 | size_t | ||
560 | GNUNET_strlcpy(char *dst, const char *src, size_t n); | ||
561 | |||
562 | |||
544 | /* ***************** IPv4/IPv6 parsing ****************** */ | 563 | /* ***************** IPv4/IPv6 parsing ****************** */ |
545 | 564 | ||
546 | struct GNUNET_STRINGS_PortPolicy | 565 | struct GNUNET_STRINGS_PortPolicy |
@@ -641,7 +660,6 @@ struct GNUNET_STRINGS_IPv6NetworkPolicy * | |||
641 | GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX); | 660 | GNUNET_STRINGS_parse_ipv6_policy (const char *routeListX); |
642 | 661 | ||
643 | 662 | ||
644 | |||
645 | #if 0 /* keep Emacsens' auto-indent happy */ | 663 | #if 0 /* keep Emacsens' auto-indent happy */ |
646 | { | 664 | { |
647 | #endif | 665 | #endif |
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 |