1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
23 #include "curl_setup.h"
25 #include <curl/curl.h>
26 #include "curl_memory.h"
30 static char *GetEnv(const char *variable)
32 #if defined(_WIN32_WCE) || defined(CURL_WINDOWS_APP)
36 /* This uses Windows API instead of C runtime getenv() to get the environment
37 variable since some changes aren't always visible to the latter. #4774 */
42 const DWORD max = 32768; /* max env var size from MSCRT source */
45 tmp = realloc(buf, rc);
54 /* It's possible for rc to be 0 if the variable was found but empty.
55 Since getenv doesn't make that distinction we ignore it as well. */
56 rc = GetEnvironmentVariableA(variable, buf, bufsize);
57 if(!rc || rc == bufsize || rc > max) {
62 /* if rc < bufsize then rc is bytes written not including null */
66 /* else rc is bytes needed, try again */
69 char *env = getenv(variable);
70 return (env && env[0])?strdup(env):NULL;
74 char *curl_getenv(const char *v)