source: trunk/src/msvcrt/environ.c@ 10005

Last change on this file since 10005 was 10005, checked in by sandervl, 22 years ago

PF: MSVCRT update

File size: 4.0 KB
Line 
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 * 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.
13 *
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.
18 *
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
22 */
23#ifdef __WIN32OS2__
24#include <winbase.h>
25#include <string.h>
26#endif
27
28#include "wine/unicode.h"
29#include "msvcrt.h"
30
31#include "msvcrt/stdlib.h"
32
33
34#include "wine/debug.h"
35
36WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
37
38/*********************************************************************
39 * getenv (MSVCRT.@)
40 */
41char *MSVCRT_getenv(const char *name)
42{
43 char *environ = GetEnvironmentStringsA();
44 char *pp,*pos = NULL;
45 unsigned int length=strlen(name);
46
47 dprintf(("MSVCRT: %s",name));
48
49 for (pp = environ; (*pp); pp = pp + strlen(pp) +1)
50 {
51 pos =strchr(pp,'=');
52 if ((pos) && ((pos - pp) == length))
53 {
54 if (!_strnicmp(pp,name,length)) break;
55 }
56 }
57 if ((*pp)&& (pos))
58 {
59 pp = pos+1;
60 TRACE("got %s\n",pp);
61 }
62 else
63 pp = 0;
64 FreeEnvironmentStringsA( environ );
65 return pp;
66}
67
68/*********************************************************************
69 * _wgetenv (MSVCRT.@)
70 */
71MSVCRT_wchar_t *_wgetenv(const MSVCRT_wchar_t *name)
72{
73 MSVCRT_wchar_t* environ = GetEnvironmentStringsW();
74 MSVCRT_wchar_t* pp,*pos = NULL;
75 unsigned int length=strlenW(name);
76
77 dprintf(("MSVCRT: _wgetenv %s",debugstr_w(name)));
78
79 for (pp = environ; (*pp); pp = pp + strlenW(pp) + 1)
80 {
81 pos = strchrW(pp,'=');
82 if ((pos) && ((pos - pp) == length))
83 {
84 if (!strncmpiW(pp,name,length))
85 {
86 pp = pos+1;
87 TRACE("got %s\n",debugstr_w(pp));
88 /* can't free pointer since we are returning it */
89 /* should probably use MSVCRT_wenviron instead */
90 FIXME( "memory leak\n" );
91 return pp;
92 }
93 }
94 }
95 FreeEnvironmentStringsW( environ );
96 return NULL;
97}
98
99/*********************************************************************
100 * _putenv (MSVCRT.@)
101 */
102int MSVCRT__putenv(const char *str)
103{
104 char name[256], value[512];
105 char *dst = name;
106 int ret;
107
108 TRACE("%s\n", str);
109
110 if (!str)
111 return -1;
112 while (*str && *str != '=')
113 *dst++ = *str++;
114 if (!*str++)
115 return -1;
116 *dst = '\0';
117 dst = value;
118 while (*str)
119 *dst++ = *str++;
120 *dst = '\0';
121
122 ret = !SetEnvironmentVariableA(name, value[0] ? value : NULL);
123 /* Update the __p__environ array only when already initialized */
124 if (MSVCRT__environ)
125 MSVCRT__environ = msvcrt_SnapshotOfEnvironmentA(MSVCRT__environ);
126 if (MSVCRT__wenviron)
127 MSVCRT__wenviron = msvcrt_SnapshotOfEnvironmentW(MSVCRT__wenviron);
128 return ret;
129}
130
131/*********************************************************************
132 * _wputenv (MSVCRT.@)
133 */
134int _wputenv(const MSVCRT_wchar_t *str)
135{
136 MSVCRT_wchar_t name[256], value[512];
137 MSVCRT_wchar_t *dst = name;
138 int ret;
139
140 TRACE("%s\n", debugstr_w(str));
141
142 if (!str)
143 return -1;
144 while (*str && *str != '=')
145 *dst++ = *str++;
146 if (!*str++)
147 return -1;
148 *dst = 0;
149 dst = value;
150 while (*str)
151 *dst++ = *str++;
152 *dst = 0;
153
154 ret = !SetEnvironmentVariableW(name, value[0] ? value : NULL);
155 /* Update the __p__environ array only when already initialized */
156 if (MSVCRT__environ)
157 MSVCRT__environ = msvcrt_SnapshotOfEnvironmentA(MSVCRT__environ);
158 if (MSVCRT__wenviron)
159 MSVCRT__wenviron = msvcrt_SnapshotOfEnvironmentW(MSVCRT__wenviron);
160 return ret;
161}
Note: See TracBrowser for help on using the repository browser.