diff options
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | lib/xutil.c | 8 |
2 files changed, 6 insertions, 4 deletions
@@ -41,8 +41,6 @@ Portability ----------- Fix configure script to test each compiler warning we want to use. -Implement strndup locally (or call talloc_strndup instead). - Implement getline locally, (look at gnulib). Completion diff --git a/lib/xutil.c b/lib/xutil.c index 6fa5eb0d..268225b8 100644 --- a/lib/xutil.c +++ b/lib/xutil.c @@ -18,7 +18,6 @@ * Author: Carl Worth <cworth@cworth.org> */ -#define _GNU_SOURCE /* For strndup */ #include "notmuch-private.h" #include <stdio.h> @@ -84,11 +83,16 @@ xstrndup (const char *s, size_t n) { char *ret; - ret = strndup (s, n); + if (strlen (s) <= n) + n = strlen (s); + + ret = malloc (n + 1); if (ret == NULL) { fprintf (stderr, "Out of memory.\n"); exit (1); } + memcpy (ret, s, n); + ret[n] = '\0'; return ret; } |