[PATCH 2/3] add estrndup

From: Jakob Kramer <jakob.kramer_AT_gmx.de>
Date: Wed, 11 Feb 2015 01:59:04 +0100

---
 libutil/ealloc.c | 17 +++++++++++++++++
 util.h           |  2 ++
 2 files changed, 19 insertions(+)
diff --git a/libutil/ealloc.c b/libutil/ealloc.c
index 8e2f21e..320865d 100644
--- a/libutil/ealloc.c
+++ b/libutil/ealloc.c
_AT_@ -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)
 {
_AT_@ -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
index 2efcd89..448f51e 100644
--- a/util.h
+++ b/util.h
_AT_@ -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 *, ...);
-- 
1.9.1
--------------040200000501010009080504--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Wed Feb 11 2015 - 02:12:14 CET