ReactOS  0.4.15-dev-3187-ge372f2b
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 void(* p_get_environ )(char ***)
 
static void(* p_get_wenviron )(WCHAR ***)
 
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
char * _acmdln
Definition: environ.c:18
char ** __argv
Definition: getargs.c:18
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define TRUE
Definition: types.h:120
#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:539
#define FALSE
Definition: types.h:117
GLuint bufferIndex
Definition: glext.h:7857
#define GetProcessHeap()
Definition: compat.h:595
#define MAX_PATH
Definition: compat.h:34
int aexpand(char *name, int expand_wildcards)
Definition: getargs.c:132
GLenum GLsizei len
Definition: glext.h:6722
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
char * strndup(char const *name, size_t len)
Definition: getargs.c:25
char * _pgmptr
Definition: environ.c:27
#define NULL
Definition: types.h:112
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:170
#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:600
static int argc
Definition: ServiceArgs.c:12
wchar_t * _wpgmptr
Definition: environ.c:29
#define TRUE
Definition: types.h:120
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
#define FALSE
Definition: types.h:117
GLuint bufferIndex
Definition: glext.h:7857
wchar_t * wcsndup(wchar_t *name, size_t len)
Definition: getargs.c:36
#define GetProcessHeap()
Definition: compat.h:595
#define MAX_PATH
Definition: compat.h:34
GLenum GLsizei len
Definition: glext.h:6722
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
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#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)

Referenced by test__wenviron().

◆ init()

static void init ( void  )
static

Definition at line 56 of file environ.c.

57 {
58  HMODULE hmod = GetModuleHandleA("msvcrt.dll");
59 
60  p__p__environ = (void *)GetProcAddress(hmod, "__p__environ");
61  p__p__wenviron = (void *)GetProcAddress(hmod, "__p__wenviron");
62  p_environ = (void *)GetProcAddress(hmod, "_environ");
63  p_wenviron = (void *)GetProcAddress(hmod, "_wenviron");
64  p_get_environ = (void *)GetProcAddress(hmod, "_get_environ");
65  p_get_wenviron = (void *)GetProcAddress(hmod, "_get_wenviron");
66 }
static char *** p_environ
Definition: environ.c:53
static void(* p_get_wenviron)(WCHAR ***)
Definition: environ.c:51
static WCHAR ***__cdecl * p__p__wenviron(void)
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:141
static char ***__cdecl * p__p__environ(void)
static void(* p_get_environ)(char ***)
Definition: environ.c:50
#define GetProcAddress(x, y)
Definition: compat.h:612
static WCHAR *** p_wenviron
Definition: environ.c:54

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 257 of file environ.c.

258 {
259  init();
260 
261  /* The environ tests should always be run first, as they assume
262  * that the process has not manipulated the environment. */
263  test__environ();
264  test__wenviron();
266  test_system();
267 }
static void test_environment_manipulation(void)
Definition: environ.c:243
static void init(void)
Definition: environ.c:56
static void test__wenviron(void)
Definition: environ.c:140
static void test_system(void)
Definition: environ.c:68
static void test__environ(void)
Definition: environ.c:77

◆ test__environ()

static void test__environ ( void  )
static

Definition at line 77 of file environ.c.

78 {
79  int argc;
80  char **argv, **envp = NULL;
81  int i, mode = 0;
82 
83  ok( p_environ != NULL, "Expected the pointer to _environ to be non-NULL\n" );
84  if (p_environ)
85  ok( *p_environ != NULL, "Expected _environ to be initialized on startup\n" );
86 
87  if (!p_environ || !*p_environ)
88  {
89  skip( "_environ pointers are not valid\n" );
90  return;
91  }
92 
93  /* Examine the returned pointer from __p__environ(), if available. */
94  if (p__p__environ)
95  {
96  ok( *p__p__environ() == *p_environ,
97  "Expected _environ pointers to be identical\n" );
98  }
99  else
100  skip( "__p__environ() is not available\n" );
101 
102  if (p_get_environ)
103  {
104  char **retptr;
105  p_get_environ(&retptr);
106  ok( retptr == *p_environ,
107  "Expected _environ pointers to be identical\n" );
108  }
109  else
110  win_skip( "_get_environ() is not available\n" );
111 
112  /* Note that msvcrt from Windows versions older than Vista
113  * expects the mode pointer parameter to be valid.*/
114  __getmainargs(&argc, &argv, &envp, 0, &mode);
115 
116  ok( envp != NULL, "Expected initial environment block pointer to be non-NULL\n" );
117  if (!envp)
118  {
119  skip( "Initial environment block pointer is not valid\n" );
120  return;
121  }
122 
123  for (i = 0; ; i++)
124  {
125  if ((*p_environ)[i])
126  {
127  ok( envp[i] != NULL, "Expected environment block pointer element to be non-NULL\n" );
128  ok( !strcmp((*p_environ)[i], envp[i]),
129  "Expected _environ and environment block pointer strings (%s vs. %s) to match\n",
130  (*p_environ)[i], envp[i] );
131  }
132  else
133  {
134  ok( !envp[i], "Expected environment block pointer element to be NULL, got %p\n", envp[i] );
135  break;
136  }
137  }
138 }
static int argc
Definition: ServiceArgs.c:12
static char *** p_environ
Definition: environ.c:53
#define argv
Definition: mplay32.c:18
void __cdecl __getmainargs(int *, char ***, char ***, int, int *)
Definition: getargs.c:182
GLenum mode
Definition: glext.h:6217
static char ***__cdecl * p__p__environ(void)
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
#define ok(value,...)
Definition: atltest.h:57
static void(* p_get_environ)(char ***)
Definition: environ.c:50
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define win_skip
Definition: test.h:151

Referenced by START_TEST().

◆ test__wenviron()

static void test__wenviron ( void  )
static

Definition at line 140 of file environ.c.

141 {
142  static const WCHAR cat_eq_dogW[] = {'c','a','t','=','d','o','g',0};
143  static const WCHAR cat_eqW[] = {'c','a','t','=',0};
144 
145  int argc;
146  char **argv, **envp = NULL;
147  WCHAR **wargv, **wenvp = NULL;
148  int i, mode = 0;
149 
150  ok( p_wenviron != NULL, "Expected the pointer to _wenviron to be non-NULL\n" );
151  if (p_wenviron)
152  ok( *p_wenviron == NULL, "Expected _wenviron to be NULL, got %p\n", *p_wenviron );
153  else
154  {
155  win_skip( "Pointer to _wenviron is not valid\n" );
156  return;
157  }
158 
159  /* Examine the returned pointer from __p__wenviron(), if available. */
160  if (p__p__wenviron)
161  {
162  ok( *p__p__wenviron() == NULL,
163  "Expected _wenviron pointers to be NULL\n" );
164  }
165  else
166  skip( "__p__wenviron() is not available\n" );
167 
168  if (p_get_wenviron)
169  {
170  WCHAR **retptr;
171  p_get_wenviron(&retptr);
172  ok( retptr == NULL,
173  "Expected _wenviron pointers to be NULL\n" );
174  }
175  else
176  win_skip( "_get_wenviron() is not available\n" );
177 
178  /* __getmainargs doesn't initialize _wenviron. */
179  __getmainargs(&argc, &argv, &envp, 0, &mode);
180 
181  ok( *p_wenviron == NULL, "Expected _wenviron to be NULL, got %p\n", *p_wenviron);
182  ok( envp != NULL, "Expected initial environment block pointer to be non-NULL\n" );
183  if (!envp)
184  {
185  skip( "Initial environment block pointer is not valid\n" );
186  return;
187  }
188 
189  /* Neither does calling the non-Unicode environment manipulation functions. */
190  ok( _putenv("cat=dog") == 0, "failed setting cat=dog\n" );
191  ok( *p_wenviron == NULL, "Expected _wenviron to be NULL, got %p\n", *p_wenviron);
192  ok( _putenv("cat=") == 0, "failed deleting cat\n" );
193 
194  /* _wenviron isn't initialized until __wgetmainargs is called or
195  * one of the Unicode environment manipulation functions is called. */
196  ok( _wputenv(cat_eq_dogW) == 0, "failed setting cat=dog\n" );
197  ok( *p_wenviron != NULL, "Expected _wenviron to be non-NULL\n" );
198  ok( _wputenv(cat_eqW) == 0, "failed deleting cat\n" );
199 
200  __wgetmainargs(&argc, &wargv, &wenvp, 0, &mode);
201 
202  ok( *p_wenviron != NULL, "Expected _wenviron to be non-NULL\n" );
203  ok( wenvp != NULL, "Expected initial environment block pointer to be non-NULL\n" );
204  if (!wenvp)
205  {
206  skip( "Initial environment block pointer is not valid\n" );
207  return;
208  }
209 
210  /* Examine the returned pointer from __p__wenviron(),
211  * if available, after _wenviron is initialized. */
212  if (p__p__wenviron)
213  {
214  ok( *p__p__wenviron() == *p_wenviron,
215  "Expected _wenviron pointers to be identical\n" );
216  }
217 
218  if (p_get_wenviron)
219  {
220  WCHAR **retptr;
221  p_get_wenviron(&retptr);
222  ok( retptr == *p_wenviron,
223  "Expected _wenviron pointers to be identical\n" );
224  }
225 
226  for (i = 0; ; i++)
227  {
228  if ((*p_wenviron)[i])
229  {
230  ok( wenvp[i] != NULL, "Expected environment block pointer element to be non-NULL\n" );
231  ok( !winetest_strcmpW((*p_wenviron)[i], wenvp[i]),
232  "Expected _wenviron and environment block pointer strings (%s vs. %s) to match\n",
233  wine_dbgstr_w((*p_wenviron)[i]), wine_dbgstr_w(wenvp[i]) );
234  }
235  else
236  {
237  ok( !wenvp[i], "Expected environment block pointer element to be NULL, got %p\n", wenvp[i] );
238  break;
239  }
240  }
241 }
static int argc
Definition: ServiceArgs.c:12
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
void __cdecl __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, int *)
Definition: getargs.c:328
#define argv
Definition: mplay32.c:18
static void(* p_get_wenviron)(WCHAR ***)
Definition: environ.c:51
void __cdecl __getmainargs(int *, char ***, char ***, int, int *)
Definition: getargs.c:182
static WCHAR ***__cdecl * p__p__wenviron(void)
static int winetest_strcmpW(const WCHAR *str1, const WCHAR *str2)
Definition: test.h:91
__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)
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
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
static WCHAR *** p_wenviron
Definition: environ.c:54
#define win_skip
Definition: test.h:151

Referenced by START_TEST().

◆ test_environment_manipulation()

static void test_environment_manipulation ( void  )
static

Definition at line 243 of file environ.c.

244 {
245  ok( _putenv("cat=") == 0, "_putenv failed on deletion of nonexistent environment variable\n" );
246  ok( _putenv("cat=dog") == 0, "failed setting cat=dog\n" );
247  ok( strcmp(getenv("cat"), "dog") == 0, "getenv did not return 'dog'\n" );
248  ok( _putenv("cat=") == 0, "failed deleting cat\n" );
249 
250  ok( _putenv("=") == -1, "should not accept '=' as input\n" );
251  ok( _putenv("=dog") == -1, "should not accept '=dog' as input\n" );
252  ok( _putenv(a_very_long_env_string) == 0, "_putenv failed for long environment string\n");
253 
254  ok( getenv("nonexistent") == NULL, "getenv should fail with nonexistent var name\n" );
255 }
_Check_return_ _CRTIMP int __cdecl _putenv(_In_z_ const char *_EnvString)
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
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 68 of file environ.c.

69 {
70  int ret = system(NULL);
71  ok(ret == 1, "Expected system to return 1, got %d\n", ret);
72 
73  ret = system("echo OK");
74  ok(ret == 0, "Expected system to return 0, got %d\n", ret);
75 }
int __cdecl system(_In_opt_z_ const char *_Command)
int ret
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112

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 53 of file environ.c.

Referenced by init(), and test__environ().

◆ p_get_environ

void(* p_get_environ) (char ***)
static

Definition at line 50 of file environ.c.

Referenced by init(), and test__environ().

◆ p_get_wenviron

void(* p_get_wenviron) (WCHAR ***)
static

Definition at line 51 of file environ.c.

Referenced by init(), and test__wenviron().

◆ p_wenviron

WCHAR*** p_wenviron
static

Definition at line 54 of file environ.c.

Referenced by init(), and test__wenviron().