/src/httpd/srclib/apr/misc/unix/env.c
Line | Count | Source (jump to first uncovered line) |
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 | | #include "apr_strings.h" |
23 | | |
24 | | #if APR_HAVE_UNISTD_H |
25 | | #include <unistd.h> |
26 | | #endif |
27 | | #if APR_HAVE_STDLIB_H |
28 | | #include <stdlib.h> |
29 | | #endif |
30 | | |
31 | | APR_DECLARE(apr_status_t) apr_env_get(char **value, |
32 | | const char *envvar, |
33 | | apr_pool_t *pool) |
34 | 0 | { |
35 | 0 | #ifdef HAVE_GETENV |
36 | |
|
37 | 0 | char *val = getenv(envvar); |
38 | 0 | if (!val) |
39 | 0 | return APR_ENOENT; |
40 | 0 | *value = val; |
41 | 0 | return APR_SUCCESS; |
42 | |
|
43 | | #else |
44 | | return APR_ENOTIMPL; |
45 | | #endif |
46 | 0 | } |
47 | | |
48 | | |
49 | | APR_DECLARE(apr_status_t) apr_env_set(const char *envvar, |
50 | | const char *value, |
51 | | apr_pool_t *pool) |
52 | 0 | { |
53 | 0 | #if defined(HAVE_SETENV) |
54 | |
|
55 | 0 | if (0 > setenv(envvar, value, 1)) |
56 | 0 | return APR_ENOMEM; |
57 | 0 | return APR_SUCCESS; |
58 | |
|
59 | | #elif defined(HAVE_PUTENV) |
60 | | |
61 | | if (0 > putenv(apr_pstrcat(pool, envvar, "=", value, NULL))) |
62 | | return APR_ENOMEM; |
63 | | return APR_SUCCESS; |
64 | | |
65 | | #else |
66 | | return APR_ENOTIMPL; |
67 | | #endif |
68 | 0 | } |
69 | | |
70 | | |
71 | | APR_DECLARE(apr_status_t) apr_env_delete(const char *envvar, apr_pool_t *pool) |
72 | 0 | { |
73 | 0 | #ifdef HAVE_UNSETENV |
74 | |
|
75 | 0 | unsetenv(envvar); |
76 | 0 | return APR_SUCCESS; |
77 | |
|
78 | | #else |
79 | | /* hint: some platforms allow envvars to be unset via |
80 | | * putenv("varname")... that isn't Single Unix spec, |
81 | | * but if your platform doesn't have unsetenv() it is |
82 | | * worth investigating and potentially adding a |
83 | | * configure check to decide when to use that form of |
84 | | * putenv() here |
85 | | */ |
86 | | return APR_ENOTIMPL; |
87 | | #endif |
88 | 0 | } |