bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / misc / unix / env.c
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #define APR_WANT_STRFUNC
18 #include "apr_want.h"
19 #include "apr.h"
20 #include "apr_private.h"
21 #include "apr_env.h"
22
23 #if APR_HAVE_UNISTD_H
24 #include <unistd.h>
25 #endif
26 #if APR_HAVE_STDLIB_H
27 #include <stdlib.h>
28 #endif
29
30 APR_DECLARE(apr_status_t) apr_env_get(char **value,
31                                       const char *envvar,
32                                       apr_pool_t *pool)
33 {
34 #ifdef HAVE_GETENV
35
36     char *val = getenv(envvar);
37     if (!val)
38         return APR_ENOENT;
39     *value = val;
40     return APR_SUCCESS;
41
42 #else
43     return APR_ENOTIMPL;
44 #endif
45 }
46
47
48 APR_DECLARE(apr_status_t) apr_env_set(const char *envvar,
49                                       const char *value,
50                                       apr_pool_t *pool)
51 {
52 #if defined(HAVE_SETENV)
53
54     if (0 > setenv(envvar, value, 1))
55         return APR_ENOMEM;
56     return APR_SUCCESS;
57
58 #elif defined(HAVE_PUTENV)
59
60     apr_size_t elen = strlen(envvar);
61     apr_size_t vlen = strlen(value);
62     char *env = apr_palloc(pool, elen + vlen + 2);
63     char *p = env + elen;
64
65     memcpy(env, envvar, elen);
66     *p++ = '=';
67     memcpy(p, value, vlen);
68     p[vlen] = '\0';
69
70     if (0 > putenv(env))
71         return APR_ENOMEM;
72     return APR_SUCCESS;
73
74 #else
75     return APR_ENOTIMPL;
76 #endif
77 }
78
79
80 APR_DECLARE(apr_status_t) apr_env_delete(const char *envvar, apr_pool_t *pool)
81 {
82 #ifdef HAVE_UNSETENV
83
84     unsetenv(envvar);
85     return APR_SUCCESS;
86
87 #else
88     /* hint: some platforms allow envvars to be unset via
89      *       putenv("varname")...  that isn't Single Unix spec,
90      *       but if your platform doesn't have unsetenv() it is
91      *       worth investigating and potentially adding a
92      *       configure check to decide when to use that form of
93      *       putenv() here
94      */
95     return APR_ENOTIMPL;
96 #endif
97 }