Robert Weaver's fix
[platform/upstream/curl.git] / lib / getenv.c
1 /*****************************************************************************
2  *                                  _   _ ____  _     
3  *  Project                     ___| | | |  _ \| |    
4  *                             / __| | | | |_) | |    
5  *                            | (__| |_| |  _ <| |___ 
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 2000, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * In order to be useful for every potential user, curl and libcurl are
11  * dual-licensed under the MPL and the MIT/X-derivate licenses.
12  *
13  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
14  * copies of the Software, and permit persons to whom the Software is
15  * furnished to do so, under the terms of the MPL or the MIT/X-derivate
16  * licenses. You may pick one of these licenses.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  * $Id$
22  *****************************************************************************/
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #ifdef WIN32
29 #include <windows.h>
30 #endif
31
32 #ifdef MALLOCDEBUG
33 #include "memdebug.h"
34 #endif
35
36 static
37 char *GetEnv(char *variable)
38 {
39 #ifdef WIN32
40   /* This shit requires windows.h (HUGE) to be included */
41   char env[MAX_PATH]; /* MAX_PATH is from windef.h */
42   char *temp = getenv(variable);
43   env[0] = '\0';
44   if (temp != NULL)
45     ExpandEnvironmentStrings(temp, env, sizeof(env));
46 #else
47   /* no length control */
48   char *env = getenv(variable);
49 #endif
50   return (env && env[0])?strdup(env):NULL;
51 }
52
53 char *curl_getenv(char *v)
54 {
55   return GetEnv(v);
56 }