ReactOS  0.4.13-dev-479-gec9c8fd
environ.c File Reference
#include "wine/test.h"
#include <stdlib.h>
Include dependency graph for environ.c:

Go to the source code of this file.

Functions

void __cdecl __getmainargs (int *, char ***, char ***, int, int *)
 
void __cdecl __wgetmainargs (int *, wchar_t ***, wchar_t ***, int, int *)
 
static char ***__cdeclp__p__environ (void)
 
static WCHAR ***__cdeclp__p__wenviron (void)
 
static void init (void)
 
static void test_system (void)
 
static void test__environ (void)
 
static void test__wenviron (void)
 
static void test_environment_manipulation (void)
 
 START_TEST (environ)
 

Variables

static const chara_very_long_env_string
 
static char *** p_environ
 
static WCHAR *** p_wenviron
 

Function Documentation

◆ __getmainargs()

void __cdecl __getmainargs ( int ,
char ***  ,
char ***  ,
int  ,
int  
)

Definition at line 182 of file getargs.c.

183 {
184  int i, doexpand, slashesAdded, escapedQuote, inQuotes, bufferIndex, anyLetter;
185  size_t len;
186  char* buffer;
187 
188  /* missing threading init */
189 
190  i = 0;
191  doexpand = expand_wildcards;
192  escapedQuote = FALSE;
193  anyLetter = FALSE;
194  slashesAdded = 0;
195  inQuotes = 0;
196  bufferIndex = 0;
197 
198  if (__argv && _environ)
199  {
200  *argv = __argv;
201  *env = _environ;
202  *argc = __argc;
203  return;
204  }
205 
206  __argc = 0;
207 
208  len = strlen(_acmdln);
209  buffer = malloc(sizeof(char) * len);
210 
211  // Reference: https://msdn.microsoft.com/en-us/library/a1y7w461.aspx
212  while (TRUE)
213  {
214  // Arguments are delimited by white space, which is either a space or a tab.
215  if (i >= len || ((_acmdln[i] == ' ' || _acmdln[i] == '\t') && !inQuotes))
216  {
217  // Handle the case when empty spaces are in the end of the cmdline
218  if (anyLetter)
219  {
220  aexpand(strndup(buffer, bufferIndex), doexpand);
221  }
222  // Copy the last element from buffer and quit the loop
223  if (i >= len)
224  {
225  break;
226  }
227 
228  while (_acmdln[i] == ' ' || _acmdln[i] == '\t')
229  ++i;
230  anyLetter = FALSE;
231  bufferIndex = 0;
232  slashesAdded = 0;
233  escapedQuote = FALSE;
234  continue;
235  }
236 
237  anyLetter = TRUE;
238 
239  if (_acmdln[i] == '\\')
240  {
241  buffer[bufferIndex++] = _acmdln[i];
242  ++slashesAdded;
243  ++i;
244  escapedQuote = FALSE;
245  continue;
246  }
247 
248  if (_acmdln[i] == '\"')
249  {
250  if (slashesAdded > 0)
251  {
252  if (slashesAdded % 2 == 0)
253  {
254  // If an even number of backslashes is followed by a double quotation mark, then one backslash (\)
255  // is placed in the argv array for every pair of backslashes (\\), and the double quotation mark (")
256  // is interpreted as a string delimiter.
257  bufferIndex -= slashesAdded / 2;
258  }
259  else
260  {
261  // If an odd number of backslashes is followed by a double quotation mark, then one backslash (\)
262  // is placed in the argv array for every pair of backslashes (\\) and the double quotation mark is
263  // interpreted as an escape sequence by the remaining backslash, causing a literal double quotation mark (")
264  // to be placed in argv.
265  bufferIndex -= slashesAdded / 2 + 1;
266  buffer[bufferIndex++] = '\"';
267  slashesAdded = 0;
268  escapedQuote = TRUE;
269  ++i;
270  continue;
271  }
272  slashesAdded = 0;
273  }
274  else if (!inQuotes && i > 0 && _acmdln[i - 1] == '\"' && !escapedQuote)
275  {
276  buffer[bufferIndex++] = '\"';
277  ++i;
278  escapedQuote = TRUE;
279  continue;
280  }
281  slashesAdded = 0;
282  escapedQuote = FALSE;
283  inQuotes = !inQuotes;
284  doexpand = inQuotes ? FALSE : expand_wildcards;
285  ++i;
286  continue;
287  }
288 
289  buffer[bufferIndex++] = _acmdln[i];
290  slashesAdded = 0;
291  escapedQuote = FALSE;
292  ++i;
293  }
294 
295  /* Free the temporary buffer. */
296  free(buffer);
297 
298  *argc = __argc;
299  if (__argv == NULL)
300  {
301  __argv = (char**)malloc(sizeof(char*));
302  __argv[0] = 0;
303  }
304  *argv = __argv;
305  *env = _environ;
306 
307  _pgmptr = malloc(MAX_PATH * sizeof(char));
308  if (_pgmptr)
309  {
311  _pgmptr[0] = '\0';
312  else
313  _pgmptr[MAX_PATH - 1] = '\0';
314  }
315  else
316  {
317  _pgmptr = _strdup(__argv[0]);
318  }
319 
321 
322  // if (new_mode) _set_new_mode(*new_mode);
323 }
char ** _environ
Definition: environ.c:22
int __argc
Definition: getargs.c:21
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
char * _acmdln
Definition: environ.c:18
char ** __argv
Definition: getargs.c:18
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define free
Definition: debug_ros.c:5
BOOL WINAPI HeapValidate(HANDLE hHeap, DWORD dwFlags, LPCVOID lpMem)
Definition: heapmem.c:156
GLuint buffer
Definition: glext.h:5915
#define argv
Definition: mplay32.c:18
#define _strdup
Definition: debug_ros.c:7
DWORD WINAPI GetModuleFileNameA(HINSTANCE hModule, LPSTR lpFilename, DWORD nSize)
Definition: loader.c:546
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLuint bufferIndex
Definition: glext.h:7857
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
#define MAX_PATH
Definition: compat.h:26
int aexpand(char *name, int expand_wildcards)
Definition: getargs.c:132
GLenum GLsizei len
Definition: glext.h:6722
char * strndup(char const *name, size_t len)
Definition: getargs.c:25
char * _pgmptr
Definition: environ.c:27
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:168
#define malloc
Definition: debug_ros.c:4

Referenced by test__environ(), and test__wenviron().

◆ __wgetmainargs()

void __cdecl __wgetmainargs ( int ,
wchar_t ***  ,
wchar_t ***  ,
int  ,
int  
)

Definition at line 328 of file getargs.c.

330 {
331  int i, doexpand, slashesAdded, escapedQuote, inQuotes, bufferIndex, anyLetter;
332  size_t len;
333  wchar_t* buffer;
334 
335  /* missing threading init */
336 
337  i = 0;
338  doexpand = expand_wildcards;
339  escapedQuote = FALSE;
340  anyLetter = TRUE;
341  slashesAdded = 0;
342  inQuotes = 0;
343  bufferIndex = 0;
344 
345  if (__wargv && __winitenv)
346  {
347  *wargv = __wargv;
348  *wenv = __winitenv;
349  *argc = __argc;
350  return;
351  }
352 
353  __argc = 0;
354 
355  len = wcslen(_wcmdln);
356  buffer = malloc(sizeof(wchar_t) * len);
357 
358  // Reference: https://msdn.microsoft.com/en-us/library/a1y7w461.aspx
359  while (TRUE)
360  {
361  // Arguments are delimited by white space, which is either a space or a tab.
362  if (i >= len || ((_wcmdln[i] == ' ' || _wcmdln[i] == '\t') && !inQuotes))
363  {
364  // Handle the case when empty spaces are in the end of the cmdline
365  if (anyLetter)
366  {
367  wexpand(wcsndup(buffer, bufferIndex), doexpand);
368  }
369  // Copy the last element from buffer and quit the loop
370  if (i >= len)
371  {
372  break;
373  }
374 
375  while (_wcmdln[i] == ' ' || _wcmdln[i] == '\t')
376  ++i;
377  anyLetter = FALSE;
378  bufferIndex = 0;
379  slashesAdded = 0;
380  escapedQuote = FALSE;
381  continue;
382  }
383 
384  anyLetter = TRUE;
385 
386  if (_wcmdln[i] == '\\')
387  {
388  buffer[bufferIndex++] = _wcmdln[i];
389  ++slashesAdded;
390  ++i;
391  escapedQuote = FALSE;
392  continue;
393  }
394 
395  if (_wcmdln[i] == '\"')
396  {
397  if (slashesAdded > 0)
398  {
399  if (slashesAdded % 2 == 0)
400  {
401  // If an even number of backslashes is followed by a double quotation mark, then one backslash (\)
402  // is placed in the argv array for every pair of backslashes (\\), and the double quotation mark (")
403  // is interpreted as a string delimiter.
404  bufferIndex -= slashesAdded / 2;
405  }
406  else
407  {
408  // If an odd number of backslashes is followed by a double quotation mark, then one backslash (\)
409  // is placed in the argv array for every pair of backslashes (\\) and the double quotation mark is
410  // interpreted as an escape sequence by the remaining backslash, causing a literal double quotation mark (")
411  // to be placed in argv.
412  bufferIndex -= slashesAdded / 2 + 1;
413  buffer[bufferIndex++] = '\"';
414  slashesAdded = 0;
415  escapedQuote = TRUE;
416  ++i;
417  continue;
418  }
419  slashesAdded = 0;
420  }
421  else if (!inQuotes && i > 0 && _wcmdln[i - 1] == '\"' && !escapedQuote)
422  {
423  buffer[bufferIndex++] = '\"';
424  ++i;
425  escapedQuote = TRUE;
426  continue;
427  }
428  slashesAdded = 0;
429  escapedQuote = FALSE;
430  inQuotes = !inQuotes;
431  doexpand = inQuotes ? FALSE : expand_wildcards;
432  ++i;
433  continue;
434  }
435 
436  buffer[bufferIndex++] = _wcmdln[i];
437  slashesAdded = 0;
438  escapedQuote = FALSE;
439  ++i;
440  }
441 
442  /* Free the temporary buffer. */
443  free(buffer);
444 
445  *argc = __argc;
446  if (__wargv == NULL)
447  {
448  __wargv = (wchar_t**)malloc(sizeof(wchar_t*));
449  __wargv[0] = 0;
450  }
451  *wargv = __wargv;
452  *wenv = __winitenv;
453 
454  _wpgmptr = malloc(MAX_PATH * sizeof(wchar_t));
455  if (_wpgmptr)
456  {
458  _wpgmptr[0] = '\0';
459  else
460  _wpgmptr[MAX_PATH - 1] = '\0';
461  }
462  else
463  {
464  _wpgmptr = _wcsdup(__wargv[0]);
465  }
466 
468 
469  // if (new_mode) _set_new_mode(*new_mode);
470 }
int __argc
Definition: getargs.c:21
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:607
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
wchar_t * _wpgmptr
Definition: environ.c:29
int wexpand(wchar_t *name, int expand_wildcards)
Definition: getargs.c:67
#define free
Definition: debug_ros.c:5
BOOL WINAPI HeapValidate(HANDLE hHeap, DWORD dwFlags, LPCVOID lpMem)
Definition: heapmem.c:156
GLuint buffer
Definition: glext.h:5915
wchar_t ** __winitenv
Definition: environ.c:25
wchar_t ** __wargv
Definition: getargs.c:20
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLuint bufferIndex
Definition: glext.h:7857
smooth NULL
Definition: ftsmooth.c:416
wchar_t * wcsndup(wchar_t *name, size_t len)
Definition: getargs.c:36
#define GetProcessHeap()
Definition: compat.h:395
#define MAX_PATH
Definition: compat.h:26
GLenum GLsizei len
Definition: glext.h:6722
#define malloc
Definition: debug_ros.c:4
wchar_t * _wcmdln
Definition: environ.c:19
_Check_return_ _CRTIMP wchar_t *__cdecl _wcsdup(_In_z_ const wchar_t *_Str)
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by test__wenviron().

◆ init()

static void init ( void  )
static

Definition at line 54 of file environ.c.

55 {
56  HMODULE hmod = GetModuleHandleA("msvcrt.dll");
57 
58  p__p__environ = (void *)GetProcAddress(hmod, "__p__environ");
59  p__p__wenviron = (void *)GetProcAddress(hmod, "__p__wenviron");
60  p_environ = (void *)GetProcAddress(hmod, "_environ");
61  p_wenviron = (void *)GetProcAddress(hmod, "_wenviron");
62 }
static char *** p_environ
Definition: environ.c:51
static WCHAR ***__cdecl * p__p__wenviron(void)
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:141
static char ***__cdecl * p__p__environ(void)
#define GetProcAddress(x, y)
Definition: compat.h:410
static WCHAR *** p_wenviron
Definition: environ.c:52

Referenced by START_TEST().

◆ p__p__environ()

static char*** __cdecl* p__p__environ ( void  )
static

Referenced by init(), and test__environ().

◆ p__p__wenviron()

static WCHAR*** __cdecl* p__p__wenviron ( void  )
static

Referenced by init(), and test__wenviron().

◆ START_TEST()

START_TEST ( environ  )

Definition at line 225 of file environ.c.

226 {
227  init();
228 
229  /* The environ tests should always be run first, as they assume
230  * that the process has not manipulated the environment. */
231  test__environ();
232  test__wenviron();
234  test_system();
235 }
static void test_environment_manipulation(void)
Definition: environ.c:211
static void init(void)
Definition: environ.c:54
static void test__wenviron(void)
Definition: environ.c:126
static void test_system(void)
Definition: environ.c:64
static void test__environ(void)
Definition: environ.c:73

◆ test__environ()

static void test__environ ( void  )
static

Definition at line 73 of file environ.c.

74 {
75  int argc;
76  char **argv, **envp = NULL;
77  int i, mode = 0;
78 
79  ok( p_environ != NULL, "Expected the pointer to _environ to be non-NULL\n" );
80  if (p_environ)
81  ok( *p_environ != NULL, "Expected _environ to be initialized on startup\n" );
82 
83  if (!p_environ || !*p_environ)
84  {
85  skip( "_environ pointers are not valid\n" );
86  return;
87  }
88 
89  /* Examine the returned pointer from __p__environ(), if available. */
90  if (p__p__environ)
91  {
92  ok( *p__p__environ() == *p_environ,
93  "Expected _environ pointers to be identical\n" );
94  }
95  else
96  win_skip( "__p__environ() is not available\n" );
97 
98  /* Note that msvcrt from Windows versions older than Vista
99  * expects the mode pointer parameter to be valid.*/
100  __getmainargs(&argc, &argv, &envp, 0, &mode);
101 
102  ok( envp != NULL, "Expected initial environment block pointer to be non-NULL\n" );
103  if (!envp)
104  {
105  skip( "Initial environment block pointer is not valid\n" );
106  return;
107  }
108 
109  for (i = 0; ; i++)
110  {
111  if ((*p_environ)[i])
112  {
113  ok( envp[i] != NULL, "Expected environment block pointer element to be non-NULL\n" );
114  ok( !strcmp((*p_environ)[i], envp[i]),
115  "Expected _environ and environment block pointer strings (%s vs. %s) to match\n",
116  (*p_environ)[i], envp[i] );
117  }
118  else
119  {
120  ok( !envp[i], "Expected environment block pointer element to be NULL, got %p\n", envp[i] );
121  break;
122  }
123  }
124 }
static int argc
Definition: ServiceArgs.c:12
static char *** p_environ
Definition: environ.c:51
#define argv
Definition: mplay32.c:18
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
void __cdecl __getmainargs(int *, char ***, char ***, int, int *)
Definition: getargs.c:182
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
GLenum mode
Definition: glext.h:6217
static char ***__cdecl * p__p__environ(void)
#define skip(...)
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define win_skip
Definition: test.h:141

Referenced by START_TEST().

◆ test__wenviron()

static void test__wenviron ( void  )
static

Definition at line 126 of file environ.c.

127 {
128  static const WCHAR cat_eq_dogW[] = {'c','a','t','=','d','o','g',0};
129  static const WCHAR cat_eqW[] = {'c','a','t','=',0};
130 
131  int argc;
132  char **argv, **envp = NULL;
133  WCHAR **wargv, **wenvp = NULL;
134  int i, mode = 0;
135 
136  ok( p_wenviron != NULL, "Expected the pointer to _wenviron to be non-NULL\n" );
137  if (p_wenviron)
138  ok( *p_wenviron == NULL, "Expected _wenviron to be NULL, got %p\n", *p_wenviron );
139  else
140  {
141  win_skip( "Pointer to _wenviron is not valid\n" );
142  return;
143  }
144 
145  /* Examine the returned pointer from __p__wenviron(), if available. */
146  if (p__p__wenviron)
147  {
148  ok( *p__p__wenviron() == NULL,
149  "Expected _wenviron pointers to be NULL\n" );
150  }
151  else
152  win_skip( "__p__wenviron() is not available\n" );
153 
154  /* __getmainargs doesn't initialize _wenviron. */
155  __getmainargs(&argc, &argv, &envp, 0, &mode);
156 
157  ok( *p_wenviron == NULL, "Expected _wenviron to be NULL, got %p\n", *p_wenviron);
158  ok( envp != NULL, "Expected initial environment block pointer to be non-NULL\n" );
159  if (!envp)
160  {
161  skip( "Initial environment block pointer is not valid\n" );
162  return;
163  }
164 
165  /* Neither does calling the non-Unicode environment manipulation functions. */
166  ok( _putenv("cat=dog") == 0, "failed setting cat=dog\n" );
167  ok( *p_wenviron == NULL, "Expected _wenviron to be NULL, got %p\n", *p_wenviron);
168  ok( _putenv("cat=") == 0, "failed deleting cat\n" );
169 
170  /* _wenviron isn't initialized until __wgetmainargs is called or
171  * one of the Unicode environment manipulation functions is called. */
172  ok( _wputenv(cat_eq_dogW) == 0, "failed setting cat=dog\n" );
173  ok( *p_wenviron != NULL, "Expected _wenviron to be non-NULL\n" );
174  ok( _wputenv(cat_eqW) == 0, "failed deleting cat\n" );
175 
176  __wgetmainargs(&argc, &wargv, &wenvp, 0, &mode);
177 
178  ok( *p_wenviron != NULL, "Expected _wenviron to be non-NULL\n" );
179  ok( wenvp != NULL, "Expected initial environment block pointer to be non-NULL\n" );
180  if (!wenvp)
181  {
182  skip( "Initial environment block pointer is not valid\n" );
183  return;
184  }
185 
186  /* Examine the returned pointer from __p__wenviron(),
187  * if available, after _wenviron is initialized. */
188  if (p__p__wenviron)
189  {
190  ok( *p__p__wenviron() == *p_wenviron,
191  "Expected _wenviron pointers to be identical\n" );
192  }
193 
194  for (i = 0; ; i++)
195  {
196  if ((*p_wenviron)[i])
197  {
198  ok( wenvp[i] != NULL, "Expected environment block pointer element to be non-NULL\n" );
199  ok( !winetest_strcmpW((*p_wenviron)[i], wenvp[i]),
200  "Expected _wenviron and environment block pointer strings (%s vs. %s) to match\n",
201  wine_dbgstr_w((*p_wenviron)[i]), wine_dbgstr_w(wenvp[i]) );
202  }
203  else
204  {
205  ok( !wenvp[i], "Expected environment block pointer element to be NULL, got %p\n", wenvp[i] );
206  break;
207  }
208  }
209 }
static int argc
Definition: ServiceArgs.c:12
void __cdecl __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, int *)
Definition: getargs.c:328
#define wine_dbgstr_w
Definition: kernel32.h:34
#define argv
Definition: mplay32.c:18
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
void __cdecl __getmainargs(int *, char ***, char ***, int, int *)
Definition: getargs.c:182
#define ok(value,...)
static WCHAR ***__cdecl * p__p__wenviron(void)
smooth NULL
Definition: ftsmooth.c:416
static int winetest_strcmpW(const WCHAR *str1, const WCHAR *str2)
Definition: test.h:83
__wchar_t WCHAR
Definition: xmlstorage.h:180
_Check_return_ _CRTIMP int __cdecl _wputenv(_In_z_ const wchar_t *_EnvString)
GLenum mode
Definition: glext.h:6217
_Check_return_ _CRTIMP int __cdecl _putenv(_In_z_ const char *_EnvString)
#define skip(...)
static WCHAR *** p_wenviron
Definition: environ.c:52
#define win_skip
Definition: test.h:141

Referenced by START_TEST().

◆ test_environment_manipulation()

static void test_environment_manipulation ( void  )
static

Definition at line 211 of file environ.c.

212 {
213  ok( _putenv("cat=") == 0, "_putenv failed on deletion of nonexistent environment variable\n" );
214  ok( _putenv("cat=dog") == 0, "failed setting cat=dog\n" );
215  ok( strcmp(getenv("cat"), "dog") == 0, "getenv did not return 'dog'\n" );
216  ok( _putenv("cat=") == 0, "failed deleting cat\n" );
217 
218  ok( _putenv("=") == -1, "should not accept '=' as input\n" );
219  ok( _putenv("=dog") == -1, "should not accept '=dog' as input\n" );
220  ok( _putenv(a_very_long_env_string) == 0, "_putenv failed for long environment string\n");
221 
222  ok( getenv("nonexistent") == NULL, "getenv should fail with nonexistent var name\n" );
223 }
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
_Check_return_ _CRTIMP int __cdecl _putenv(_In_z_ const char *_EnvString)
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static const char * a_very_long_env_string
Definition: environ.c:24

Referenced by START_TEST().

◆ test_system()

static void test_system ( void  )
static

Definition at line 64 of file environ.c.

65 {
66  int ret = system(NULL);
67  ok(ret == 1, "Expected system to return 1, got %d\n", ret);
68 
69  ret = system("echo OK");
70  ok(ret == 0, "Expected system to return 0, got %d\n", ret);
71 }
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
int __cdecl system(_In_opt_z_ const char *_Command)
int ret

Referenced by START_TEST().

Variable Documentation

◆ a_very_long_env_string

const char* a_very_long_env_string
static
Initial value:
=
"LIBRARY_PATH="
"C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/mingw32/3.4.2/;"
"C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/;"
"/mingw/lib/gcc/mingw32/3.4.2/;"
"/usr/lib/gcc/mingw32/3.4.2/;"
"C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/lib/mingw32/3.4.2/;"
"C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/lib/;"
"/mingw/mingw32/lib/mingw32/3.4.2/;"
"/mingw/mingw32/lib/;"
"/mingw/lib/mingw32/3.4.2/;"
"/mingw/lib/;"
"C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/mingw32/3.4.2/../../../mingw32/3.4.2/;"
"C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/mingw32/3.4.2/../../../;"
"/mingw/lib/mingw32/3.4.2/;"
"/mingw/lib/;"
"/lib/mingw32/3.4.2/;"
"/lib/;"
"/usr/lib/mingw32/3.4.2/;"
"/usr/lib/"

Definition at line 24 of file environ.c.

Referenced by test_environment_manipulation().

◆ p_environ

char*** p_environ
static

Definition at line 51 of file environ.c.

Referenced by init(), and test__environ().

◆ p_wenviron

WCHAR*** p_wenviron
static

Definition at line 52 of file environ.c.

Referenced by init(), and test__wenviron().