aboutsummaryrefslogtreecommitdiff
path: root/src/util/strings.c
diff options
context:
space:
mode:
authorlurchi <lurchi@strangeplace.net>2019-06-27 10:49:09 +0200
committerlurchi <lurchi@strangeplace.net>2019-06-27 10:49:09 +0200
commit0e7c93c3a0a3aa966503a8ae4caf3a21914e4126 (patch)
tree64ec750ae76bfe9851ee989ece90003d6ee06a42 /src/util/strings.c
parent06f8f6b3f76f69285240b056dd78697faddda32f (diff)
downloadgnunet-0e7c93c3a0a3aa966503a8ae4caf3a21914e4126.tar.gz
gnunet-0e7c93c3a0a3aa966503a8ae4caf3a21914e4126.zip
introduce GNUNET_strlcpy
Diffstat (limited to 'src/util/strings.c')
-rw-r--r--src/util/strings.c30
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 */
220size_t
221GNUNET_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 */
208struct ConversionTable 238struct ConversionTable