From bb94729c098f21ae850044a9201c1d5b92baea1f Mon Sep 17 00:00:00 2001 From: Will Miles Date: Fri, 27 Feb 2015 14:43:23 -0500 Subject: util: Use util-common for strndup in pacsort and pactree This small refactor reduces the number of replications of the local imeplementation of strndup. Signed-off-by: Will Miles Signed-off-by: Allan McRae --- src/util/pacsort.c | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) (limited to 'src/util/pacsort.c') diff --git a/src/util/pacsort.c b/src/util/pacsort.c index d864fdb9..9d248fad 100644 --- a/src/util/pacsort.c +++ b/src/util/pacsort.c @@ -25,6 +25,7 @@ #include #include +#include "util-common.h" #define DELIM ' ' @@ -69,28 +70,6 @@ static struct options_t { char delim; } opts; -#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 - static struct buffer_t *buffer_new(size_t initial_size) { struct buffer_t *buf; -- cgit v1.2.3-24-g4f1b