Nico Baggus' VMS adjustments
[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 VMS
33 #include <unixlib.h>
34 #endif
35
36 #ifdef MALLOCDEBUG
37 #include "memdebug.h"
38 #endif
39
40 static
41 char *GetEnv(char *variable)
42 {
43 #ifdef WIN32
44   /* This shit requires windows.h (HUGE) to be included */
45   char env[MAX_PATH]; /* MAX_PATH is from windef.h */
46   char *temp = getenv(variable);
47   env[0] = '\0';
48   if (temp != NULL)
49     ExpandEnvironmentStrings(temp, env, sizeof(env));
50 #else
51 #ifdef  VMS
52   char *env = getenv(variable);
53   if (env && strcmp("HOME",variable) == 0) {
54         env = decc$translate_vms(env);
55   }
56 /*  printf ("Getenv: %s=%s\n",variable,env); */
57 #else
58   /* no length control */
59   char *env = getenv(variable);
60 #endif
61 #endif
62   return (env && env[0])?strdup(env):NULL;
63 }
64
65 char *curl_getenv(char *v)
66 {
67   return GetEnv(v);
68 }