diff options
author | Dave Reisner <dreisner@archlinux.org> | 2011-09-18 16:22:38 -0400 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-09-18 16:58:21 -0500 |
commit | 83ee9708b1c0ed3c262e0148ea8cdc880f177d0d (patch) | |
tree | 8b605f9be56f0361b81d2876813843cc6d950843 /src/util/pacsort.c | |
parent | 07e89c1e5db2769c1128f5d99fead151a4afc751 (diff) | |
download | pacman-83ee9708b1c0ed3c262e0148ea8cdc880f177d0d.tar.xz |
src/util: provide strndup definitions where needed
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src/util/pacsort.c')
-rw-r--r-- | src/util/pacsort.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/util/pacsort.c b/src/util/pacsort.c index 2b12f097..0eedf59d 100644 --- a/src/util/pacsort.c +++ b/src/util/pacsort.c @@ -48,6 +48,28 @@ 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; |