From f73c5b3069fd10048f1fcdf5266d8da2fcb403e5 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 20 Dec 2008 16:55:10 +0100 Subject: [PATCH] src/common.c: Change `sstrdup' to not call `strdup' anymore. --- src/common.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/common.c b/src/common.c index 119d284f..ae89c44f 100644 --- a/src/common.c +++ b/src/common.c @@ -77,15 +77,21 @@ int ssnprintf (char *dest, size_t n, const char *format, ...) char *sstrdup (const char *s) { char *r; + size_t sz; if (s == NULL) return (NULL); - if((r = strdup (s)) == NULL) + /* Do not use `strdup' here, because it's not specified in POSIX. It's + * ``only'' an XSI extension. */ + sz = strlen (s) + 1; + r = (char *) malloc (sizeof (char) * sz); + if (r == NULL) { - ERROR ("Not enough memory."); + ERROR ("sstrdup: Out of memory."); exit (3); } + memcpy (r, s, sizeof (char) * sz); return (r); } /* char *sstrdup */ -- 2.11.0