diff options
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/common-utils.c | 14 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.h | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index ef76bdfe750..46a3084fe39 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -4931,3 +4931,17 @@ get_struct_variable (int mem_num, gf_gsync_status_t *sts_val) out: return NULL; } + +/* * Safe wrapper function for strncpy. + * This wrapper makes sure that when there is no null byte among the first n in + * source srting for strncpy function call, the string placed in dest will be + * null-terminated. + */ + +char * +gf_strncpy (char *dest, const char *src, const size_t dest_size) +{ + strncpy (dest, src, dest_size - 1); + dest[dest_size - 1] = '\0'; + return dest; +} diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 8df96c338f5..89f7927aae1 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -948,4 +948,7 @@ glusterfs_compute_sha256 (const unsigned char *content, size_t size, char* get_struct_variable (int mem_num, gf_gsync_status_t *sts_val); +char * +gf_strncpy (char *dest, const char *src, const size_t dest_size); + #endif /* _COMMON_UTILS_H */ |