xref: /reactos/sdk/lib/crt/stdlib/getenv.c (revision c2c66aff)
1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS system libraries
4  * FILE:        lib/sdk/crt/stdlib/getenv.c
5  * PURPOSE:     Unknown
6  * PROGRAMER:   Unknown
7  * UPDATE HISTORY:
8  *              25/11/05: Added license header
9  */
10 
11 #include <precomp.h>
12 //#undef environ
13 
14 /*
15  * @implemented
16  */
getenv(const char * name)17 char *getenv(const char *name)
18 {
19    char **env;
20    size_t length = strlen(name);
21 
22    for (env = *__p__environ(); *env; env++)
23    {
24       char *str = *env;
25       char *pos = strchr(str,'=');
26       if (pos && ((unsigned int)(pos - str) == length) && !_strnicmp(str, name, length))
27          return pos + 1;
28    }
29    return NULL;
30 }
31 
32 /*
33  * @implemented
34  */
_wgetenv(const wchar_t * name)35 wchar_t *_wgetenv(const wchar_t *name)
36 {
37    wchar_t **env;
38    size_t length = wcslen(name);
39 
40    for (env = *__p__wenviron(); *env; env++)
41    {
42       wchar_t *str = *env;
43       wchar_t *pos = wcschr(str, L'=');
44       if (pos && ((unsigned int)(pos - str) == length) && !_wcsnicmp(str, name, length))
45          return pos + 1;
46    }
47    return NULL;
48 }
49