diff options
-rw-r--r-- | libglusterfs/src/common-utils.c | 68 | ||||
-rw-r--r-- | libglusterfs/src/dict.c | 2 | ||||
-rw-r--r-- | libglusterfs/src/glusterfs/common-utils.h | 2 |
3 files changed, 71 insertions, 1 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index ddc3e486b6f..5814eb90e21 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -1941,6 +1941,74 @@ gf_string2boolean(const char *str, gf_boolean_t *b) } int +gf_strn2boolean(const char *str, const int len, gf_boolean_t *b) +{ + if (str == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + return -1; + } + + switch (len) { + case 1: + if (strcasecmp(str, "1") == 0) { + *b = _gf_true; + return 0; + } else if (strcasecmp(str, "0") == 0) { + *b = _gf_false; + return 0; + } + break; + case 2: + if (strcasecmp(str, "on") == 0) { + *b = _gf_true; + return 0; + } else if (strcasecmp(str, "no") == 0) { + *b = _gf_false; + return 0; + } + break; + case 3: + if (strcasecmp(str, "yes") == 0) { + *b = _gf_true; + return 0; + } else if (strcasecmp(str, "off") == 0) { + *b = _gf_false; + return 0; + } + break; + case 4: + if (strcasecmp(str, "true") == 0) { + *b = _gf_true; + return 0; + } + break; + case 5: + if (strcasecmp(str, "false") == 0) { + *b = _gf_false; + return 0; + } + break; + case 6: + if (strcasecmp(str, "enable") == 0) { + *b = _gf_true; + return 0; + } + break; + case 7: + if (strcasecmp(str, "disable") == 0) { + *b = _gf_false; + return 0; + } + break; + default: + return -1; + break; + } + return -1; +} + +int gf_lockfd(int fd) { struct gf_flock fl; diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 5f81c48d70f..d786e557fff 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -2798,7 +2798,7 @@ dict_get_str_boolean(dict_t *this, char *key, int default_val) VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, key, -EINVAL); - ret = gf_string2boolean(data->data, &boo); + ret = gf_strn2boolean(data->data, data->len - 1, &boo); if (ret == -1) goto err; diff --git a/libglusterfs/src/glusterfs/common-utils.h b/libglusterfs/src/glusterfs/common-utils.h index bc4b4cb8e7d..f6d82cc0b85 100644 --- a/libglusterfs/src/glusterfs/common-utils.h +++ b/libglusterfs/src/glusterfs/common-utils.h @@ -904,6 +904,8 @@ gf_string2percent_or_bytesize(const char *str, double *n, int gf_string2boolean(const char *str, gf_boolean_t *b); int +gf_strn2boolean(const char *str, const int len, gf_boolean_t *b); +int gf_string2percent(const char *str, double *n); int gf_string2time(const char *str, uint32_t *n); |