aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-10 11:22:32 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-10 11:22:32 +0000
commit15e4e5ef56c35935b57f2b1efc40548c54234d3e (patch)
treedf43f1d6d61317915bc7a78a1f5de208e7a89cb4 /src/util
parent52e04dad6eab39408a35da45462c2ddf8a2f6a10 (diff)
downloadgnunet-15e4e5ef56c35935b57f2b1efc40548c54234d3e.tar.gz
gnunet-15e4e5ef56c35935b57f2b1efc40548c54234d3e.zip
strndup
Diffstat (limited to 'src/util')
-rw-r--r--src/util/common_allocation.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index 59fa2dc05..1ae01ca49 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -215,6 +215,30 @@ GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber)
215 return res; 215 return res;
216} 216}
217 217
218
219/**
220 * Dup partially a string (same semantics as strndup).
221 *
222 * @param str the string to dup
223 * @param len the lenght of the string to dup
224 * @param filename where in the code was the call to GNUNET_strndup
225 * @param linenumber where in the code was the call to GNUNET_strndup
226 * @return strndup(str,len)
227 */
228char *
229GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, int linenumber)
230{
231 char *res;
232
233 GNUNET_assert_at (str != NULL, filename, linenumber);
234 len = GNUNET_MIN(len,strlen(str));
235 res = GNUNET_xmalloc_ (len + 1, filename, linenumber);
236 memcpy (res, str, len);
237 res[len] = '\0';
238 return res;
239}
240
241
218/** 242/**
219 * Grow an array. Grows old by (*oldCount-newCount)*elementSize bytes 243 * Grow an array. Grows old by (*oldCount-newCount)*elementSize bytes
220 * and sets *oldCount to newCount. 244 * and sets *oldCount to newCount.