diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2015-07-02 17:25:48 +0300 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-07-02 19:35:43 +0300 |
commit | e069c621bdd62e603b048eb536f5a978a905b310 (patch) | |
tree | e3fa76833856f675d8eda911059a254465cfdf75 /tests/core | |
parent | aa92c318a235cc6a5230682b9c071eb35f9c5f4c (diff) |
git__getenv: utf-8 aware env reader
Introduce `git__getenv` which is a UTF-8 aware `getenv` everywhere.
Make `cl_getenv` use this to keep consistent memory handling around
return values (free everywhere, as opposed to only some platforms).
Diffstat (limited to 'tests/core')
-rw-r--r-- | tests/core/env.c | 20 | ||||
-rw-r--r-- | tests/core/ftruncate.c | 2 |
2 files changed, 9 insertions, 13 deletions
diff --git a/tests/core/env.c b/tests/core/env.c index 293b786db..ee08258a6 100644 --- a/tests/core/env.c +++ b/tests/core/env.c @@ -30,14 +30,8 @@ static char *home_values[] = { void test_core_env__initialize(void) { int i; - for (i = 0; i < NUM_VARS; ++i) { - const char *original = cl_getenv(env_vars[i]); -#ifdef GIT_WIN32 - env_save[i] = (char *)original; -#else - env_save[i] = original ? git__strdup(original) : NULL; -#endif - } + for (i = 0; i < NUM_VARS; ++i) + env_save[i] = cl_getenv(env_vars[i]); } static void set_global_search_path_from_env(void) @@ -77,12 +71,14 @@ static void setenv_and_check(const char *name, const char *value) char *check; cl_git_pass(cl_setenv(name, value)); - check = cl_getenv(name); - cl_assert_equal_s(value, check); -#ifdef GIT_WIN32 + + if (value) + cl_assert_equal_s(value, check); + else + cl_assert(check == NULL); + git__free(check); -#endif } void test_core_env__0(void) diff --git a/tests/core/ftruncate.c b/tests/core/ftruncate.c index 21981d677..2f4729fc2 100644 --- a/tests/core/ftruncate.c +++ b/tests/core/ftruncate.c @@ -10,7 +10,7 @@ static int fd = -1; void test_core_ftruncate__initialize(void) { - if (!cl_getenv("GITTEST_INVASIVE_FS_SIZE")) + if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE")) cl_skip(); cl_must_pass((fd = p_open(filename, O_CREAT | O_RDWR, 0644))); |