Part of patch contributed by Gunnar Andr� Dalsnes.

svn path=/trunk/; revision=3641
This commit is contained in:
Robert Dickenson 2002-10-20 03:34:00 +00:00
parent db067a2011
commit bab254e373
2 changed files with 48 additions and 25 deletions

View file

@ -1,4 +1,4 @@
/* $Id: curdir.c,v 1.31 2002/09/08 10:22:41 chorns Exp $ /* $Id: curdir.c,v 1.32 2002/10/20 03:33:34 robd 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
@ -250,29 +250,35 @@ GetSystemDirectoryA (
{ {
ANSI_STRING String; ANSI_STRING String;
ULONG Length; ULONG Length;
NTSTATUS Status;
if (lpBuffer == NULL) if (lpBuffer == NULL)
return 0; return 0;
Length = RtlUnicodeStringToAnsiSize (&SystemDirectory); Length = RtlUnicodeStringToAnsiSize (&SystemDirectory); //len of ansi str incl. nullchar
if (uSize > Length)
{ if (uSize >= Length){
String.Length = 0; String.Length = 0;
String.MaximumLength = uSize; String.MaximumLength = uSize;
String.Buffer = lpBuffer; String.Buffer = lpBuffer;
/* convert unicode string to ansi (or oem) */ /* convert unicode string to ansi (or oem) */
if (bIsFileApiAnsi) if (bIsFileApiAnsi)
RtlUnicodeStringToAnsiString (&String, Status = RtlUnicodeStringToAnsiString (&String,
&SystemDirectory, &SystemDirectory,
FALSE); FALSE);
else else
RtlUnicodeStringToOemString (&String, Status = RtlUnicodeStringToOemString (&String,
&SystemDirectory, &SystemDirectory,
FALSE); FALSE);
if (!NT_SUCCESS(Status) )
return 0;
return Length-1; //good: ret chars excl. nullchar
} }
return Length; return Length; //bad: ret space needed incl. nullchar
} }
@ -289,15 +295,16 @@ GetSystemDirectoryW (
return 0; return 0;
Length = SystemDirectory.Length / sizeof (WCHAR); Length = SystemDirectory.Length / sizeof (WCHAR);
if (uSize > Length) if (uSize > Length) {
{
memmove (lpBuffer, memmove (lpBuffer,
SystemDirectory.Buffer, SystemDirectory.Buffer,
SystemDirectory.Length); SystemDirectory.Length);
lpBuffer[Length] = 0; lpBuffer[Length] = 0;
return Length; //good: ret chars excl. nullchar
} }
return Length; return Length+1; //bad: ret space needed incl. nullchar
} }
@ -310,29 +317,43 @@ GetWindowsDirectoryA (
{ {
ANSI_STRING String; ANSI_STRING String;
ULONG Length; ULONG Length;
NTSTATUS Status;
if (lpBuffer == NULL) if (lpBuffer == NULL)
return 0; return 0;
Length = RtlUnicodeStringToAnsiSize (&WindowsDirectory); Length = RtlUnicodeStringToAnsiSize (&WindowsDirectory); //len of ansi str incl. nullchar
if (uSize > Length)
{ printf("windirlen incl term %i\n", Length);
if (uSize >= Length){
printf("ok: enoug space\n");
String.Length = 0; String.Length = 0;
String.MaximumLength = uSize; String.MaximumLength = uSize;
String.Buffer = lpBuffer; String.Buffer = lpBuffer;
/* convert unicode string to ansi (or oem) */ /* convert unicode string to ansi (or oem) */
if (bIsFileApiAnsi) if (bIsFileApiAnsi)
RtlUnicodeStringToAnsiString (&String, Status = RtlUnicodeStringToAnsiString (&String,
&WindowsDirectory, &WindowsDirectory,
FALSE); FALSE);
else else
RtlUnicodeStringToOemString (&String, Status = RtlUnicodeStringToOemString (&String,
&WindowsDirectory, &WindowsDirectory,
FALSE); FALSE);
if (!NT_SUCCESS(Status))
return 0;
printf("good: ret chars %i\n",Length-1);
printf("dir: %s\n",lpBuffer);
return Length-1; //good: ret chars excl. nullchar
} }
return Length; printf("bad: ret chars needed %i\n",Length);
return Length; //bad: ret space needed incl. nullchar
} }
@ -355,9 +376,11 @@ GetWindowsDirectoryW (
WindowsDirectory.Buffer, WindowsDirectory.Buffer,
WindowsDirectory.Length); WindowsDirectory.Length);
lpBuffer[Length] = 0; lpBuffer[Length] = 0;
return Length; //good: ret chars excl. nullchar
} }
return Length; return Length+1; //bad: ret space needed incl. nullchar
} }
/* EOF */ /* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: unicode.c,v 1.23 2002/09/17 23:41:44 dwelch Exp $ /* $Id: unicode.c,v 1.24 2002/10/20 03:34:00 robd Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -1122,7 +1122,7 @@ RtlUnicodeStringToAnsiSize (
UnicodeString->Buffer, UnicodeString->Buffer,
UnicodeString->Length); UnicodeString->Length);
return Size; return Size+1; //NB: incl. nullterm
} }
@ -1286,7 +1286,7 @@ RtlUnicodeStringToOemSize (
UnicodeString->Buffer, UnicodeString->Buffer,
UnicodeString->Length); UnicodeString->Length);
return Size; return Size+1; //NB: incl. nullterm
} }
@ -1303,7 +1303,7 @@ RtlUnicodeStringToCountedOemString (
ULONG Size; ULONG Size;
if (NlsMbOemCodePageTag == TRUE) if (NlsMbOemCodePageTag == TRUE)
Length = RtlUnicodeStringToAnsiSize (SourceString) + 1; Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
else else
Length = SourceString->Length / sizeof(WCHAR) + 1; Length = SourceString->Length / sizeof(WCHAR) + 1;
@ -1370,7 +1370,7 @@ RtlUnicodeStringToOemString (
ULONG Size; ULONG Size;
if (NlsMbOemCodePageTag == TRUE) if (NlsMbOemCodePageTag == TRUE)
Length = RtlUnicodeStringToAnsiSize (SourceString) + 1; Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
else else
Length = SourceString->Length / sizeof(WCHAR) + 1; Length = SourceString->Length / sizeof(WCHAR) + 1;
@ -1496,7 +1496,7 @@ RtlUpcaseUnicodeStringToAnsiString (
ULONG Size; ULONG Size;
if (NlsMbCodePageTag == TRUE) if (NlsMbCodePageTag == TRUE)
Length = RtlUnicodeStringToAnsiSize (SourceString) + 1; Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
else else
Length = SourceString->Length / sizeof(WCHAR) + 1; Length = SourceString->Length / sizeof(WCHAR) + 1;
@ -1563,7 +1563,7 @@ RtlUpcaseUnicodeStringToCountedOemString (
ULONG Size; ULONG Size;
if (NlsMbCodePageTag == TRUE) if (NlsMbCodePageTag == TRUE)
Length = RtlUnicodeStringToAnsiSize (SourceString) + 1; Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
else else
Length = SourceString->Length / sizeof(WCHAR) + 1; Length = SourceString->Length / sizeof(WCHAR) + 1;
@ -1630,7 +1630,7 @@ RtlUpcaseUnicodeStringToOemString (
ULONG Size; ULONG Size;
if (NlsMbOemCodePageTag == TRUE) if (NlsMbOemCodePageTag == TRUE)
Length = RtlUnicodeStringToAnsiSize (SourceString) + 1; Length = RtlUnicodeStringToAnsiSize (SourceString)/* + 1*/;
else else
Length = SourceString->Length / sizeof(WCHAR) + 1; Length = SourceString->Length / sizeof(WCHAR) + 1;