Manually applying Gunnars patch because it's easier this way - and a good chance...
[reactos.git] / reactos / lib / kernel32 / file / curdir.c
index 4c131c8..9c68c5a 100644 (file)
@@ -1,4 +1,4 @@
-/* $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
@@ -11,9 +11,9 @@
 
 /* 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>
@@ -250,29 +250,35 @@ GetSystemDirectoryA (
 {
        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
 }
 
 
@@ -289,15 +295,16 @@ GetSystemDirectoryW (
                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
 }
 
 
@@ -310,29 +317,36 @@ GetWindowsDirectoryA (
 {
        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
 }
 
 
@@ -355,9 +369,11 @@ GetWindowsDirectoryW (
                         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 */