diff options
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/common-utils.c | 18 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.h | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 3bd7c3d8fa2..6882b6c3178 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -3630,3 +3630,21 @@ recursive_rmdir (const char *delete_path) out: return ret; } +/* + * Input: Array of strings 'array' terminating in NULL + * string 'elem' to be searched in the array + * + * Output: Index of the element in the array if found, '-1' otherwise + */ +int +gf_get_index_by_elem (char **array, char *elem) +{ + int i = 0; + + for (i = 0; array[i]; i++) { + if (strcmp (elem, array[i]) == 0) + return i; + } + + return -1; +} diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 2a46f768e75..eaede81a5c8 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -677,4 +677,6 @@ gf_build_absolute_path (char *current_path, char *relative_path, char **path); int recursive_rmdir (const char *delete_path); +int +gf_get_index_by_elem (char **array, char *elem); #endif /* _COMMON_UTILS_H */ |