saait

Simple static page generator
git clone https://git.sinitax.com/codemadness/saait
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

commit 5bd3c655c560c3a69e431e75b9b9386192915194
parent 627a6cda2e82c3f4937d7fb0cc82f54549bd15ac
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 27 Nov 2016 13:02:46 +0100

fix strdup return type and improve compatibility

Diffstat:
Msaait.c | 21+++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/saait.c b/saait.c @@ -44,10 +44,10 @@ xmlencode(const char *s, FILE *fp) } } -void * +char * estrdup(const char *s) { - void *p; + char *p; if (!(p = strdup(s))) { fprintf(stderr, "strdup: %s\n", strerror(errno)); @@ -56,15 +56,24 @@ estrdup(const char *s) return p; } -void * -estrndup(const char *s, size_t maxlen) +/* for compatibility (non-POSIX 2008) strndup is implemented */ +char * +estrndup(const char *s, size_t n) { - void *p; + char *p, *e; + size_t l; - if (!(p = strndup(s, maxlen))) { + /* strnlen */ + e = memchr(s, 0, n); + l = e ? e - s : n; + + if (!(p = malloc(l + 1))) { fprintf(stderr, "strndup: %s\n", strerror(errno)); exit(1); } + memcpy(p, s, l); + p[l] = '\0'; + return p; }