aboutsummaryrefslogtreecommitdiffstats
path: root/xmalloc.c
diff options
context:
space:
mode:
authorMatthias Andree <matthias.andree@gmx.de>2010-04-10 17:49:23 +0200
committerMatthias Andree <matthias.andree@gmx.de>2010-04-10 18:03:10 +0200
commiteec588b0b2d77eb2fe6d441efb6ab66ed538bedf (patch)
tree84fe1bc1465c1a1112503bb67d48b433de6edbfd /xmalloc.c
parent0c92635914becb4f6913c3f1d5a6f3756325315b (diff)
downloadfetchmail-eec588b0b2d77eb2fe6d441efb6ab66ed538bedf.tar.gz
fetchmail-eec588b0b2d77eb2fe6d441efb6ab66ed538bedf.tar.bz2
fetchmail-eec588b0b2d77eb2fe6d441efb6ab66ed538bedf.zip
Add xstrndup().
Diffstat (limited to 'xmalloc.c')
-rw-r--r--xmalloc.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/xmalloc.c b/xmalloc.c
index a762d0a2..f722c73b 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -69,4 +69,16 @@ char *strdup(const char *s)
}
#endif /* !HAVE_STRDUP */
+char *xstrndup(const char *s, size_t len)
+{
+ char *p;
+ size_t l = strlen(s);
+
+ if (len < l) l = len;
+ p = (char *)xmalloc(l + 1);
+ memcpy(p, s, l);
+ p[l] = '\0';
+ return p;
+}
+
/* xmalloc.c ends here */