[RTL]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Tue, 24 Sep 2013 22:16:30 +0000 (22:16 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Tue, 24 Sep 2013 22:16:30 +0000 (22:16 +0000)
Implement and export RtlGetLengthWithoutTrailingPathSeperators (aka. RtlGetLengthWithoutTrailingPathSeparators) (needed for win2k3's basesrv.dll).
Patch by David Quintana, where I simplified the loop (and reduced the number of local variables).
CORE-7482 #comment Function committed in revision 60348, thanks ;)

svn path=/trunk/; revision=60348

reactos/dll/ntdll/def/ntdll.spec
reactos/include/ndk/rtlfuncs.h
reactos/lib/rtl/path.c

index 32e07c8..e4ab7e1 100644 (file)
 @ stdcall RtlGetLastWin32Error()
 @ stdcall RtlGetLengthWithoutLastFullDosOrNtPathElement(long ptr ptr)
 ; Yes, Microsoft really misspelled this one!
-;@ stdcall RtlGetLengthWithoutTrailingPathSeperators
+@ stdcall RtlGetLengthWithoutTrailingPathSeperators(long ptr ptr) RtlGetLengthWithoutTrailingPathSeparators
 @ stdcall RtlGetLongestNtPathLength()
 @ stdcall RtlGetNativeSystemInformation(long long long long) NtQuerySystemInformation
 @ stdcall RtlGetNextRange(ptr ptr long)
index 7216f13..4084dd8 100644 (file)
@@ -2725,6 +2725,15 @@ RtlGetFullPathName_UstrEx(
     _Out_opt_ PSIZE_T LengthNeeded
 );
 
+NTSYSAPI
+NTSTATUS
+NTAPI
+RtlGetLengthWithoutTrailingPathSeparators(
+    _In_ ULONG Flags,
+    _In_ PCUNICODE_STRING PathString,
+    _Out_ PULONG Length
+);
+
 NTSYSAPI
 ULONG
 NTAPI
index ca68d1d..ef9c250 100644 (file)
@@ -1251,6 +1251,48 @@ RtlGetLongestNtPathLength(VOID)
     return MAX_PATH + RtlpDosDevicesUncPrefix.Length / sizeof(WCHAR) + sizeof(ANSI_NULL);
 }
 
+/*
+ * @implemented
+ * @note: the export is called RtlGetLengthWithoutTrailingPathSeperators
+ *        (with a 'e' instead of a 'a' in "Seperators").
+ */
+NTSTATUS
+NTAPI
+RtlGetLengthWithoutTrailingPathSeparators(IN  ULONG Flags,
+                                          IN  PCUNICODE_STRING PathString,
+                                          OUT PULONG Length)
+{
+    ULONG NumChars;
+
+    /* Parameters validation */
+    if (Length == NULL) return STATUS_INVALID_PARAMETER;
+
+    *Length = 0;
+
+    if (PathString == NULL) return STATUS_INVALID_PARAMETER;
+
+    /* No flags are supported yet */
+    if (Flags != 0) return STATUS_INVALID_PARAMETER;
+
+    NumChars = PathString->Length / sizeof(WCHAR);
+
+    /*
+     * Notice that we skip the last character, therefore:
+     * - if we have: "some/path/f" we test for: "some/path/"
+     * - if we have: "some/path/"  we test for: "some/path"
+     * - if we have: "s" we test for: ""
+     * - if we have: "" then NumChars was already zero and we aren't there
+     */
+
+    while (NumChars > 0 && IS_PATH_SEPARATOR(PathString->Buffer[NumChars - 1]))
+    {
+        --NumChars;
+    }
+
+    *Length = NumChars;
+    return STATUS_SUCCESS;
+}
+
 /*
  * @implemented
  */