#include <k32.h>
#define NDEBUG
-#include "../include/debug.h"
+#include <debug.h>
/* FUNCTIONS ******************************************************************/
* @implemented
*/
DWORD
-STDCALL
+WINAPI
GetEnvironmentVariableA (
LPCSTR lpName,
LPSTR lpBuffer,
/* initialize ansi variable value string */
VarValue.Length = 0;
- VarValue.MaximumLength = nSize;
+ VarValue.MaximumLength = (USHORT)nSize;
VarValue.Buffer = lpBuffer;
/* initialize unicode variable value string and allocate buffer */
VarValueU.Length = 0;
if (nSize != 0)
{
- VarValueU.MaximumLength = (nSize - 1) * sizeof(WCHAR);
+ VarValueU.MaximumLength = (USHORT)(nSize - 1) * sizeof(WCHAR);
VarValueU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
0,
nSize * sizeof(WCHAR));
* @implemented
*/
DWORD
-STDCALL
+WINAPI
GetEnvironmentVariableW (
LPCWSTR lpName,
LPWSTR lpBuffer,
lpName);
VarValue.Length = 0;
- VarValue.MaximumLength = (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
)
DPRINT("EnvPtr %p\n", EnvPtr);
/* convert unicode environment to ansi */
- UnicodeString.MaximumLength = Length * sizeof(WCHAR) + sizeof(WCHAR);
+ UnicodeString.MaximumLength = (USHORT)Length * sizeof(WCHAR) + sizeof(WCHAR);
UnicodeString.Buffer = EnvU;
- AnsiString.MaximumLength = Length + 1;
+ AnsiString.MaximumLength = (USHORT)Length + 1;
AnsiString.Length = 0;
AnsiString.Buffer = EnvPtr;
if (UnicodeString.Length > 0)
{
AnsiString.Length = 0;
- AnsiString.MaximumLength = Length + 1 - (AnsiString.Buffer - EnvPtr);
+ AnsiString.MaximumLength = (USHORT)Length + 1 - (AnsiString.Buffer - EnvPtr);
RtlUnicodeStringToAnsiString (&AnsiString,
&UnicodeString,
* @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 = nSize;
+ Destination.MaximumLength = (USHORT)nSize;
Destination.Buffer = lpDst;
DestinationU.Length = 0;
- DestinationU.MaximumLength = nSize * sizeof(WCHAR);
+ DestinationU.MaximumLength = (USHORT)nSize * sizeof(WCHAR);
DestinationU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
0,
DestinationU.MaximumLength);
* @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 = nSize * sizeof(WCHAR);
+ Destination.MaximumLength = (USHORT)nSize * sizeof(WCHAR);
Destination.Buffer = lpDst;
Status = RtlExpandEnvironmentStrings_U (NULL,