summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-01-19 12:00:39 -0600
committerDan McGee <dan@archlinux.org>2011-01-21 09:14:47 -0600
commitaff3e63c451ead18571a8abed56e911f71906fe6 (patch)
treef04a34a1de11facfc854f567387db8dff030e12f /lib/libalpm/util.c
parentb40c8e292244c497ddb557428b8bd152ed7f0482 (diff)
downloadpacman-aff3e63c451ead18571a8abed56e911f71906fe6.tar.xz
Add strndup fallback function to libalpm util
The same fallback we are currently using in the pacman frontend. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/util.c')
-rw-r--r--lib/libalpm/util.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 2eee5e4a..81d950e8 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -937,4 +937,26 @@ long _alpm_parsedate(const char *line)
return(atol(line));
}
+#ifndef HAVE_STRNDUP
+/* A quick and dirty implementation derived from glibc */
+static size_t strnlen(const char *s, size_t max)
+{
+ register const char *p;
+ for(p = s; *p && max--; ++p);
+ return(p - s);
+}
+
+char *strndup(const char *s, size_t n)
+{
+ size_t len = strnlen(s, n);
+ char *new = (char *) malloc(len + 1);
+
+ if (new == NULL)
+ return NULL;
+
+ new[len] = '\0';
+ return (char *) memcpy(new, s, len);
+}
+#endif
+
/* vim: set ts=2 sw=2 noet: */