* @implemented
*/
DWORD
-STDCALL
+WINAPI
GetEnvironmentVariableA (
LPCSTR lpName,
LPSTR lpBuffer,
* @implemented
*/
DWORD
-STDCALL
+WINAPI
GetEnvironmentVariableW (
LPCWSTR lpName,
LPWSTR lpBuffer,
lpName);
VarValue.Length = 0;
- VarValue.MaximumLength = (USHORT)(nSize != 0 ? (nSize - 1) * sizeof(WCHAR) : 0);
+ VarValue.MaximumLength = (USHORT) (nSize ? nSize - 1 : 0) * sizeof(WCHAR);
VarValue.Buffer = lpBuffer;
Status = RtlQueryEnvironmentVariable_U (NULL,
&VarValue);
if (!NT_SUCCESS(Status))
{
- SetLastErrorByStatus (Status);
if (Status == STATUS_BUFFER_TOO_SMALL)
{
return (VarValue.Length / sizeof(WCHAR)) + 1;
}
else
{
+ SetLastErrorByStatus (Status);
return 0;
}
}
{
/* make sure the string is NULL-terminated! RtlQueryEnvironmentVariable_U
only terminates it if MaximumLength < Length */
- VarValue.Buffer[VarValue.Length / sizeof(WCHAR)] = L'\0';
+ lpBuffer[VarValue.Length / sizeof(WCHAR)] = L'\0';
}
return (VarValue.Length / sizeof(WCHAR));
* @implemented
*/
BOOL
-STDCALL
+WINAPI
SetEnvironmentVariableA (
LPCSTR lpName,
LPCSTR lpValue
&VarName,
TRUE);
- RtlInitAnsiString (&VarValue,
- (LPSTR)lpValue);
- RtlAnsiStringToUnicodeString (&VarValueU,
- &VarValue,
- TRUE);
+ if (lpValue)
+ {
+ RtlInitAnsiString (&VarValue,
+ (LPSTR)lpValue);
+ RtlAnsiStringToUnicodeString (&VarValueU,
+ &VarValue,
+ TRUE);
- Status = RtlSetEnvironmentVariable (NULL,
- &VarNameU,
- &VarValueU);
+ Status = RtlSetEnvironmentVariable (NULL,
+ &VarNameU,
+ &VarValueU);
+ RtlFreeUnicodeString (&VarValueU);
+ }
+ else
+ {
+ Status = RtlSetEnvironmentVariable (NULL,
+ &VarNameU,
+ NULL);
+ }
RtlFreeUnicodeString (&VarNameU);
- RtlFreeUnicodeString (&VarValueU);
if (!NT_SUCCESS(Status))
{
* @implemented
*/
BOOL
-STDCALL
+WINAPI
SetEnvironmentVariableW (
LPCWSTR lpName,
LPCWSTR lpValue
Status = RtlSetEnvironmentVariable (NULL,
&VarName,
&VarValue);
+
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus (Status);
* @implemented
*/
LPSTR
-STDCALL
+WINAPI
GetEnvironmentStringsA (
VOID
)
* @implemented
*/
LPWSTR
-STDCALL
+WINAPI
GetEnvironmentStringsW (
VOID
)
* @implemented
*/
BOOL
-STDCALL
+WINAPI
FreeEnvironmentStringsA (
LPSTR EnvironmentStrings
)
* @implemented
*/
BOOL
-STDCALL
+WINAPI
FreeEnvironmentStringsW (
LPWSTR EnvironmentStrings
)
{
- (void)EnvironmentStrings;
return TRUE;
}
* @implemented
*/
DWORD
-STDCALL
+WINAPI
ExpandEnvironmentStringsA (
LPCSTR lpSrc,
LPSTR lpDst,
return 0;
}
+ /* make sure we don't overflow the maximum ANSI_STRING size */
+ if (nSize > 0x7fff)
+ nSize = 0x7fff;
+
Destination.Length = 0;
Destination.MaximumLength = (USHORT)nSize;
Destination.Buffer = lpDst;
* @implemented
*/
DWORD
-STDCALL
+WINAPI
ExpandEnvironmentStringsW (
LPCWSTR lpSrc,
LPWSTR lpDst,
RtlInitUnicodeString (&Source,
(LPWSTR)lpSrc);
+ /* make sure we don't overflow the maximum UNICODE_STRING size */
+ if (nSize > 0x7fff)
+ nSize = 0x7fff;
+
Destination.Length = 0;
Destination.MaximumLength = (USHORT)nSize * sizeof(WCHAR);
Destination.Buffer = lpDst;