diff options
author | Vicent Marti <tanoku@gmail.com> | 2011-09-30 16:08:06 +0200 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2011-09-30 16:08:41 +0200 |
commit | fafd471021218a425adb1506c0c942e8cd23f90c (patch) | |
tree | 39d3d04b2e86264f35c527a8b7c5c3a9e9044751 /src | |
parent | 358a15fd65cdc56ddc02b3ea261851f20c7ac618 (diff) | |
download | libgit2-fafd471021218a425adb1506c0c942e8cd23f90c.tar.gz |
config: Proper type declarations for 64 bit ints
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 62 | ||||
-rw-r--r-- | src/util.c | 11 | ||||
-rw-r--r-- | src/util.h | 4 |
3 files changed, 44 insertions, 33 deletions
diff --git a/src/config.c b/src/config.c index 54727c0f6..f53afa145 100644 --- a/src/config.c +++ b/src/config.c @@ -164,16 +164,16 @@ int git_config_delete(git_config *cfg, const char *name) * Setters **************/ -int git_config_set_long(git_config *cfg, const char *name, long long value) +int git_config_set_int64(git_config *cfg, const char *name, int64_t value) { char str_value[32]; /* All numbers should fit in here */ p_snprintf(str_value, sizeof(str_value), "%" PRId64, value); return git_config_set_string(cfg, name, str_value); } -int git_config_set_int(git_config *cfg, const char *name, int value) +int git_config_set_int32(git_config *cfg, const char *name, int32_t value) { - return git_config_set_long(cfg, name, (long long)value); + return git_config_set_int64(cfg, name, (int64_t)value); } int git_config_set_bool(git_config *cfg, const char *name, int value) @@ -199,11 +199,11 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value) * Getters ***********/ -int git_config_get_long(git_config *cfg, const char *name, long long *out) +int git_config_get_int64(git_config *cfg, const char *name, int64_t *out) { const char *value, *num_end; int ret; - long long num; + int64_t num; ret = git_config_get_string(cfg, name, &value); if (ret < GIT_SUCCESS) @@ -214,35 +214,45 @@ int git_config_get_long(git_config *cfg, const char *name, long long *out) return git__rethrow(ret, "Failed to convert value for '%s'", name); switch (*num_end) { - case '\0': - break; - case 'k': - case 'K': + case 'g': + case 'G': num *= 1024; - break; + /* fallthrough */ + case 'm': case 'M': - num *= 1024 * 1024; - break; - case 'g': - case 'G': - num *= 1024 * 1024 * 1024; - break; - default: - return git__throw(GIT_EINVALIDTYPE, "Failed to get value for '%s'. Value is of invalid type", name); - } + num *= 1024; + /* fallthrough */ - *out = num; + case 'k': + case 'K': + num *= 1024; - return GIT_SUCCESS; + /* check that that there are no more characters after the + * given modifier suffix */ + if (num_end[1] != '\0') + return git__throw(GIT_EINVALIDTYPE, + "Failed to get value for '%s'. Invalid type suffix", name); + + /* fallthrough */ + + case '\0': + *out = num; + return GIT_SUCCESS; + + default: + return git__throw(GIT_EINVALIDTYPE, + "Failed to get value for '%s'. Value is of invalid type", name); + } } -int git_config_get_int(git_config *cfg, const char *name, int *out) +int git_config_get_int32(git_config *cfg, const char *name, int32_t *out) { - long long tmp_long; - int tmp_int, ret; + int64_t tmp_long; + int32_t tmp_int; + int ret; - ret = git_config_get_long(cfg, name, &tmp_long); + ret = git_config_get_int64(cfg, name, &tmp_long); if (ret < GIT_SUCCESS) return git__rethrow(ret, "Failed to convert value for '%s'", name); @@ -284,7 +294,7 @@ int git_config_get_bool(git_config *cfg, const char *name, int *out) } /* Try to parse it as an integer */ - error = git_config_get_int(cfg, name, out); + error = git_config_get_int32(cfg, name, out); if (error == GIT_SUCCESS) *out = !!(*out); diff --git a/src/util.c b/src/util.c index dc0eab38d..c81ed2d3a 100644 --- a/src/util.c +++ b/src/util.c @@ -46,10 +46,10 @@ int git__fnmatch(const char *pattern, const char *name, int flags) } } -int git__strtol64(long long *result, const char *nptr, const char **endptr, int base) +int git__strtol64(int64_t *result, const char *nptr, const char **endptr, int base) { const char *p; - long long n, nn; + int64_t n, nn; int c, ovfl, v, neg, ndig; p = nptr; @@ -124,10 +124,11 @@ Return: return GIT_SUCCESS; } -int git__strtol32(int *result, const char *nptr, const char **endptr, int base) +int git__strtol32(int32_t *result, const char *nptr, const char **endptr, int base) { - int tmp_int, error = GIT_SUCCESS; - long long tmp_long; + int error = GIT_SUCCESS; + int32_t tmp_int; + int64_t tmp_long; if ((error = git__strtol64(&tmp_long, nptr, endptr, base)) < GIT_SUCCESS) return error; diff --git a/src/util.h b/src/util.h index 888caf106..4de91b494 100644 --- a/src/util.h +++ b/src/util.h @@ -75,8 +75,8 @@ GIT_INLINE(void *) git__realloc(void *ptr, size_t size) extern int git__prefixcmp(const char *str, const char *prefix); extern int git__suffixcmp(const char *str, const char *suffix); -extern int git__strtol32(int *n, const char *buff, const char **end_buf, int base); -extern int git__strtol64(long long *n, const char *buff, const char **end_buf, int base); +extern int git__strtol32(int32_t *n, const char *buff, const char **end_buf, int base); +extern int git__strtol64(int64_t *n, const char *buff, const char **end_buf, int base); extern void git__hexdump(const char *buffer, size_t n); extern uint32_t git__hash(const void *key, int len, uint32_t seed); |