Added an unknown VxD error code.
[wine] / dlls / msvcrt / environ.c
1 /*
2  * msvcrt.dll environment functions
3  *
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"
11
12 #include "msvcrt/stdlib.h"
13
14
15 DEFAULT_DEBUG_CHANNEL(msvcrt);
16
17 /*********************************************************************
18  *              getenv (MSVCRT.@)
19  */
20 char *MSVCRT_getenv(const char *name)
21 {
22   char *environ = GetEnvironmentStringsA();
23   char *pp,*pos = NULL;
24   unsigned int length;
25
26   for (pp = environ; (*pp); pp = pp + strlen(pp) +1)
27   {
28     pos =strchr(pp,'=');
29     if (pos)
30       length = pos -pp;
31     else
32       length = strlen(pp);
33     if (!strncmp(pp,name,length)) break;
34   }
35   if ((pp)&& (pos))
36   {
37      pp = pos+1;
38      TRACE("got %s\n",pp);
39   }
40   FreeEnvironmentStringsA( environ );
41   return pp;
42 }
43
44 /*********************************************************************
45  *              _wgetenv (MSVCRT.@)
46  */
47 WCHAR *_wgetenv(const WCHAR *name)
48 {
49   WCHAR* environ = GetEnvironmentStringsW();
50   WCHAR* pp,*pos = NULL;
51   unsigned int length;
52
53   for (pp = environ; (*pp); pp = pp + strlenW(pp) + 1)
54   {
55     pos = strrchrW(pp,'=');
56     if (pos)
57       length = pos -pp;
58     else
59       length = strlenW(pp);
60     if (!strncmpW(pp,name,length)) break;
61   }
62   if ((pp)&& (pos))
63   {
64      pp = pos+1;
65      TRACE("got %s\n",debugstr_w(pp));
66   }
67   FreeEnvironmentStringsW( environ );
68   return pp;
69 }
70
71 /*********************************************************************
72  *              _putenv (MSVCRT.@)
73  */
74 int _putenv(const char *str)
75 {
76  char name[256], value[512];
77  char *dst = name;
78
79  TRACE("%s\n", str);
80
81  if (!str)
82    return -1;
83  while (*str && *str != '=')
84   *dst++ = *str++;
85  if (!*str++)
86    return -1;
87  *dst = '\0';
88  dst = value;
89  while (*str)
90   *dst++ = *str++;
91  *dst = '\0';
92
93  return !SetEnvironmentVariableA(name, value[0] ? value : NULL);
94 }
95
96 /*********************************************************************
97  *              _wputenv (MSVCRT.@)
98  */
99 int _wputenv(const WCHAR *str)
100 {
101  WCHAR name[256], value[512];
102  WCHAR *dst = name;
103
104  TRACE("%s\n", debugstr_w(str));
105
106  if (!str)
107    return -1;
108  while (*str && *str != (WCHAR)L'=')
109   *dst++ = *str++;
110  if (!*str++)
111    return -1;
112  *dst = (WCHAR)L'\0';
113  dst = value;
114  while (*str)
115   *dst++ = *str++;
116  *dst = (WCHAR)L'\0';
117
118  return !SetEnvironmentVariableW(name, value[0] ? value : NULL);
119 }