[sheepdog] [PATCH 1/2] lib: add a new wrapper function of strdup()

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Wed Aug 20 11:07:53 CEST 2014


Cc: Ruoyu <liangry at ucweb.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 include/util.h |  2 ++
 lib/util.c     | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/include/util.h b/include/util.h
index 9da872d..69e114b 100644
--- a/include/util.h
+++ b/include/util.h
@@ -573,4 +573,6 @@ static inline uint64_t clock_get_time(void)
 	return (uint64_t)ts.tv_sec * 1000000000LL + (uint64_t)ts.tv_nsec;
 }
 
+char *xstrdup(const char *s);
+
 #endif
diff --git a/lib/util.c b/lib/util.c
index a5b7532..164f755 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -831,3 +831,15 @@ double get_time_interval(const struct timespec *start,
 	return ((end->tv_nsec - start->tv_nsec) * 0.000000001)
 			+ end->tv_sec - start->tv_sec;
 }
+
+char *xstrdup(const char *s)
+{
+	char *ret;
+
+	ret = strdup(s);
+	if (!ret)
+		panic("Out of memory");
+
+	return ret;
+}
+
-- 
1.8.3.2




More information about the sheepdog mailing list