1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
#define APR_WANT_STRFUNC
20
#include "apr_arch_misc.h"
21
#include "apr_arch_utf8.h"
23
#include "apr_errno.h"
24
#include "apr_pools.h"
27
#if APR_HAS_UNICODE_FS
28
static apr_status_t widen_envvar_name (apr_wchar_t *buffer,
35
inchars = strlen(envvar) + 1;
36
status = apr_conv_utf8_to_ucs2(envvar, &inchars, buffer, &bufflen);
37
if (status == APR_INCOMPLETE)
38
status = APR_ENAMETOOLONG;
45
APR_DECLARE(apr_status_t) apr_env_get(char **value,
52
#if APR_HAS_UNICODE_FS
55
apr_wchar_t wenvvar[APR_PATH_MAX];
56
apr_size_t inchars, outchars;
57
apr_wchar_t *wvalue, dummy;
60
status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar);
64
size = GetEnvironmentVariableW(wenvvar, &dummy, 0);
66
/* The environment variable doesn't exist. */
69
wvalue = apr_palloc(pool, size * sizeof(*wvalue));
70
size = GetEnvironmentVariableW(wenvvar, wvalue, size);
72
/* Mid-air collision?. Somebody must've changed the env. var. */
73
return APR_INCOMPLETE;
75
inchars = wcslen(wvalue) + 1;
76
outchars = 3 * inchars; /* Enougn for any UTF-8 representation */
77
val = apr_palloc(pool, outchars);
78
status = apr_conv_ucs2_to_utf8(wvalue, &inchars, val, &outchars);
88
size = GetEnvironmentVariableA(envvar, &dummy, 0);
90
/* The environment variable doesn't exist. */
93
val = apr_palloc(pool, size);
94
size = GetEnvironmentVariableA(envvar, val, size);
96
/* Mid-air collision?. Somebody must've changed the env. var. */
97
return APR_INCOMPLETE;
106
APR_DECLARE(apr_status_t) apr_env_set(const char *envvar,
110
#if APR_HAS_UNICODE_FS
113
apr_wchar_t wenvvar[APR_PATH_MAX];
115
apr_size_t inchars, outchars;
118
status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar);
122
outchars = inchars = strlen(value) + 1;
123
wvalue = apr_palloc(pool, outchars * sizeof(*wvalue));
124
status = apr_conv_utf8_to_ucs2(value, &inchars, wvalue, &outchars);
128
if (!SetEnvironmentVariableW(wenvvar, wvalue))
129
return apr_get_os_error();
135
if (!SetEnvironmentVariableA(envvar, value))
136
return apr_get_os_error();
144
APR_DECLARE(apr_status_t) apr_env_delete(const char *envvar, apr_pool_t *pool)
146
#if APR_HAS_UNICODE_FS
149
apr_wchar_t wenvvar[APR_PATH_MAX];
152
status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar);
156
if (!SetEnvironmentVariableW(wenvvar, NULL))
157
return apr_get_os_error();
163
if (!SetEnvironmentVariableA(envvar, NULL))
164
return apr_get_os_error();