From aff3e63c451ead18571a8abed56e911f71906fe6 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 19 Jan 2011 12:00:39 -0600 Subject: Add strndup fallback function to libalpm util The same fallback we are currently using in the pacman frontend. Signed-off-by: Dan McGee --- lib/libalpm/util.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib/libalpm/util.c') 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: */ -- cgit v1.2.3-24-g4f1b