libglusterfs: implement gf_strndup

Change-Id: Ifb7bf22e8cf4ad1faccf7999c36919693912093f
BUG: 808400
Signed-off-by: Raghavendra G <raghavendra@gluster.com>
Reviewed-on: http://review.gluster.org/4135
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
This commit is contained in:
Raghavendra G 2012-10-29 12:41:03 +05:30 committed by Vijay Bellur
parent bc3253b070
commit 79eb7c62e2

View File

@ -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)
{