sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit c0a3c66a84f38bd7b7a73d19cf0b4d0003d28b3d
parent 08e93dd4f5e315cdfc5a44a7ae17d702207f67d3
Author: Jakob Kramer <jakob.kramer@gmx.de>
Date:   Wed, 11 Feb 2015 01:59:04 +0100

add estrndup

Diffstat:
Mlibutil/ealloc.c | 17+++++++++++++++++
Mutil.h | 2++
2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/libutil/ealloc.c b/libutil/ealloc.c @@ -28,6 +28,12 @@ estrdup(const char *s) return enstrdup(1, s); } +char * +estrndup(const char *s, size_t n) +{ + return enstrndup(1, s, n); +} + void * encalloc(int status, size_t nmemb, size_t size) { @@ -69,3 +75,14 @@ enstrdup(int status, const char *s) enprintf(status, "strdup: out of memory\n"); return p; } + +char * +enstrndup(int status, const char *s, size_t n) +{ + char *p; + + p = strndup(s, n); + if (!p) + enprintf(status, "strndup: out of memory\n"); + return p; +} diff --git a/util.h b/util.h @@ -25,10 +25,12 @@ void *ecalloc(size_t, size_t); void *emalloc(size_t); void *erealloc(void *, size_t); char *estrdup(const char *); +char *estrndup(const char *, size_t); void *encalloc(int, size_t, size_t); void *enmalloc(int, size_t); void *enrealloc(int, void *, size_t); char *enstrdup(int, const char *); +char *enstrndup(int, const char *, size_t); void enprintf(int, const char *, ...); void eprintf(const char *, ...);