summaryrefslogtreecommitdiff
path: root/src/util/common_allocation.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/common_allocation.c')
-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.