Display thread id instead of %fs in relay trace.
[wine.git] / dlls / msvcrt / environ.c
blob03990d13bcc8cb33a5c37a058e6596f03c834e13
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
8 */
9 #include "wine/unicode.h"
10 #include "msvcrt.h"
12 DEFAULT_DEBUG_CHANNEL(msvcrt);
14 LPWSTR __cdecl wcsrchr( LPWSTR str, WCHAR ch );
16 /*********************************************************************
17 * getenv (MSVCRT.@)
19 char *__cdecl MSVCRT_getenv(const char *name)
21 char *environ = GetEnvironmentStringsA();
22 char *pp,*pos = NULL;
23 unsigned int length;
25 for (pp = environ; (*pp); pp = pp + strlen(pp) +1)
27 pos =strchr(pp,'=');
28 if (pos)
29 length = pos -pp;
30 else
31 length = strlen(pp);
32 if (!strncmp(pp,name,length)) break;
34 if ((pp)&& (pos))
36 pp = pos+1;
37 TRACE("got %s\n",pp);
39 FreeEnvironmentStringsA( environ );
40 return pp;
43 /*********************************************************************
44 * _wgetenv (MSVCRT.@)
46 WCHAR *__cdecl MSVCRT__wgetenv(const WCHAR *name)
48 WCHAR* environ = GetEnvironmentStringsW();
49 WCHAR* pp,*pos = NULL;
50 unsigned int length;
52 for (pp = environ; (*pp); pp = pp + strlenW(pp) + 1)
54 pos =wcsrchr(pp,'=');
55 if (pos)
56 length = pos -pp;
57 else
58 length = strlenW(pp);
59 if (!strncmpW(pp,name,length)) break;
61 if ((pp)&& (pos))
63 pp = pos+1;
64 TRACE("got %s\n",debugstr_w(pp));
66 FreeEnvironmentStringsW( environ );
67 return pp;
70 /*********************************************************************
71 * _putenv (MSVCRT.@)
73 int __cdecl MSVCRT__putenv(const char *str)
75 char name[256], value[512];
76 char *dst = name;
78 TRACE("%s\n", str);
80 if (!str)
81 return -1;
82 while (*str && *str != '=')
83 *dst++ = *str++;
84 if (!*str++)
85 return -1;
86 *dst = '\0';
87 dst = value;
88 while (*str)
89 *dst++ = *str++;
90 *dst = '\0';
92 return !SetEnvironmentVariableA(name, value[0] ? value : NULL);
95 /*********************************************************************
96 * _wputenv (MSVCRT.@)
98 int __cdecl MSVCRT__wputenv(const WCHAR *str)
100 WCHAR name[256], value[512];
101 WCHAR *dst = name;
103 TRACE("%s\n", debugstr_w(str));
105 if (!str)
106 return -1;
107 while (*str && *str != (WCHAR)L'=')
108 *dst++ = *str++;
109 if (!*str++)
110 return -1;
111 *dst = (WCHAR)L'\0';
112 dst = value;
113 while (*str)
114 *dst++ = *str++;
115 *dst = (WCHAR)L'\0';
117 return !SetEnvironmentVariableW(name, value[0] ? value : NULL);