[RTL/NDK]
[reactos.git] / reactos / lib / rtl / path.c
index 3fc824f..4585815 100644 (file)
@@ -138,7 +138,7 @@ RtlIsDosDeviceName_Ustr(IN PCUNICODE_STRING PathString)
                     ((c == 'l') || (c == 'c') || (c == 'p') || (c == 'a') || (c == 'n')))
                 {
                     /* Calculate the offset */
-                    ReturnOffset = (PCHAR)End - (PCHAR)PathCopy.Buffer;
+                    ReturnOffset = (USHORT)((PCHAR)End - (PCHAR)PathCopy.Buffer);
 
                     /* Build the final string */
                     PathCopy.Length = OriginalLength - ReturnOffset - (ColonCount * sizeof(WCHAR));
@@ -179,7 +179,7 @@ RtlIsDosDeviceName_Ustr(IN PCUNICODE_STRING PathString)
     while ((Start > PathCopy.Buffer) && (Start[-1] == ' ')) --Start;
 
     /* Finally see how many characters are left, and that's our size */
-    PathChars = Start - PathCopy.Buffer;
+    PathChars = (USHORT)(Start - PathCopy.Buffer);
     PathCopy.Length = PathChars * sizeof(WCHAR);
 
     /* Check if this is a COM or LPT port, which has a digit after it */
@@ -641,13 +641,13 @@ RtlpDosPathNameToRelativeNtPathName_Ustr(IN BOOLEAN HaveRelative,
                     RtlReleasePebLock();
                     return Status;
                 }
+
                 /* File is in current directory */
                 if (RtlEqualUnicodeString(&FullPath, &CurrentDirectory->DosPath, TRUE))
                 {
                     /* Make relative name string */
                     RelativeName->RelativeName.Buffer = (PWSTR)((ULONG_PTR)NewBuffer + FullPath.Length - PrefixCut);
-                    RelativeName->RelativeName.Length = PathLength - FullPath.Length;
+                    RelativeName->RelativeName.Length = (USHORT)(PathLength - FullPath.Length);
                     /* If relative name starts with \, skip it */
                     if (RelativeName->RelativeName.Buffer[0] == L'\\')
                     {
@@ -1009,10 +1009,13 @@ RtlSetCurrentDirectory_U(IN PUNICODE_STRING Path)
     OBJECT_ATTRIBUTES ObjectAttributes;
     FILE_FS_DEVICE_INFORMATION FileFsDeviceInfo;
     ULONG SavedLength, CharLength, FullPathLength;
-    HANDLE OldHandle = 0, CurDirHandle, OldCurDirHandle = 0;
+    HANDLE OldHandle = NULL, CurDirHandle = NULL, OldCurDirHandle = NULL;
 
     DPRINT("RtlSetCurrentDirectory_U %wZ\n", Path);
 
+    /* Initialize for failure case */
+    RtlInitEmptyUnicodeString(&NtName, NULL, 0);
+
     /* Can't set current directory on DOS device */
     if (RtlIsDosDeviceName_Ustr(Path))
     {
@@ -1075,7 +1078,7 @@ RtlSetCurrentDirectory_U(IN PUNICODE_STRING Path)
     {
         /* Get back normal handle */
         CurDirHandle = (HANDLE)((ULONG_PTR)(CurDir->Handle) & ~RTL_CURDIR_ALL_FLAGS);
-        CurDir->Handle = 0;
+        CurDir->Handle = NULL;
 
         /* Get device information */
         Status = NtQueryVolumeInformationFile(CurDirHandle,
@@ -1116,7 +1119,7 @@ RtlSetCurrentDirectory_U(IN PUNICODE_STRING Path)
         CurDirHandle = (HANDLE)((ULONG_PTR)CurDirHandle | RTL_CURDIR_IS_REMOVABLE);
     }
 
-    FullPath.Length = FullPathLength;
+    FullPath.Length = (USHORT)FullPathLength;
 
     /* If full path isn't \ terminated, do it */
     if (FullPath.Buffer[CharLength - 1] != L'\\')
@@ -1157,7 +1160,7 @@ RtlSetCurrentDirectory_U(IN PUNICODE_STRING Path)
     /* Save new data */
     CurDir->Handle = CurDirHandle;
     RtlpCurDirRef->Handle = CurDirHandle;
-    CurDirHandle = 0;
+    CurDirHandle = NULL;
 
     /* Copy full path */
     RtlCopyMemory(CurDir->DosPath.Buffer, FullPath.Buffer, FullPath.Length + sizeof(WCHAR));
@@ -1775,7 +1778,7 @@ RtlDosSearchPath_U(IN PCWSTR Path,
 /*
  * @implemented
  */
-ULONG
+NTSTATUS
 NTAPI
 RtlGetFullPathName_UstrEx(IN PUNICODE_STRING FileName,
                           IN PUNICODE_STRING StaticString,
@@ -1784,7 +1787,7 @@ RtlGetFullPathName_UstrEx(IN PUNICODE_STRING FileName,
                           IN PSIZE_T FilePartSize,
                           OUT PBOOLEAN NameInvalid,
                           OUT RTL_PATH_TYPE* PathType,
-                          OUT PULONG LengthNeeded)
+                          OUT PSIZE_T LengthNeeded)
 {
     NTSTATUS Status;
     PWCHAR StaticBuffer;
@@ -1846,7 +1849,7 @@ RtlGetFullPathName_UstrEx(IN PUNICODE_STRING FileName,
     if ((StaticString) && (Length < StaticLength))
     {
         /* Set the final length */
-        StaticString->Length = Length;
+        StaticString->Length = (USHORT)Length;
 
         /* Set the file part size */
         if (FilePartSize) *FilePartSize = ShortName ? (ShortName - StaticString->Buffer) : 0;
@@ -1878,7 +1881,7 @@ RtlGetFullPathName_UstrEx(IN PUNICODE_STRING FileName,
 
         /* Set the settings for the dynamic string the caller sent */
         DynamicString->MaximumLength = StaticLength;
-        DynamicString->Length = Length;
+        DynamicString->Length = (USHORT)Length;
         DynamicString->Buffer = StaticBuffer;
 
         /* Set the part size */
@@ -1914,7 +1917,7 @@ RtlGetFullPathName_UstrEx(IN PUNICODE_STRING FileName,
     if ((StaticString) && (Length < StaticLength))
     {
         /* Set the final length */
-        StaticString->Length = Length;
+        StaticString->Length = (USHORT)Length;
 
         /* Set the file part size */
         if (FilePartSize) *FilePartSize = ShortName ? (ShortName - StaticString->Buffer) : 0;
@@ -1946,7 +1949,7 @@ RtlGetFullPathName_UstrEx(IN PUNICODE_STRING FileName,
     }
 
     /* Add space for a NULL terminator, and now check the full path */
-    TempDynamicString.MaximumLength = Length + sizeof(UNICODE_NULL);
+    TempDynamicString.MaximumLength = (USHORT)Length + sizeof(UNICODE_NULL);
     Length = RtlGetFullPathName_Ustr(FileName,
                                      Length,
                                      TempDynamicString.Buffer,
@@ -1979,7 +1982,7 @@ RtlGetFullPathName_UstrEx(IN PUNICODE_STRING FileName,
 
     /* Finalize the string and return it to the user */
     DynamicString->Buffer = TempDynamicString.Buffer;
-    DynamicString->Length = Length;
+    DynamicString->Length = (USHORT)Length;
     DynamicString->MaximumLength = TempDynamicString.MaximumLength;
     if (StringUsed) *StringUsed = DynamicString;
 
@@ -2027,16 +2030,16 @@ RtlDosSearchPath_Ustr(IN ULONG Flags,
                       IN PUNICODE_STRING CallerBuffer,
                       IN OUT PUNICODE_STRING DynamicString OPTIONAL,
                       OUT PUNICODE_STRING* FullNameOut OPTIONAL,
-                      OUT PULONG FilePartSize OPTIONAL,
-                      OUT PULONG LengthNeeded OPTIONAL)
+                      OUT PSIZE_T FilePartSize OPTIONAL,
+                      OUT PSIZE_T LengthNeeded OPTIONAL)
 {
     WCHAR StaticCandidateBuffer[MAX_PATH];
     UNICODE_STRING StaticCandidateString;
     NTSTATUS Status;
     RTL_PATH_TYPE PathType;
     PWCHAR p, End, CandidateEnd, SegmentEnd;
-    ULONG SegmentSize, NamePlusExtLength, PathSize, MaxPathSize = 0, WorstCaseLength, ByteCount;
-    USHORT ExtensionLength = 0;
+    SIZE_T SegmentSize, ByteCount, PathSize, MaxPathSize = 0;
+    USHORT NamePlusExtLength, WorstCaseLength, ExtensionLength = 0;
     PUNICODE_STRING FullIsolatedPath;
     DPRINT("DOS Path Search: %lx %wZ %wZ %wZ %wZ %wZ\n",
             Flags, PathString, FileNameString, ExtensionString, CallerBuffer, DynamicString);
@@ -2177,7 +2180,7 @@ RtlDosSearchPath_Ustr(IN ULONG Flags,
         /* Use the extension, the file name, and the largest path as the size */
         WorstCaseLength = ExtensionLength +
                           FileNameString->Length +
-                          MaxPathSize +
+                          (USHORT)MaxPathSize +
                           sizeof(UNICODE_NULL);
         if (WorstCaseLength > UNICODE_STRING_MAX_BYTES)
         {
@@ -2292,7 +2295,7 @@ RtlDosSearchPath_Ustr(IN ULONG Flags,
             *CandidateEnd = UNICODE_NULL;
 
             /* Now set the final length of the string so it becomes valid */
-            StaticCandidateString.Length = (CandidateEnd -
+            StaticCandidateString.Length = (USHORT)(CandidateEnd -
                                             StaticCandidateString.Buffer) *
                                            sizeof(WCHAR);