- Added f8 (history retrieval from partial command) support
[wine/multimedia.git] / dlls / msvcrt / environ.c
blobc213f1ea886a3ad34eb208b5ef62239dd699cb40
1 /*
2 * msvcrt.dll environment functions
4 * Copyright 1996,1998 Marcus Meissner
5 * Copyright 1996 Jukka Iivonen
6 * Copyright 1997,2000 Uwe Bonnes
7 * Copyright 2000 Jon Griffiths
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/unicode.h"
24 #include "msvcrt.h"
26 #include "msvcrt/stdlib.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
33 /*********************************************************************
34 * getenv (MSVCRT.@)
36 char *MSVCRT_getenv(const char *name)
38 char *environ = GetEnvironmentStringsA();
39 char *pp,*pos = NULL;
40 unsigned int length=strlen(name);
42 for (pp = environ; (*pp); pp = pp + strlen(pp) +1)
44 pos =strchr(pp,'=');
45 if ((pos) && ((pos - pp) == length))
47 if (!strncasecmp(pp,name,length)) break;
50 if ((*pp)&& (pos))
52 pp = pos+1;
53 TRACE("got %s\n",pp);
55 else
56 pp = 0;
57 FreeEnvironmentStringsA( environ );
58 return pp;
61 /*********************************************************************
62 * _wgetenv (MSVCRT.@)
64 WCHAR *_wgetenv(const WCHAR *name)
66 WCHAR* environ = GetEnvironmentStringsW();
67 WCHAR* pp,*pos = NULL;
68 unsigned int length=strlenW(name);
70 for (pp = environ; (*pp); pp = pp + strlenW(pp) + 1)
72 pos = strchrW(pp,'=');
73 if ((pos) && ((pos - pp) == length))
75 if (!strncmpiW(pp,name,length))
77 pp = pos+1;
78 TRACE("got %s\n",debugstr_w(pp));
79 /* can't free pointer since we are returning it */
80 /* should probably use MSVCRT_wenviron instead */
81 FIXME( "memory leak\n" );
82 return pp;
86 FreeEnvironmentStringsW( environ );
87 return NULL;
90 /*********************************************************************
91 * _putenv (MSVCRT.@)
93 int _putenv(const char *str)
95 char name[256], value[512];
96 char *dst = name;
98 TRACE("%s\n", str);
100 if (!str)
101 return -1;
102 while (*str && *str != '=')
103 *dst++ = *str++;
104 if (!*str++)
105 return -1;
106 *dst = '\0';
107 dst = value;
108 while (*str)
109 *dst++ = *str++;
110 *dst = '\0';
112 return !SetEnvironmentVariableA(name, value[0] ? value : NULL);
115 /*********************************************************************
116 * _wputenv (MSVCRT.@)
118 int _wputenv(const WCHAR *str)
120 WCHAR name[256], value[512];
121 WCHAR *dst = name;
123 TRACE("%s\n", debugstr_w(str));
125 if (!str)
126 return -1;
127 while (*str && *str != (WCHAR)L'=')
128 *dst++ = *str++;
129 if (!*str++)
130 return -1;
131 *dst = (WCHAR)L'\0';
132 dst = value;
133 while (*str)
134 *dst++ = *str++;
135 *dst = (WCHAR)L'\0';
137 return !SetEnvironmentVariableW(name, value[0] ? value : NULL);