1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2009, 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 http://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 ***************************************************************************/
41 #if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
46 char *GetEnv(const char *variable, char do_expand)
50 char buf1[1024], buf2[1024];
53 /* Don't use getenv(); it doesn't find variable added after program was
54 * started. Don't accept truncated results (i.e. rc >= sizeof(buf1)). */
56 rc = GetEnvironmentVariable(variable, buf1, sizeof(buf1));
57 if (rc > 0 && rc < sizeof(buf1)) {
61 if (do_expand && strchr(variable,'%')) {
62 /* buf2 == variable if not expanded */
63 rc = ExpandEnvironmentStrings (variable, buf2, sizeof(buf2));
64 if (rc > 0 && rc < sizeof(buf2) &&
65 !strchr(buf2,'%')) /* no vars still unexpanded */
71 env = getenv(variable);
72 if (env && strcmp("HOME",variable) == 0) {
73 env = decc_translate_vms(env);
76 /* no length control */
77 env = getenv(variable);
80 return (env && env[0])?strdup(env):NULL;
83 /* return the home directory of the current user as an allocated string */
88 home = GetEnv("CURL_HOME", FALSE);
92 home = GetEnv("HOME", FALSE);
96 #if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
98 struct passwd *pw = getpwuid(geteuid());
102 home = decc_translate_vms(pw->pw_dir);
112 #endif /* PWD-stuff */
114 home = GetEnv("APPDATA", TRUE);
116 home = GetEnv("%USERPROFILE%\\Application Data", TRUE); /* Normally only