diff options
author | Mladen Turk <mturk@apache.org> | 2021-12-02 21:45:47 +0000 |
---|---|---|
committer | Mladen Turk <mturk@apache.org> | 2021-12-02 21:45:47 +0000 |
commit | 3579ad96307fc536b7e53d8dc81a819655446c71 (patch) | |
tree | 1cb27d42edcaffbb50617668c7e3fca7bb2c81cf /misc | |
parent | 6487330c38e3c0430782a5ceca674b94398f347f (diff) | |
download | apr-3579ad96307fc536b7e53d8dc81a819655446c71.tar.gz |
Stage 1 in cleaning win95 code ... cleanup utils
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1895509 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'misc')
-rw-r--r-- | misc/win32/env.c | 168 |
1 files changed, 56 insertions, 112 deletions
diff --git a/misc/win32/env.c b/misc/win32/env.c index 3712309b9..5838feaac 100644 --- a/misc/win32/env.c +++ b/misc/win32/env.c @@ -24,7 +24,6 @@ #include "apr_pools.h" #include "apr_strings.h" -#if APR_HAS_UNICODE_FS static apr_status_t widen_envvar_name (apr_wchar_t *buffer, apr_size_t bufflen, const char *envvar) @@ -39,7 +38,6 @@ static apr_status_t widen_envvar_name (apr_wchar_t *buffer, return status; } -#endif APR_DECLARE(apr_status_t) apr_env_get(char **value, @@ -48,66 +46,36 @@ APR_DECLARE(apr_status_t) apr_env_get(char **value, { char *val = NULL; DWORD size; - -#if APR_HAS_UNICODE_FS - IF_WIN_OS_IS_UNICODE - { - apr_wchar_t wenvvar[APR_PATH_MAX]; - apr_size_t inchars, outchars; - apr_wchar_t *wvalue, dummy; - apr_status_t status; - - status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar); - if (status) - return status; - - SetLastError(0); - size = GetEnvironmentVariableW(wenvvar, &dummy, 0); - if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) - /* The environment variable doesn't exist. */ - return APR_ENOENT; - - if (size == 0) { - /* The environment value exists, but is zero-length. */ - *value = apr_pstrdup(pool, ""); - return APR_SUCCESS; - } - - wvalue = apr_palloc(pool, size * sizeof(*wvalue)); - size = GetEnvironmentVariableW(wenvvar, wvalue, size); - - inchars = wcslen(wvalue) + 1; - outchars = 3 * inchars; /* Enough for any UTF-8 representation */ - val = apr_palloc(pool, outchars); - status = apr_conv_utf16_to_utf8(wvalue, &inchars, val, &outchars); - if (status) - return status; - } -#endif -#if APR_HAS_ANSI_FS - ELSE_WIN_OS_IS_ANSI - { - char dummy; - - SetLastError(0); - size = GetEnvironmentVariableA(envvar, &dummy, 0); - if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) - /* The environment variable doesn't exist. */ - return APR_ENOENT; - - if (size == 0) { - /* The environment value exists, but is zero-length. */ - *value = apr_pstrdup(pool, ""); - return APR_SUCCESS; - } - - val = apr_palloc(pool, size); - size = GetEnvironmentVariableA(envvar, val, size); - if (size == 0) - /* Mid-air collision?. Somebody must've changed the env. var. */ - return APR_INCOMPLETE; - } -#endif + apr_wchar_t wenvvar[APR_PATH_MAX]; + apr_size_t inchars, outchars; + apr_wchar_t *wvalue, dummy; + apr_status_t status; + + status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar); + if (status) + return status; + + SetLastError(0); + size = GetEnvironmentVariableW(wenvvar, &dummy, 0); + if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) + /* The environment variable doesn't exist. */ + return APR_ENOENT; + + if (size == 0) { + /* The environment value exists, but is zero-length. */ + *value = apr_pstrdup(pool, ""); + return APR_SUCCESS; + } + + wvalue = apr_palloc(pool, size * sizeof(*wvalue)); + size = GetEnvironmentVariableW(wenvvar, wvalue, size); + + inchars = wcslen(wvalue) + 1; + outchars = 3 * inchars; /* Enough for any UTF-8 representation */ + val = apr_palloc(pool, outchars); + status = apr_conv_utf16_to_utf8(wvalue, &inchars, val, &outchars); + if (status) + return status; *value = val; return APR_SUCCESS; @@ -118,35 +86,23 @@ APR_DECLARE(apr_status_t) apr_env_set(const char *envvar, const char *value, apr_pool_t *pool) { -#if APR_HAS_UNICODE_FS - IF_WIN_OS_IS_UNICODE - { - apr_wchar_t wenvvar[APR_PATH_MAX]; - apr_wchar_t *wvalue; - apr_size_t inchars, outchars; - apr_status_t status; - - status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar); - if (status) - return status; - - outchars = inchars = strlen(value) + 1; - wvalue = apr_palloc(pool, outchars * sizeof(*wvalue)); - status = apr_conv_utf8_to_utf16(value, &inchars, wvalue, &outchars); - if (status) - return status; - - if (!SetEnvironmentVariableW(wenvvar, wvalue)) - return apr_get_os_error(); - } -#endif -#if APR_HAS_ANSI_FS - ELSE_WIN_OS_IS_ANSI - { - if (!SetEnvironmentVariableA(envvar, value)) - return apr_get_os_error(); - } -#endif + apr_wchar_t wenvvar[APR_PATH_MAX]; + apr_wchar_t *wvalue; + apr_size_t inchars, outchars; + apr_status_t status; + + status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar); + if (status) + return status; + + outchars = inchars = strlen(value) + 1; + wvalue = apr_palloc(pool, outchars * sizeof(*wvalue)); + status = apr_conv_utf8_to_utf16(value, &inchars, wvalue, &outchars); + if (status) + return status; + + if (!SetEnvironmentVariableW(wenvvar, wvalue)) + return apr_get_os_error(); return APR_SUCCESS; } @@ -154,27 +110,15 @@ APR_DECLARE(apr_status_t) apr_env_set(const char *envvar, APR_DECLARE(apr_status_t) apr_env_delete(const char *envvar, apr_pool_t *pool) { -#if APR_HAS_UNICODE_FS - IF_WIN_OS_IS_UNICODE - { - apr_wchar_t wenvvar[APR_PATH_MAX]; - apr_status_t status; - - status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar); - if (status) - return status; - - if (!SetEnvironmentVariableW(wenvvar, NULL)) - return apr_get_os_error(); - } -#endif -#if APR_HAS_ANSI_FS - ELSE_WIN_OS_IS_ANSI - { - if (!SetEnvironmentVariableA(envvar, NULL)) - return apr_get_os_error(); - } -#endif + apr_wchar_t wenvvar[APR_PATH_MAX]; + apr_status_t status; + + status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar); + if (status) + return status; + + if (!SetEnvironmentVariableW(wenvvar, NULL)) + return apr_get_os_error(); return APR_SUCCESS; } |