- Complete rewrite of environment variable handling to get rid of memory leaks, heap...
[reactos.git] / reactos / lib / msvcrt / stdlib / getenv.c
1 #include "precomp.h"
2 #include <msvcrt/stdlib.h>
3
4 #define NDEBUG
5 #include <msvcrt/msvcrtdbg.h>
6
7 #undef environ
8
9 /*
10 * @implemented
11 */
12 char *getenv(const char *name)
13 {
14 char **environ;
15 unsigned int length = strlen(name);
16
17 for (environ = *__p__environ(); *environ; environ++)
18 {
19 char *str = *environ;
20 char *pos = strchr(str,'=');
21 if (pos && ((pos - str) == length) && !strnicmp(str, name, length))
22 return pos + 1;
23 }
24 return NULL;
25 }
26
27 /*
28 * @implemented
29 */
30 wchar_t *_wgetenv(const wchar_t *name)
31 {
32 wchar_t **environ;
33 unsigned int length = wcslen(name);
34
35 for (environ = *__p__wenviron(); *environ; environ++)
36 {
37 wchar_t *str = *environ;
38 wchar_t *pos = wcschr(str, L'=');
39 if (pos && ((pos - str) == length) && !wcsnicmp(str, name, length))
40 return pos + 1;
41 }
42 return NULL;
43 }