Set short path names for 'temp' and 'tmp' environment variables.

svn path=/trunk/; revision=9926
This commit is contained in:
Eric Kohl 2004-06-29 12:06:01 +00:00
parent 2a6745d9d4
commit b031cfa717

View file

@ -1,4 +1,4 @@
/* $Id: environment.c,v 1.4 2004/06/25 11:42:00 ekohl Exp $ /* $Id: environment.c,v 1.5 2004/06/29 12:06:01 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -21,6 +21,7 @@ SetUserEnvironmentVariable (LPVOID *Environment,
LPWSTR lpValue, LPWSTR lpValue,
BOOL bExpand) BOOL bExpand)
{ {
WCHAR ShortName[MAX_PATH];
UNICODE_STRING Name; UNICODE_STRING Name;
UNICODE_STRING SrcValue; UNICODE_STRING SrcValue;
UNICODE_STRING DstValue; UNICODE_STRING DstValue;
@ -36,8 +37,8 @@ SetUserEnvironmentVariable (LPVOID *Environment,
DstValue.Length = 0; DstValue.Length = 0;
DstValue.MaximumLength = Length; DstValue.MaximumLength = Length;
DstValue.Buffer = LocalAlloc (LPTR, DstValue.Buffer = LocalAlloc(LPTR,
Length); Length);
if (DstValue.Buffer == NULL) if (DstValue.Buffer == NULL)
{ {
DPRINT1("LocalAlloc() failed\n"); DPRINT1("LocalAlloc() failed\n");
@ -50,8 +51,8 @@ SetUserEnvironmentVariable (LPVOID *Environment,
&Length); &Length);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1 ("RtlExpandEnvironmentStrings_U() failed (Status %lx)\n", Status); DPRINT1("RtlExpandEnvironmentStrings_U() failed (Status %lx)\n", Status);
DPRINT1 ("Length %lu\n", Length); DPRINT1("Length %lu\n", Length);
return FALSE; return FALSE;
} }
} }
@ -61,14 +62,27 @@ SetUserEnvironmentVariable (LPVOID *Environment,
lpValue); lpValue);
} }
RtlInitUnicodeString (&Name, if (!_wcsicmp (lpName, L"temp") || !_wcsicmp (lpName, L"tmp"))
lpName); {
if (!GetShortPathNameW(DstValue.Buffer, ShortName, MAX_PATH))
{
DPRINT1("GetShortPathNameW() failed (Error %lu)\n", GetLastError());
return FALSE;
}
DPRINT("Buffer: %S\n", ShortName);
RtlInitUnicodeString(&DstValue,
ShortName);
}
RtlInitUnicodeString(&Name,
lpName);
DPRINT("Value: %wZ\n", &DstValue); DPRINT("Value: %wZ\n", &DstValue);
Status = RtlSetEnvironmentVariable ((PWSTR*)Environment, Status = RtlSetEnvironmentVariable((PWSTR*)Environment,
&Name, &Name,
&DstValue); &DstValue);
if (bExpand) if (bExpand)
{ {
@ -77,7 +91,7 @@ SetUserEnvironmentVariable (LPVOID *Environment,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1 ("RtlSetEnvironmentVariable() failed (Status %lx)\n", Status); DPRINT1("RtlSetEnvironmentVariable() failed (Status %lx)\n", Status);
return FALSE; return FALSE;
} }