From 79eb7c62e27d01d14b3053f9ecd14d6b964bac76 Mon Sep 17 00:00:00 2001 From: Raghavendra G Date: Mon, 29 Oct 2012 12:41:03 +0530 Subject: libglusterfs: implement gf_strndup Change-Id: Ifb7bf22e8cf4ad1faccf7999c36919693912093f BUG: 808400 Signed-off-by: Raghavendra G Reviewed-on: http://review.gluster.org/4135 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- libglusterfs/src/mem-pool.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'libglusterfs') diff --git a/libglusterfs/src/mem-pool.h b/libglusterfs/src/mem-pool.h index 4361c936d88..63264c75495 100644 --- a/libglusterfs/src/mem-pool.h +++ b/libglusterfs/src/mem-pool.h @@ -109,6 +109,25 @@ void* __gf_default_realloc (void *oldptr, size_t size) #define GF_FREE(free_ptr) __gf_free (free_ptr) +static inline +char *gf_strndup (const char *src, size_t len) +{ + char *dup_str = NULL; + + if (!src) { + goto out; + } + + dup_str = GF_CALLOC (1, len + 1, gf_common_mt_strdup); + if (!dup_str) { + goto out; + } + + memcpy (dup_str, src, len); +out: + return dup_str; +} + static inline char * gf_strdup (const char *src) { -- cgit