-/* $Id: curdir.c,v 1.30 2002/09/07 15:12:26 chorns Exp $
+/* $Id: curdir.c,v 1.33 2002/11/07 02:52:37 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
/* INCLUDES ******************************************************************/
+#include <ddk/ntddk.h>
+#include <ntdll/rtl.h>
#include <windows.h>
-#define NTOS_USER_MODE
-#include <ntos.h>
#define NDEBUG
#include <kernel32/kernel32.h>
{
ANSI_STRING String;
ULONG Length;
+ NTSTATUS Status;
if (lpBuffer == NULL)
return 0;
- Length = RtlUnicodeStringToAnsiSize (&SystemDirectory);
- if (uSize > Length)
- {
+ Length = RtlUnicodeStringToAnsiSize (&SystemDirectory); //len of ansi str incl. nullchar
+
+ if (uSize >= Length){
String.Length = 0;
String.MaximumLength = uSize;
String.Buffer = lpBuffer;
/* convert unicode string to ansi (or oem) */
if (bIsFileApiAnsi)
- RtlUnicodeStringToAnsiString (&String,
+ Status = RtlUnicodeStringToAnsiString (&String,
&SystemDirectory,
FALSE);
else
- RtlUnicodeStringToOemString (&String,
+ Status = RtlUnicodeStringToOemString (&String,
&SystemDirectory,
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
}
return 0;
Length = SystemDirectory.Length / sizeof (WCHAR);
- if (uSize > Length)
- {
+ if (uSize > Length) {
memmove (lpBuffer,
SystemDirectory.Buffer,
SystemDirectory.Length);
lpBuffer[Length] = 0;
+
+ return Length; //good: ret chars excl. nullchar
}
- return Length;
+ return Length+1; //bad: ret space needed incl. nullchar
}
{
ANSI_STRING String;
ULONG Length;
+ NTSTATUS Status;
if (lpBuffer == NULL)
return 0;
- Length = RtlUnicodeStringToAnsiSize (&WindowsDirectory);
- if (uSize > Length)
- {
+ Length = RtlUnicodeStringToAnsiSize (&WindowsDirectory); //len of ansi str incl. nullchar
+
+ if (uSize >= Length){
+
String.Length = 0;
String.MaximumLength = uSize;
String.Buffer = lpBuffer;
/* convert unicode string to ansi (or oem) */
if (bIsFileApiAnsi)
- RtlUnicodeStringToAnsiString (&String,
+ Status = RtlUnicodeStringToAnsiString (&String,
&WindowsDirectory,
FALSE);
else
- RtlUnicodeStringToOemString (&String,
+ Status = RtlUnicodeStringToOemString (&String,
&WindowsDirectory,
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
}
WindowsDirectory.Buffer,
WindowsDirectory.Length);
lpBuffer[Length] = 0;
+
+ return Length; //good: ret chars excl. nullchar
}
- return Length;
+ return Length+1; //bad: ret space needed incl. nullchar
}
/* EOF */