ReactOS  0.4.14-dev-49-gfb4591c
environ.c File Reference
#include <k32.h>
#include <debug.h>
Include dependency graph for environ.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

DWORD WINAPI DECLSPEC_HOTPATCH GetEnvironmentVariableA (IN LPCSTR lpName, IN LPSTR lpBuffer, IN DWORD nSize)
 
DWORD WINAPI DECLSPEC_HOTPATCH GetEnvironmentVariableW (IN LPCWSTR lpName, IN LPWSTR lpBuffer, IN DWORD nSize)
 
BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableA (IN LPCSTR lpName, IN LPCSTR lpValue)
 
BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableW (IN LPCWSTR lpName, IN LPCWSTR lpValue)
 
LPSTR WINAPI GetEnvironmentStringsA (VOID)
 
LPWSTR WINAPI GetEnvironmentStringsW (VOID)
 
BOOL WINAPI FreeEnvironmentStringsA (IN LPSTR EnvironmentStrings)
 
BOOL WINAPI FreeEnvironmentStringsW (IN LPWSTR EnvironmentStrings)
 
DWORD WINAPI ExpandEnvironmentStringsA (IN LPCSTR lpSrc, IN LPSTR lpDst, IN DWORD nSize)
 
DWORD WINAPI ExpandEnvironmentStringsW (IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
 
BOOL WINAPI SetEnvironmentStringsA (IN LPCH NewEnvironment)
 
BOOL WINAPI SetEnvironmentStringsW (IN LPWCH NewEnvironment)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 17 of file environ.c.

Function Documentation

◆ ExpandEnvironmentStringsA()

DWORD WINAPI ExpandEnvironmentStringsA ( IN LPCSTR  lpSrc,
IN LPSTR  lpDst,
IN DWORD  nSize 
)

Definition at line 399 of file environ.c.

402 {
403  ANSI_STRING Source, Dest;
404  UNICODE_STRING SourceU, DestU;
405  PWSTR Buffer;
406  ULONG Result = 0, Length;
407  USHORT UniSize;
409 
410  /* Check if the size is too big to fit */
411  UniSize = UNICODE_STRING_MAX_CHARS - 2;
412  if (nSize <= UniSize) UniSize = (USHORT)nSize;
413 
414  /* Clear the input buffer */
415  if (lpDst) *lpDst = ANSI_NULL;
416 
417  /* Initialize all the strings */
418  RtlInitAnsiString(&Source, lpSrc);
419  RtlInitUnicodeString(&SourceU, NULL);
420  RtlInitUnicodeString(&DestU, NULL);
422  if (!NT_SUCCESS(Status)) goto Quickie;
423 
424  /* If the string fit in, make space for a NULL char */
425  if (UniSize)
426  {
427  UniSize--;
428  }
429  else
430  {
431  /* No input size, so no string size */
432  UniSize = 0;
433  }
434 
435  /* Allocate the value string buffer */
436  Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, UniSize * sizeof(WCHAR));
437  if (!Buffer)
438  {
440  goto Quickie;
441  }
442 
443  /* And initialize its string */
444  RtlInitEmptyUnicodeString(&DestU, Buffer, UniSize * sizeof(WCHAR));
445 
446  /* Query the variable */
447  Length = 0;
448  Status = RtlExpandEnvironmentStrings_U(NULL, &SourceU, &DestU, &Length);
449 
450  /* Check if we didn't have enough space */
452  {
453  /* Fixup the length that the API returned */
454  DestU.MaximumLength = (SHORT)Length;
455 
456  /* Free old Unicode buffer */
457  RtlFreeHeap(RtlGetProcessHeap(), 0, DestU.Buffer);
458 
459  /* Allocate new one */
460  Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length);
461  if (Buffer)
462  {
463  /* Query the variable so we can know its size */
464  DestU.Buffer = Buffer;
465  Status = RtlExpandEnvironmentStrings_U(NULL, &SourceU, &DestU, &Length);
466  if (NT_SUCCESS(Status))
467  {
468  /* Get the ASCII length of the variable, add a byte for NULL */
469  Result = RtlUnicodeStringToAnsiSize(&DestU) + sizeof(ANSI_NULL);
470  }
471  }
472  else
473  {
474  /* Set failure status */
476  DestU.Buffer = NULL;
477  }
478  }
479  else if (NT_SUCCESS(Status))
480  {
481  /* Check if the size is too big to fit */
482  UniSize = UNICODE_STRING_MAX_BYTES - 1;
483  if (nSize <= UniSize) UniSize = (USHORT)nSize;
484 
485  /* Check the size */
487  if (Result <= UniSize)
488  {
489  /* Convert the string */
490  RtlInitEmptyAnsiString(&Dest, lpDst, UniSize);
491  Status = RtlUnicodeStringToAnsiString(&Dest, &DestU, FALSE);
492 
493  /* Write a NULL-char in case of failure only */
494  if (!NT_SUCCESS(Status)) *lpDst = ANSI_NULL;
495  }
496  }
497 Quickie:
498  /* Free the strings */
499  RtlFreeUnicodeString(&SourceU);
500  if (DestU.Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, DestU.Buffer);
501 
502  /* Check if we succeeded */
503  if (!NT_SUCCESS(Status))
504  {
505  /* We did not, clear the result and set the error code */
507  Result = 0;
508  }
509 
510  /* Return the result */
511  return Result;
512 }
#define TRUE
Definition: types.h:120
NTSYSAPI DWORD WINAPI RtlUnicodeStringToAnsiSize(const UNICODE_STRING *)
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:54
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2024
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define UNICODE_STRING_MAX_BYTES
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define ANSI_NULL
short SHORT
Definition: pedump.c:59
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
Definition: bufpool.h:45
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
NTSYSAPI NTSTATUS WINAPI RtlExpandEnvironmentStrings_U(PCWSTR, const UNICODE_STRING *, UNICODE_STRING *, ULONG *)
#define UNICODE_STRING_MAX_CHARS
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Status
Definition: gdiplustypes.h:24
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by create_test_entries(), DoEnvironmentSubstA(), HCR_RegGetIconA(), install_from_registered_dir(), RegGetValueA(), SHQueryValueExA(), test_appsearch_reglocator(), test_DoEnvironmentSubst(), test_ExpandEnvironmentStringsA(), test_get_profiles_dir(), test_GetVolumePathNameA(), and WsNpInitialize().

◆ ExpandEnvironmentStringsW()

DWORD WINAPI ExpandEnvironmentStringsW ( IN LPCWSTR  lpSrc,
IN LPWSTR  lpDst,
IN DWORD  nSize 
)

Definition at line 519 of file environ.c.

522 {
525  USHORT UniSize;
526 
527  UniSize = min(nSize, UNICODE_STRING_MAX_CHARS - 2);
528 
530  RtlInitEmptyUnicodeString(&Destination, lpDst, UniSize * sizeof(WCHAR));
531 
533  &Source,
534  &Destination,
535  &nSize);
537  {
538  return nSize / sizeof(WCHAR);
539  }
540 
542  return 0;
543 }
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2024
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
NTSYSAPI NTSTATUS WINAPI RtlExpandEnvironmentStrings_U(PCWSTR, const UNICODE_STRING *, UNICODE_STRING *, ULONG *)
#define UNICODE_STRING_MAX_CHARS
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2891
Status
Definition: gdiplustypes.h:24
unsigned short USHORT
Definition: pedump.c:61
#define min(a, b)
Definition: monoChain.cc:55
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by _SHExpandEnvironmentStrings(), _tryLoadProvider(), ACTION_AppSearchReg(), ACTION_ConvertRegValue(), AddNewTopicEx(), AddUserProfile(), AppendSystemPostfix(), BackupIniFile(), BuildCommandLine(), Control_LoadApplet(), CClassNode::ConvertResourceDescriptorToString(), CopySystemProfile(), CreateShortcut(), CreateTempDir(), CreateUserProfileExW(), CryptAcquireContextW(), DoEnvironmentSubstW(), DoFileTypeIconLocation(), DoLoadIcons(), EditTypeDlg_OnChangeIcon(), expand_environment(), FileQueryFiles(), get_object_dll_path(), GetAllUsersProfileDirectoryW(), GetDefaultUserProfileDirectoryW(), GetDesktopPath(), CQueryAssociations::GetExecutable(), GetExpandedFilePathName(), getIconLocationForDrive(), getIconLocationForFolder(), GetLayoutName(), GetProfilesDirectoryW(), GetProgramsPath(), GetServiceMainFunctions(), GetUserProfileDirectoryW(), HCR_RegGetIconW(), ICO_ExtractIconExW(), init_envvars_map(), init_filedlg_infoW(), CLayerUIPropPage::InitFile(), InitializeProfiles(), InitializeProgramFilesDir(), CFileDefExt::InitOpensWithField(), LaunchProcess(), LayoutList_Create(), load_mapi_provider(), LoadIniFile(), LoadLogFile(), MyFileExists(), CNewMenu::NewItemByCommand(), OpenNetworkDatabase(), PickIconDlg(), PlayLogonSoundThread(), ProcessUnattendSection(), query_reg_path(), RegGetValueW(), CControlPanelEnum::RegisterRegistryCPanelApps(), RegLoadMUIStringW(), runCmd(), RunCommand(), RunDlgProc(), RunSetupThreadProc(), ScmConvertToBootPathName(), ScmReadString(), SetUserWallpaper(), SHELL_execute(), SHQueryValueExW(), SockLoadHelperDll(), StartProcess(), test_checklinkpath(), test_DoEnvironmentSubst(), test_iconlocation(), Test_ProtectedFiles(), variant_from_registry_value(), ViewTree_LoadTree(), WlxActivateUserShell(), WriteIniFile(), and WshShell3_ExpandEnvironmentStrings().

◆ FreeEnvironmentStringsA()

BOOL WINAPI FreeEnvironmentStringsA ( IN LPSTR  EnvironmentStrings)

Definition at line 379 of file environ.c.

380 {
381  return RtlFreeHeap(RtlGetProcessHeap(), 0, EnvironmentStrings);
382 }
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606

Referenced by BlockEnvToEnvironA(), doChild(), and test_Environment().

◆ FreeEnvironmentStringsW()

BOOL WINAPI FreeEnvironmentStringsW ( IN LPWSTR  EnvironmentStrings)

Definition at line 389 of file environ.c.

390 {
391  return RtlFreeHeap(RtlGetProcessHeap(), 0, EnvironmentStrings);
392 }
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606

Referenced by BlockEnvToEnvironW(), doChild(), service_main(), SHELL_BuildEnvW(), and Test_ApphelpCheckRunApp().

◆ GetEnvironmentStringsA()

LPSTR WINAPI GetEnvironmentStringsA ( VOID  )

Definition at line 293 of file environ.c.

294 {
295  ULONG Length, Size;
298  PCHAR Buffer = NULL;
299 
301  p = Environment = NtCurrentPeb()->ProcessParameters->Environment;
302 
303  do
304  {
305  p += wcslen(p) + 1;
306  } while (*p);
307 
308  Length = p - Environment + 1;
309 
311  if (NT_SUCCESS(Status))
312  {
313  Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Size);
314  if (Buffer)
315  {
317  if (!NT_SUCCESS(Status))
318  {
319  RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
320  Buffer = NULL;
321 
323  }
324  }
325  else
326  {
328  }
329  }
330  else
331  {
333  }
334 
336  return Buffer;
337 }
signed char * PCHAR
Definition: retypes.h:7
PVOID PVOID PWCHAR PVOID Environment
Definition: env.c:45
NTSYSAPI NTSTATUS NTAPI RtlUnicodeToMultiByteSize(PULONG MbSize, PCWCH UnicodeString, ULONG UnicodeSize)
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
VOID NTAPI RtlReleasePebLock(VOID)
Definition: libsupp.c:82
uint16_t * PWCHAR
Definition: typedefs.h:54
NTSYSAPI NTSTATUS NTAPI RtlUnicodeToOemN(PCHAR OemString, ULONG OemSize, PULONG ResultSize, PCWCH UnicodeString, ULONG UnicodeSize)
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
#define NtCurrentPeb()
Definition: FLS.c:20
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
VOID NTAPI RtlAcquirePebLock(VOID)
Definition: libsupp.c:72
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by BlockEnvToEnvironA(), doChild(), and test_Environment().

◆ GetEnvironmentStringsW()

LPWSTR WINAPI GetEnvironmentStringsW ( VOID  )

Definition at line 344 of file environ.c.

345 {
347  ULONG Length;
348 
350 
351  p = Environment = NtCurrentPeb()->ProcessParameters->Environment;
352 
353  do
354  {
355  p += wcslen(p) + 1;
356  } while (*p);
357 
358  Length = p - Environment + 1;
359 
360  p = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length * sizeof(WCHAR));
361  if (p)
362  {
363  RtlCopyMemory(p, Environment, Length * sizeof(WCHAR));
364  }
365  else
366  {
368  }
369 
371  return p;
372 }
PVOID PVOID PWCHAR PVOID Environment
Definition: env.c:45
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
VOID NTAPI RtlReleasePebLock(VOID)
Definition: libsupp.c:82
uint16_t * PWCHAR
Definition: typedefs.h:54
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define NtCurrentPeb()
Definition: FLS.c:20
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
VOID NTAPI RtlAcquirePebLock(VOID)
Definition: libsupp.c:72
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by BlockEnvToEnvironW(), doChild(), service_main(), SHELL_BuildEnvW(), and Test_ApphelpCheckRunApp().

◆ GetEnvironmentVariableA()

DWORD WINAPI DECLSPEC_HOTPATCH GetEnvironmentVariableA ( IN LPCSTR  lpName,
IN LPSTR  lpBuffer,
IN DWORD  nSize 
)

Definition at line 28 of file environ.c.

31 {
32  ANSI_STRING VarName, VarValue;
33  UNICODE_STRING VarNameU, VarValueU;
34  PWSTR Buffer;
35  ULONG Result = 0;
36  USHORT UniSize;
38 
39  /* Initialize all the strings */
40  RtlInitAnsiString(&VarName, lpName);
41  RtlInitUnicodeString(&VarNameU, NULL);
42  RtlInitUnicodeString(&VarValueU, NULL);
43  Status = RtlAnsiStringToUnicodeString(&VarNameU, &VarName, TRUE);
44  if (!NT_SUCCESS(Status)) goto Quickie;
45 
46  /* Check if the size is too big to fit */
47  UniSize = UNICODE_STRING_MAX_CHARS - 2;
48  if (nSize <= UniSize)
49  {
50  /* It fits, but was there a string at all? */
51  if (nSize)
52  {
53  /* Keep the given size, minus a NULL-char */
54  UniSize = (USHORT)(nSize - 1);
55  }
56  else
57  {
58  /* No size */
59  UniSize = 0;
60  }
61  }
62  else
63  {
64  /* String is too big, so we need to return a NULL char as well */
65  UniSize--;
66  }
67 
68  /* Allocate the value string buffer */
69  Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, UniSize * sizeof(WCHAR));
70  if (!Buffer)
71  {
73  goto Quickie;
74  }
75 
76  /* And initialize its string */
77  RtlInitEmptyUnicodeString(&VarValueU, Buffer, UniSize * sizeof(WCHAR));
78 
79  /* Acquire the PEB lock since we'll be querying variables now */
81 
82  /* Query the variable */
83  Status = RtlQueryEnvironmentVariable_U(NULL, &VarNameU, &VarValueU);
85 
86  /* Check if we didn't have enough space */
88  {
89  /* Fixup the length that the API returned */
90  VarValueU.MaximumLength = VarValueU.Length + sizeof(UNICODE_NULL);
91 
92  /* Free old Unicode buffer */
93  RtlFreeHeap(RtlGetProcessHeap(), 0, VarValueU.Buffer);
94 
95  /* Allocate new one */
96  Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, VarValueU.MaximumLength);
97  if (Buffer)
98  {
99  /* Query the variable so we can know its size */
100  VarValueU.Buffer = Buffer;
101  Status = RtlQueryEnvironmentVariable_U(NULL, &VarNameU, &VarValueU);
102  if (NT_SUCCESS(Status))
103  {
104  /* Get the ASCII length of the variable */
105  Result = RtlUnicodeStringToAnsiSize(&VarValueU);
106  }
107  }
108  else
109  {
110  /* Set failure status */
112  VarValueU.Buffer = NULL;
113  }
114  }
115  else if (NT_SUCCESS(Status))
116  {
117  /* Check if the size is too big to fit */
118  UniSize = UNICODE_STRING_MAX_BYTES - 1;
119  if (nSize <= UniSize) UniSize = (USHORT)nSize;
120 
121  /* Check the size */
122  Result = RtlUnicodeStringToAnsiSize(&VarValueU);
123  if (Result <= UniSize)
124  {
125  /* Convert the string */
126  RtlInitEmptyAnsiString(&VarValue, lpBuffer, UniSize);
127  Status = RtlUnicodeStringToAnsiString(&VarValue, &VarValueU, FALSE);
128  if (NT_SUCCESS(Status))
129  {
130  /* NULL-terminate and set the final length */
131  lpBuffer[VarValue.Length] = ANSI_NULL;
132  Result = VarValue.Length;
133  }
134  }
135  }
136 
137  /* Release the lock */
139 
140 Quickie:
141  /* Free the strings */
142  RtlFreeUnicodeString(&VarNameU);
143  if (VarValueU.Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, VarValueU.Buffer);
144 
145  /* Check if we succeeded */
146  if (!NT_SUCCESS(Status))
147  {
148  /* We did not, clear the result and set the error code */
150  Result = 0;
151  }
152 
153  /* Return the result */
154  return Result;
155 }
#define TRUE
Definition: types.h:120
NTSYSAPI DWORD WINAPI RtlUnicodeStringToAnsiSize(const UNICODE_STRING *)
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:54
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2024
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
_In_ LPCSTR lpName
Definition: winbase.h:2729
VOID NTAPI RtlReleasePebLock(VOID)
Definition: libsupp.c:82
#define UNICODE_STRING_MAX_BYTES
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define UNICODE_NULL
#define ANSI_NULL
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
NTSYSAPI NTSTATUS NTAPI RtlQueryEnvironmentVariable_U(_In_opt_ PWSTR Environment, _In_ PCUNICODE_STRING Name, _Out_ PUNICODE_STRING Value)
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
Definition: bufpool.h:45
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define UNICODE_STRING_MAX_CHARS
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
Status
Definition: gdiplustypes.h:24
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
VOID NTAPI RtlAcquirePebLock(VOID)
Definition: libsupp.c:72
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by test_GetSetEnvironmentVariableA(), and test_Predefined().

◆ GetEnvironmentVariableW()

DWORD WINAPI DECLSPEC_HOTPATCH GetEnvironmentVariableW ( IN LPCWSTR  lpName,
IN LPWSTR  lpBuffer,
IN DWORD  nSize 
)

Definition at line 163 of file environ.c.

166 {
167  UNICODE_STRING VarName, VarValue;
169  USHORT UniSize;
170 
171  if (nSize <= (UNICODE_STRING_MAX_CHARS - 1))
172  {
173  if (nSize)
174  {
175  UniSize = (USHORT)nSize * sizeof(WCHAR) - sizeof(UNICODE_NULL);
176  }
177  else
178  {
179  UniSize = 0;
180  }
181  }
182  else
183  {
184  UniSize = UNICODE_STRING_MAX_BYTES - sizeof(UNICODE_NULL);
185  }
186 
187  Status = RtlInitUnicodeStringEx(&VarName, lpName);
188  if (!NT_SUCCESS(Status))
189  {
191  return 0;
192  }
193 
194  RtlInitEmptyUnicodeString(&VarValue, lpBuffer, UniSize);
195 
196  Status = RtlQueryEnvironmentVariable_U(NULL, &VarName, &VarValue);
197  if (!NT_SUCCESS(Status))
198  {
200  {
201  return (VarValue.Length / sizeof(WCHAR)) + sizeof(ANSI_NULL);
202  }
204  return 0;
205  }
206 
207  lpBuffer[VarValue.Length / sizeof(WCHAR)] = UNICODE_NULL;
208 
209  return (VarValue.Length / sizeof(WCHAR));
210 }
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2024
LONG NTSTATUS
Definition: precomp.h:26
_In_ LPCSTR lpName
Definition: winbase.h:2729
#define UNICODE_STRING_MAX_BYTES
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
#define UNICODE_NULL
#define ANSI_NULL
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
NTSYSAPI NTSTATUS NTAPI RtlQueryEnvironmentVariable_U(_In_opt_ PWSTR Environment, _In_ PCUNICODE_STRING Name, _Out_ PUNICODE_STRING Value)
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define UNICODE_STRING_MAX_CHARS
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS WINAPI RtlInitUnicodeStringEx(PUNICODE_STRING, PCWSTR)

Referenced by test_GetSetEnvironmentVariableW().

◆ SetEnvironmentStringsA()

BOOL WINAPI SetEnvironmentStringsA ( IN LPCH  NewEnvironment)

Definition at line 550 of file environ.c.

551 {
552  STUB;
553  return FALSE;
554 }
#define STUB
Definition: kernel32.h:27

◆ SetEnvironmentStringsW()

BOOL WINAPI SetEnvironmentStringsW ( IN LPWCH  NewEnvironment)

Definition at line 561 of file environ.c.

562 {
563  STUB;
564  return FALSE;
565 }
#define STUB
Definition: kernel32.h:27

◆ SetEnvironmentVariableA()

BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableA ( IN LPCSTR  lpName,
IN LPCSTR  lpValue 
)

Definition at line 218 of file environ.c.

220 {
221  ANSI_STRING VarName, VarValue;
222  UNICODE_STRING VarNameU, VarValueU;
224 
225  RtlInitAnsiString(&VarName, (LPSTR)lpName);
226  Status = RtlAnsiStringToUnicodeString(&VarNameU, &VarName, TRUE);
227  if (NT_SUCCESS(Status))
228  {
229  if (lpValue)
230  {
231  RtlInitAnsiString(&VarValue, (LPSTR)lpValue);
232  Status = RtlAnsiStringToUnicodeString(&VarValueU, &VarValue, TRUE);
233  if (NT_SUCCESS(Status))
234  {
235  Status = RtlSetEnvironmentVariable(NULL, &VarNameU, &VarValueU);
236  RtlFreeUnicodeString(&VarValueU);
237  }
238  }
239  else
240  {
241  Status = RtlSetEnvironmentVariable(NULL, &VarNameU, NULL);
242  }
243 
244  RtlFreeUnicodeString(&VarNameU);
245 
246  if (NT_SUCCESS(Status)) return TRUE;
247  }
248 
250  return FALSE;
251 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ LPCSTR lpName
Definition: winbase.h:2729
char * LPSTR
Definition: xmlstorage.h:182
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI NTSTATUS NTAPI RtlSetEnvironmentVariable(_In_z_ PWSTR *Environment, _In_ PUNICODE_STRING Name, _In_ PUNICODE_STRING Value)
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)

Referenced by create_environ(), create_test_entries(), init_test(), silence_debug_output(), START_TEST(), Test_ApphelpCheckRunApp(), test_create_env(), test_ExpandEnvironmentStringsA(), test_FileTimeToLocalFileTime(), test_fileurls(), test_formatrecord(), test_formatrecord2(), test_formatrecord_tables(), Test_GetMatchingExe(), test_GetSetEnvironmentVariableA(), test_GetTempPath(), test_GetTimeZoneInformation(), test_GetVolumeInformationA(), test_GetVolumePathNameA(), test_Installer_RegistryValue(), test_mode_generic(), test_NeedCurrentDirectoryForExePathA(), test_NeedCurrentDirectoryForExePathW(), test_PathUnExpandEnvStrings(), Test_repeatlayer(), and test_urls().

◆ SetEnvironmentVariableW()

BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableW ( IN LPCWSTR  lpName,
IN LPCWSTR  lpValue 
)

Definition at line 259 of file environ.c.

261 {
262  UNICODE_STRING VarName, VarValue;
264 
265  Status = RtlInitUnicodeStringEx(&VarName, lpName);
266  if (NT_SUCCESS(Status))
267  {
268  if (lpValue)
269  {
270  Status = RtlInitUnicodeStringEx(&VarValue, lpValue);
271  if (NT_SUCCESS(Status))
272  {
273  Status = RtlSetEnvironmentVariable(NULL, &VarName, &VarValue);
274  }
275  }
276  else
277  {
279  }
280 
281  if (NT_SUCCESS(Status)) return TRUE;
282  }
283 
285  return FALSE;
286 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ LPCSTR lpName
Definition: winbase.h:2729
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI NTSTATUS NTAPI RtlSetEnvironmentVariable(_In_z_ PWSTR *Environment, _In_ PUNICODE_STRING Name, _In_ PUNICODE_STRING Value)
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS WINAPI RtlInitUnicodeStringEx(PUNICODE_STRING, PCWSTR)

Referenced by _tchdir(), CreateStandardProfile(), DoEntry(), RegenerateUserEnvironment(), set_environment(), SetEnv(), test_GetSetEnvironmentVariableW(), TestMain_PathResolve(), and TestShellLink().