2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
5 * PURPOSE: Path and current directory functions
6 * PROGRAMMERS: Wine team
11 /* INCLUDES *****************************************************************/
18 /* DEFINITONS and MACROS ******************************************************/
20 #define MAX_PFX_SIZE 16
22 #define IS_PATH_SEPARATOR(x) (((x)==L'\\')||((x)==L'/'))
25 /* GLOBALS ********************************************************************/
27 static const WCHAR DeviceRootW
[] = L
"\\\\.\\";
28 const UNICODE_STRING DeviceRootString
= RTL_CONSTANT_STRING(L
"\\\\.\\");
30 const UNICODE_STRING RtlpDosDevicesUncPrefix
= RTL_CONSTANT_STRING(L
"\\??\\UNC\\");
31 const UNICODE_STRING RtlpWin32NtRootSlash
= RTL_CONSTANT_STRING(L
"\\\\?\\");
32 const UNICODE_STRING RtlpDosSlashCONDevice
= RTL_CONSTANT_STRING(L
"\\\\.\\CON");
33 const UNICODE_STRING RtlpDosDevicesPrefix
= RTL_CONSTANT_STRING(L
"\\??\\");
35 const UNICODE_STRING RtlpDosLPTDevice
= RTL_CONSTANT_STRING(L
"LPT");
36 const UNICODE_STRING RtlpDosCOMDevice
= RTL_CONSTANT_STRING(L
"COM");
37 const UNICODE_STRING RtlpDosPRNDevice
= RTL_CONSTANT_STRING(L
"PRN");
38 const UNICODE_STRING RtlpDosAUXDevice
= RTL_CONSTANT_STRING(L
"AUX");
39 const UNICODE_STRING RtlpDosCONDevice
= RTL_CONSTANT_STRING(L
"CON");
40 const UNICODE_STRING RtlpDosNULDevice
= RTL_CONSTANT_STRING(L
"NUL");
42 /* PRIVATE FUNCTIONS **********************************************************/
46 RtlIsDosDeviceName_Ustr(IN PUNICODE_STRING PathString
)
48 UNICODE_STRING PathCopy
;
50 USHORT PathChars
, ColonCount
= 0;
51 USHORT ReturnOffset
= 0, ReturnLength
, OriginalLength
;
54 /* Validate the input */
55 if (!PathString
) return 0;
57 /* Check what type of path this is */
58 switch (RtlDetermineDosPathNameType_Ustr(PathString
))
60 /* Fail for UNC or unknown paths */
61 case RtlPathTypeUnknown
:
62 case RtlPathTypeUncAbsolute
:
65 /* Make special check for the CON device */
66 case RtlPathTypeLocalDevice
:
67 if (RtlEqualUnicodeString(PathString
, &RtlpDosSlashCONDevice
, TRUE
))
69 /* This should return 0x80006 */
70 return MAKELONG(RtlpDosCONDevice
.Length
, DeviceRootString
.Length
);
78 /* Make a copy of the string */
79 PathCopy
= *PathString
;
80 OriginalLength
= PathString
->Length
;
82 /* Return if there's no characters */
83 PathChars
= PathCopy
.Length
/ sizeof(WCHAR
);
84 if (!PathChars
) return 0;
86 /* Check for drive path and truncate */
87 if (PathCopy
.Buffer
[PathChars
- 1] == L
':')
89 /* Fixup the lengths */
90 PathCopy
.Length
-= sizeof(WCHAR
);
91 if (!--PathChars
) return 0;
93 /* Remember this for later */
97 /* Check for extension or space, and truncate */
100 /* Stop if we hit something else than a space or period */
101 c
= PathCopy
.Buffer
[PathChars
- 1];
102 if ((c
!= '.') && (c
!= ' ')) break;
104 /* Fixup the lengths */
105 PathCopy
.Length
-= sizeof(WCHAR
);
107 /* Remember this for later */
109 } while (--PathChars
);
111 /* Anything still left? */
114 /* Loop from the end */
115 for (End
= &PathCopy
.Buffer
[PathChars
- 1];
116 End
>= PathCopy
.Buffer
;
119 /* Check if the character is a path or drive separator */
121 if ((c
== '\\') || (c
== '/') || ((c
== ':') && (End
== PathCopy
.Buffer
+ 1)))
123 /* Get the next lower case character */
125 c
= *End
| ' '; // ' ' == ('z' - 'Z')
127 /* Check if it's a DOS device (LPT, COM, PRN, AUX, or NUL) */
128 if ((End
< &PathCopy
.Buffer
[OriginalLength
/ sizeof(WCHAR
)]) &&
129 ((c
== 'l') || (c
== 'c') || (c
== 'p') || (c
== 'a') || (c
== 'n')))
131 /* Calculate the offset */
132 ReturnOffset
= (PCHAR
)End
- (PCHAR
)PathCopy
.Buffer
;
134 /* Build the final string */
135 PathCopy
.Length
= OriginalLength
- ReturnOffset
- (ColonCount
* sizeof(WCHAR
));
136 PathCopy
.Buffer
= End
;
138 /* Save new amount of chars in the path */
139 PathChars
= PathCopy
.Length
/ sizeof(WCHAR
);
150 /* Get the next lower case character and check if it's a DOS device */
151 c
= *PathCopy
.Buffer
| ' '; // ' ' == ('z' - 'Z')
152 if ((c
!= 'l') && (c
!= 'c') && (c
!= 'p') && (c
!= 'a') && (c
!= 'n'))
154 /* Not LPT, COM, PRN, AUX, or NUL */
159 /* Now skip past any extra extension or drive letter characters */
160 Start
= PathCopy
.Buffer
;
161 End
= &Start
[PathChars
];
165 if ((c
== '.') || (c
== ':')) break;
169 /* And then go backwards to get rid of spaces */
170 while ((Start
> PathCopy
.Buffer
) && (Start
[-1] == ' ')) --Start
;
172 /* Finally see how many characters are left, and that's our size */
173 PathChars
= Start
- PathCopy
.Buffer
;
174 PathCopy
.Length
= PathChars
* sizeof(WCHAR
);
176 /* Check if this is a COM or LPT port, which has a digit after it */
177 if ((PathChars
== 4) &&
178 (iswdigit(PathCopy
.Buffer
[3]) && (PathCopy
.Buffer
[3] != '0')))
180 /* Don't compare the number part, just check for LPT or COM */
181 PathCopy
.Length
-= sizeof(WCHAR
);
182 if ((RtlEqualUnicodeString(&PathCopy
, &RtlpDosLPTDevice
, TRUE
)) ||
183 (RtlEqualUnicodeString(&PathCopy
, &RtlpDosCOMDevice
, TRUE
)))
186 ReturnLength
= sizeof(L
"COM1") - sizeof(WCHAR
);
187 return MAKELONG(ReturnLength
, ReturnOffset
);
190 else if ((PathChars
== 3) &&
191 ((RtlEqualUnicodeString(&PathCopy
, &RtlpDosPRNDevice
, TRUE
)) ||
192 (RtlEqualUnicodeString(&PathCopy
, &RtlpDosAUXDevice
, TRUE
)) ||
193 (RtlEqualUnicodeString(&PathCopy
, &RtlpDosNULDevice
, TRUE
)) ||
194 (RtlEqualUnicodeString(&PathCopy
, &RtlpDosCONDevice
, TRUE
))))
196 /* Otherwise this was something like AUX, NUL, PRN, or CON */
197 ReturnLength
= sizeof(L
"AUX") - sizeof(WCHAR
);
198 return MAKELONG(ReturnLength
, ReturnOffset
);
201 /* Otherwise, this is not a valid DOS device */
207 RtlDetermineDosPathNameType_Ustr(IN PCUNICODE_STRING PathString
)
212 /* Validate the input */
213 if (!PathString
) return RtlPathTypeUnknown
;
215 Path
= PathString
->Buffer
;
216 Chars
= PathString
->Length
/ sizeof(WCHAR
);
218 /* Return if there are no characters */
219 if (!Chars
) return RtlPathTypeUnknown
;
222 * The algorithm is similar to RtlDetermineDosPathNameType_U but here we
223 * actually check for the path length before touching the characters
225 if ((Chars
< 1) || (IS_PATH_SEPARATOR(Path
[0])))
227 if ((Chars
< 2) || !(IS_PATH_SEPARATOR(Path
[1]))) return RtlPathTypeRooted
; /* \x */
228 if ((Chars
< 3) || ((Path
[2] != L
'.') && (Path
[2] != L
'?'))) return RtlPathTypeUncAbsolute
;/* \\x */
229 if ((Chars
>= 4) && (IS_PATH_SEPARATOR(Path
[3]))) return RtlPathTypeLocalDevice
; /* \\.\x or \\?\x */
230 if (Chars
!= 3) return RtlPathTypeUncAbsolute
; /* \\.x or \\?x */
231 return RtlPathTypeRootLocalDevice
; /* \\. or \\? */
235 if ((Chars
< 2) || (!(Path
[0]) || (Path
[1] != L
':'))) return RtlPathTypeRelative
; /* x */
236 if ((Chars
< 3) || (IS_PATH_SEPARATOR(Path
[2]))) return RtlPathTypeDriveAbsolute
; /* x:\ */
237 return RtlPathTypeDriveRelative
; /* x: */
243 RtlpCheckDeviceName(IN PUNICODE_STRING FileName
,
245 OUT PBOOLEAN NameInvalid
)
250 /* Allocate a large enough buffer */
251 Buffer
= RtlAllocateHeap(RtlGetProcessHeap(), 0, FileName
->Length
);
257 /* Copy the filename */
258 RtlCopyMemory(Buffer
, FileName
->Buffer
, FileName
->Length
);
260 /* And add a dot at the end */
261 Buffer
[Length
/ sizeof(WCHAR
)] = L
'.';
262 Buffer
[(Length
/ sizeof(WCHAR
)) + 1] = UNICODE_NULL
;
264 /* Check if the file exists or not */
265 *NameInvalid
= RtlDoesFileExists_U(Buffer
) ? FALSE
: TRUE
;
267 /* Get rid of the buffer now */
268 Status
= RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer
);
272 /* Assume the name is ok, but fail the call */
273 *NameInvalid
= FALSE
;
274 Status
= STATUS_NO_MEMORY
;
277 /* Return the status */
283 RtlGetFullPathName_Ustr(IN PUNICODE_STRING FileName
,
286 OUT PCWSTR
*ShortName
,
287 OUT PBOOLEAN InvalidName
,
288 OUT RTL_PATH_TYPE
*PathType
)
290 PWCHAR FileNameBuffer
;
291 ULONG FileNameLength
, FileNameChars
, DosLength
, DosLengthOffset
, FullLength
;
295 /* For now, assume the name is valid */
296 DPRINT("Filename: %wZ\n", FileName
);
297 DPRINT("Size and buffer: %lx %S\n", Size
, Buffer
);
298 if (InvalidName
) *InvalidName
= FALSE
;
300 /* Handle initial path type and failure case */
301 *PathType
= RtlPathTypeUnknown
;
302 if (!(Size
) || !(Buffer
) || !(FileName
) ||
303 !(FileName
->Length
) || (FileName
->Buffer
[0] == UNICODE_NULL
)) return 0;
305 /* Break filename into component parts */
306 FileNameBuffer
= FileName
->Buffer
;
307 FileNameLength
= FileName
->Length
;
308 FileNameChars
= FileNameLength
/ sizeof(WCHAR
);
310 /* Kill trailing spaces */
311 c
= FileNameBuffer
[FileNameChars
- 1];
312 while ((FileNameLength
) && (c
== L
' '))
314 /* Keep going, ignoring the spaces */
315 FileNameLength
-= sizeof(WCHAR
);
316 if (FileNameLength
) c
= FileNameBuffer
[FileNameLength
/ sizeof(WCHAR
) - 1];
319 /* Check if anything is left */
320 if (!FileNameLength
) return 0;
322 /* Check if this is a DOS name */
323 DosLength
= RtlIsDosDeviceName_Ustr(FileName
);
324 DPRINT("DOS length for filename: %lx %wZ\n", DosLength
, FileName
);
327 /* Zero out the short name */
328 if (ShortName
) *ShortName
= NULL
;
330 /* See comment for RtlIsDosDeviceName_Ustr if this is confusing... */
331 DosLengthOffset
= DosLength
>> 16;
332 DosLength
= DosLength
& 0xFFFF;
334 /* Do we have a DOS length, and does the caller want validity? */
335 if ((InvalidName
) && (DosLengthOffset
))
338 Status
= RtlpCheckDeviceName(FileName
, DosLengthOffset
, InvalidName
);
340 /* If the check failed, or the name is invalid, fail here */
341 if (!NT_SUCCESS(Status
)) return 0;
342 if (*InvalidName
) return 0;
345 /* Add the size of the device root and check if it fits in the size */
346 FullLength
= DosLength
+ DeviceRootString
.Length
;
347 if (FullLength
< Size
)
349 /* Add the device string */
350 RtlMoveMemory(Buffer
, DeviceRootString
.Buffer
, DeviceRootString
.Length
);
352 /* Now add the DOS device name */
353 RtlMoveMemory((PCHAR
)Buffer
+ DeviceRootString
.Length
,
354 (PCHAR
)FileNameBuffer
+ DosLengthOffset
,
358 *(PWCHAR
)((ULONG_PTR
)Buffer
+ FullLength
) = UNICODE_NULL
;
362 /* Otherwise, there's no space, so return the buffer size needed */
363 if ((FullLength
+ sizeof(UNICODE_NULL
)) > UNICODE_STRING_MAX_BYTES
) return 0;
364 return FullLength
+ sizeof(UNICODE_NULL
);
367 /* This should work well enough for our current needs */
368 *PathType
= RtlDetermineDosPathNameType_U(FileNameBuffer
);
369 DPRINT("Path type: %lx\n", *PathType
);
371 /* This is disgusting... but avoids re-writing everything */
372 DPRINT("Calling old API with %s and %lx and %S\n", FileNameBuffer
, Size
, Buffer
);
373 return RtlGetFullPathName_U(FileNameBuffer
, Size
, Buffer
, (PWSTR
*)ShortName
);
378 RtlpWin32NTNameToNtPathName_U(IN PUNICODE_STRING DosPath
,
379 OUT PUNICODE_STRING NtPath
,
380 OUT PCWSTR
*PartName
,
381 OUT PRTL_RELATIVE_NAME_U RelativeName
)
386 /* Validate the input */
387 if (!DosPath
) return STATUS_OBJECT_NAME_INVALID
;
389 /* Validate the DOS length */
390 DosLength
= DosPath
->Length
;
391 if (DosLength
>= UNICODE_STRING_MAX_BYTES
) return STATUS_NAME_TOO_LONG
;
393 /* Make space for the new path */
394 NewBuffer
= RtlAllocateHeap(RtlGetProcessHeap(),
396 DosLength
+ sizeof(UNICODE_NULL
));
397 if (!NewBuffer
) return STATUS_NO_MEMORY
;
399 /* Copy the prefix, and then the rest of the DOS path, and NULL-terminate */
400 RtlCopyMemory(NewBuffer
, RtlpDosDevicesPrefix
.Buffer
, RtlpDosDevicesPrefix
.Length
);
401 RtlCopyMemory((PCHAR
)NewBuffer
+ RtlpDosDevicesPrefix
.Length
,
402 DosPath
->Buffer
+ RtlpDosDevicesPrefix
.Length
/ sizeof(WCHAR
),
403 DosPath
->Length
- RtlpDosDevicesPrefix
.Length
);
404 NewBuffer
[DosLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
406 /* Did the caller send a relative name? */
409 /* Zero initialize it */
410 RtlInitEmptyUnicodeString(&RelativeName
->RelativeName
, NULL
, 0);
411 RelativeName
->ContainingDirectory
= NULL
;
412 RelativeName
->CurDirRef
= 0;
415 /* Did the caller request a partial name? */
418 /* Loop from the back until we find a path separator */
419 p
= &NewBuffer
[(DosLength
- 1) / sizeof (WCHAR
)];
420 while (p
> NewBuffer
) if (*p
-- == '\\') break;
425 /* Move past it -- anything left? */
429 /* The path ends with a path separator, no part name */
434 /* What follows the path separator is the part name */
440 /* Build the final NT path string */
441 NtPath
->Length
= (USHORT
)DosLength
;
442 NtPath
->Buffer
= NewBuffer
;
443 NtPath
->MaximumLength
= (USHORT
)DosLength
+ sizeof(UNICODE_NULL
);
444 return STATUS_SUCCESS
;
449 RtlpDosPathNameToRelativeNtPathName_Ustr(IN BOOLEAN HaveRelative
,
450 IN PCUNICODE_STRING DosName
,
451 OUT PUNICODE_STRING NtName
,
452 OUT PCWSTR
*PartName
,
453 OUT PRTL_RELATIVE_NAME_U RelativeName
)
455 WCHAR BigBuffer
[MAX_PATH
+ 1];
456 PWCHAR PrefixBuffer
, NewBuffer
, Buffer
;
457 ULONG MaxLength
, PathLength
, PrefixLength
, PrefixCut
, LengthChars
, Length
;
458 UNICODE_STRING CapturedDosName
, PartNameString
;
460 RTL_PATH_TYPE InputPathType
, BufferPathType
;
464 /* Assume MAX_PATH for now */
465 DPRINT("Relative: %lx DosName: %wZ NtName: %wZ, PartName: %p, RelativeName: %p\n",
466 HaveRelative
, DosName
, NtName
, PartName
, RelativeName
);
467 MaxLength
= sizeof(BigBuffer
);
469 /* Validate the input */
470 if (!DosName
) return STATUS_OBJECT_NAME_INVALID
;
472 /* Capture input string */
473 CapturedDosName
= *DosName
;
475 /* Check for \\?\\ form */
476 if ((CapturedDosName
.Length
<= RtlpWin32NtRootSlash
.Length
) ||
477 (CapturedDosName
.Buffer
[0] != RtlpWin32NtRootSlash
.Buffer
[0]) ||
478 (CapturedDosName
.Buffer
[1] != RtlpWin32NtRootSlash
.Buffer
[1]) ||
479 (CapturedDosName
.Buffer
[2] != RtlpWin32NtRootSlash
.Buffer
[2]) ||
480 (CapturedDosName
.Buffer
[3] != RtlpWin32NtRootSlash
.Buffer
[3]))
482 /* Quick path won't be used */
485 /* Use the static buffer */
487 MaxLength
+= RtlpDosDevicesUncPrefix
.Length
;
489 /* Allocate a buffer to hold the path */
490 NewBuffer
= RtlAllocateHeap(RtlGetProcessHeap(), 0, MaxLength
);
491 DPRINT("Length: %lx\n", MaxLength
);
492 if (!NewBuffer
) return STATUS_NO_MEMORY
;
496 /* Use the optimized path after acquiring the lock */
501 /* Lock the PEB and check if the quick path can be used */
505 /* Some simple fixups will get us the correct path */
506 DPRINT("Quick path\n");
507 Status
= RtlpWin32NTNameToNtPathName_U(&CapturedDosName
,
512 /* Release the lock, we're done here */
517 /* Call the main function to get the full path name and length */
518 PathLength
= RtlGetFullPathName_Ustr(&CapturedDosName
,
519 MAX_PATH
* sizeof(WCHAR
),
524 if ((NameInvalid
) || !(PathLength
) || (PathLength
> (MAX_PATH
* sizeof(WCHAR
))))
526 /* Invalid name, fail */
527 DPRINT("Invalid name: %lx Path Length: %lx\n", NameInvalid
, PathLength
);
528 RtlFreeHeap(RtlGetProcessHeap(), 0, NewBuffer
);
530 return STATUS_OBJECT_NAME_INVALID
;
533 /* Start by assuming the path starts with \??\ (DOS Devices Path) */
534 PrefixLength
= RtlpDosDevicesPrefix
.Length
;
535 PrefixBuffer
= RtlpDosDevicesPrefix
.Buffer
;
538 /* Check where it really is */
539 BufferPathType
= RtlDetermineDosPathNameType_U(Buffer
);
540 DPRINT("Buffer: %S Type: %lx\n", Buffer
, BufferPathType
);
541 switch (BufferPathType
)
543 /* It's actually a UNC path in \??\UNC\ */
544 case RtlPathTypeUncAbsolute
:
545 PrefixLength
= RtlpDosDevicesUncPrefix
.Length
;
546 PrefixBuffer
= RtlpDosDevicesUncPrefix
.Buffer
;
550 case RtlPathTypeLocalDevice
:
551 /* We made a good guess, go with it but skip the \??\ */
555 case RtlPathTypeDriveAbsolute
:
556 case RtlPathTypeDriveRelative
:
557 case RtlPathTypeRooted
:
558 case RtlPathTypeRelative
:
559 /* Our guess was good, roll with it */
562 /* Nothing else is expected */
568 /* Now copy the prefix and the buffer */
569 RtlCopyMemory(NewBuffer
, PrefixBuffer
, PrefixLength
);
570 RtlCopyMemory((PCHAR
)NewBuffer
+ PrefixLength
,
572 PathLength
- (PrefixCut
* sizeof(WCHAR
)));
574 /* Compute the length */
575 Length
= PathLength
- PrefixCut
* sizeof(WCHAR
) + PrefixLength
;
576 LengthChars
= Length
/ sizeof(WCHAR
);
578 /* Setup the actual NT path string and terminate it */
579 NtName
->Buffer
= NewBuffer
;
580 NtName
->Length
= (USHORT
)Length
;
581 NtName
->MaximumLength
= (USHORT
)MaxLength
;
582 NewBuffer
[LengthChars
] = UNICODE_NULL
;
583 DPRINT("new buffer: %S\n", NewBuffer
);
584 DPRINT("NT Name: %wZ\n", NtName
);
586 /* Check if a partial name was requested */
587 if ((PartName
) && (*PartName
))
589 /* Convert to Unicode */
590 Status
= RtlInitUnicodeStringEx(&PartNameString
, *PartName
);
591 if (NT_SUCCESS(Status
))
593 /* Set the partial name */
594 *PartName
= &NewBuffer
[LengthChars
- (PartNameString
.Length
/ sizeof(WCHAR
))];
599 RtlFreeHeap(RtlGetProcessHeap(), 0, NewBuffer
);
605 /* Check if a relative name was asked for */
608 /* Setup the structure */
609 RtlInitEmptyUnicodeString(&RelativeName
->RelativeName
, NULL
, 0);
610 RelativeName
->ContainingDirectory
= NULL
;
611 RelativeName
->CurDirRef
= 0;
613 /* Check if the input path itself was relative */
614 if (InputPathType
== RtlPathTypeRelative
)
616 /* FIXME: HACK: Old code */
619 cd
= (PCURDIR
)&(NtCurrentPeb ()->ProcessParameters
->CurrentDirectory
.DosPath
);
622 RtlInitUnicodeString(&us
, Buffer
);
623 us
.Length
= (cd
->DosPath
.Length
< us
.Length
) ? cd
->DosPath
.Length
: us
.Length
;
624 if (RtlEqualUnicodeString(&us
, &cd
->DosPath
, TRUE
))
626 Length
= ((cd
->DosPath
.Length
/ sizeof(WCHAR
)) - PrefixCut
) + ((InputPathType
== 1) ? 8 : 4);
627 RelativeName
->RelativeName
.Buffer
= NewBuffer
+ Length
;
628 RelativeName
->RelativeName
.Length
= NtName
->Length
- (USHORT
)(Length
* sizeof(WCHAR
));
629 RelativeName
->RelativeName
.MaximumLength
= RelativeName
->RelativeName
.Length
;
630 RelativeName
->ContainingDirectory
= cd
->Handle
;
638 return STATUS_SUCCESS
;
643 RtlpDosPathNameToRelativeNtPathName_U(IN BOOLEAN HaveRelative
,
645 OUT PUNICODE_STRING NtName
,
646 OUT PCWSTR
*PartName
,
647 OUT PRTL_RELATIVE_NAME_U RelativeName
)
650 UNICODE_STRING NameString
;
652 /* Create the unicode name */
653 Status
= RtlInitUnicodeStringEx(&NameString
, DosName
);
654 if (NT_SUCCESS(Status
))
656 /* Call the unicode function */
657 Status
= RtlpDosPathNameToRelativeNtPathName_Ustr(HaveRelative
,
670 RtlDosPathNameToRelativeNtPathName_Ustr(IN PCUNICODE_STRING DosName
,
671 OUT PUNICODE_STRING NtName
,
672 OUT PCWSTR
*PartName
,
673 OUT PRTL_RELATIVE_NAME_U RelativeName
)
675 /* Call the internal function */
676 ASSERT(RelativeName
);
677 return NT_SUCCESS(RtlpDosPathNameToRelativeNtPathName_Ustr(TRUE
,
686 RtlDoesFileExists_UstrEx(IN PCUNICODE_STRING FileName
,
687 IN BOOLEAN SucceedIfBusy
)
690 RTL_RELATIVE_NAME_U RelativeName
;
691 UNICODE_STRING NtPathName
;
693 OBJECT_ATTRIBUTES ObjectAttributes
;
695 FILE_BASIC_INFORMATION BasicInformation
;
697 /* Validate the input */
698 if (!FileName
) return FALSE
;
700 /* Get the NT Path */
701 Result
= RtlDosPathNameToRelativeNtPathName_Ustr(FileName
,
705 if (!Result
) return FALSE
;
707 /* Save the buffer */
708 Buffer
= NtPathName
.Buffer
;
710 /* Check if we have a relative name */
711 if (RelativeName
.RelativeName
.Length
)
714 NtPathName
= RelativeName
.RelativeName
;
718 /* Otherwise ignore it */
719 RelativeName
.ContainingDirectory
= NULL
;
722 /* Initialize the object attributes */
723 InitializeObjectAttributes(&ObjectAttributes
,
725 OBJ_CASE_INSENSITIVE
,
726 RelativeName
.ContainingDirectory
,
729 /* Query the attributes and free the buffer now */
730 Status
= ZwQueryAttributesFile(&ObjectAttributes
, &BasicInformation
);
731 RtlReleaseRelativeName(&RelativeName
);
732 RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer
);
734 /* Check if we failed */
735 if (!NT_SUCCESS(Status
))
737 /* Check if we failed because the file is in use */
738 if ((Status
== STATUS_SHARING_VIOLATION
) ||
739 (Status
== STATUS_ACCESS_DENIED
))
741 /* Check if the caller wants this to be considered OK */
742 Result
= SucceedIfBusy
? TRUE
: FALSE
;
746 /* A failure because the file didn't exist */
752 /* The file exists */
756 /* Return the result */
762 RtlDoesFileExists_UStr(IN PUNICODE_STRING FileName
)
764 /* Call the updated API */
765 return RtlDoesFileExists_UstrEx(FileName
, TRUE
);
770 RtlDoesFileExists_UEx(IN PCWSTR FileName
,
771 IN BOOLEAN SucceedIfBusy
)
773 UNICODE_STRING NameString
;
775 /* Create the unicode name*/
776 if (NT_SUCCESS(RtlInitUnicodeStringEx(&NameString
, FileName
)))
778 /* Call the unicode function */
779 return RtlDoesFileExists_UstrEx(&NameString
, SucceedIfBusy
);
786 /* PUBLIC FUNCTIONS ***********************************************************/
793 RtlReleaseRelativeName(IN PRTL_RELATIVE_NAME_U RelativeName
)
795 /* Check if a directory reference was grabbed */
796 if (RelativeName
->CurDirRef
)
798 /* FIXME: Not yet supported */
800 RelativeName
->CurDirRef
= NULL
;
809 RtlGetLongestNtPathLength(VOID
)
812 * The longest NT path is a DOS path that actually sits on a UNC path (ie:
813 * a mapped network drive), which is accessed through the DOS Global?? path.
814 * This is, and has always been equal to, 269 characters, except in Wine
815 * which claims this is 277. Go figure.
817 return (MAX_PATH
+ RtlpDosDevicesUncPrefix
.Length
+ sizeof(ANSI_NULL
));
825 RtlDetermineDosPathNameType_U(IN PCWSTR Path
)
827 DPRINT("RtlDetermineDosPathNameType_U %S\n", Path
);
829 /* Validate the input */
830 if (!Path
) return RtlPathTypeUnknown
;
832 /* Unlike the newer RtlDetermineDosPathNameType_U we assume 4 characters */
833 if (IS_PATH_SEPARATOR(Path
[0]))
835 if (!IS_PATH_SEPARATOR(Path
[1])) return RtlPathTypeRooted
; /* \x */
836 if ((Path
[2] != L
'.') && (Path
[2] != L
'?')) return RtlPathTypeUncAbsolute
;/* \\x */
837 if (IS_PATH_SEPARATOR(Path
[3])) return RtlPathTypeLocalDevice
; /* \\.\x or \\?\x */
838 if (Path
[3]) return RtlPathTypeUncAbsolute
; /* \\.x or \\?x */
839 return RtlPathTypeRootLocalDevice
; /* \\. or \\? */
843 if (!(Path
[0]) || (Path
[1] != L
':')) return RtlPathTypeRelative
; /* x */
844 if (IS_PATH_SEPARATOR(Path
[2])) return RtlPathTypeDriveAbsolute
; /* x:\ */
845 return RtlPathTypeDriveRelative
; /* x: */
854 RtlIsDosDeviceName_U(IN PWSTR Path
)
856 UNICODE_STRING PathString
;
859 /* Build the string */
860 Status
= RtlInitUnicodeStringEx(&PathString
, Path
);
861 if (!NT_SUCCESS(Status
)) return 0;
864 * Returns 0 if name is not valid DOS device name, or DWORD with
865 * offset in bytes to DOS device name from beginning of buffer in high word
866 * and size in bytes of DOS device name in low word
868 return RtlIsDosDeviceName_Ustr(&PathString
);
876 RtlGetCurrentDirectory_U(IN ULONG MaximumLength
,
882 DPRINT("RtlGetCurrentDirectory %lu %p\n", MaximumLength
, Buffer
);
884 /* Lock the PEB to get the current directory */
886 CurDir
= &NtCurrentPeb()->ProcessParameters
->CurrentDirectory
;
888 /* Get the buffer and character length */
889 CurDirName
= CurDir
->DosPath
.Buffer
;
890 Length
= CurDir
->DosPath
.Length
/ sizeof(WCHAR
);
891 ASSERT((CurDirName
!= NULL
) && (Length
> 0));
894 * DosPath.Buffer should always have a trailing slash. There is an assert
895 * below which checks for this.
897 * This function either returns x:\ for a root (keeping the original buffer)
898 * or it returns x:\path\foo for a directory (replacing the trailing slash
901 Bytes
= Length
* sizeof(WCHAR
);
902 if ((Length
<= 1) || (CurDirName
[Length
- 2] == L
':'))
904 /* Check if caller does not have enough space */
905 if (MaximumLength
<= Bytes
)
907 /* Call has no space for it, fail, add the trailing slash */
909 return Bytes
+ sizeof(OBJ_NAME_PATH_SEPARATOR
);
914 /* Check if caller does not have enough space */
915 if (MaximumLength
< Bytes
)
917 /* Call has no space for it, fail */
923 /* Copy the buffer since we seem to have space */
924 RtlCopyMemory(Buffer
, CurDirName
, Bytes
);
926 /* The buffer should end with a path separator */
927 ASSERT(Buffer
[Length
- 1] == OBJ_NAME_PATH_SEPARATOR
);
929 /* Again check for our two cases (drive root vs path) */
930 if ((Length
<= 1) || (Buffer
[Length
- 2] != L
':'))
932 /* Replace the trailing slash with a null */
933 Buffer
[Length
- 1] = UNICODE_NULL
;
938 /* Append the null char since there's no trailing slash */
939 Buffer
[Length
] = UNICODE_NULL
;
942 /* Release PEB lock */
944 DPRINT("CurrentDirectory %S\n", Buffer
);
945 return Length
* sizeof(WCHAR
);
952 RtlSetCurrentDirectory_U(PUNICODE_STRING dir
)
955 FILE_FS_DEVICE_INFORMATION device_info
;
956 OBJECT_ATTRIBUTES Attr
;
957 IO_STATUS_BLOCK iosb
;
961 HANDLE handle
= NULL
;
964 DPRINT("RtlSetCurrentDirectory %wZ\n", dir
);
968 RtlAcquirePebLock ();
970 cd
= (PCURDIR
)&NtCurrentPeb ()->ProcessParameters
->CurrentDirectory
.DosPath
;
972 if (!RtlDosPathNameToNtPathName_U (dir
->Buffer
, &full
, 0, 0))
974 RtlReleasePebLock ();
975 return STATUS_OBJECT_NAME_INVALID
;
978 DPRINT("RtlSetCurrentDirectory: full %wZ\n",&full
);
980 InitializeObjectAttributes (&Attr
,
982 OBJ_CASE_INSENSITIVE
| OBJ_INHERIT
,
986 Status
= ZwOpenFile (&handle
,
987 SYNCHRONIZE
| FILE_TRAVERSE
,
990 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
991 FILE_DIRECTORY_FILE
| FILE_SYNCHRONOUS_IO_NONALERT
);
993 if (!NT_SUCCESS(Status
))
995 RtlFreeUnicodeString( &full
);
996 RtlReleasePebLock ();
1000 /* don't keep the directory handle open on removable media */
1001 if (NT_SUCCESS(ZwQueryVolumeInformationFile( handle
, &iosb
, &device_info
,
1002 sizeof(device_info
), FileFsDeviceInformation
)) &&
1003 (device_info
.Characteristics
& FILE_REMOVABLE_MEDIA
))
1005 DPRINT1("don't keep the directory handle open on removable media\n");
1011 ZwClose(cd
->Handle
);
1012 cd
->Handle
= handle
;
1014 /* append trailing \ if missing */
1015 size
= full
.Length
/ sizeof(WCHAR
);
1017 ptr
+= 4; /* skip \??\ prefix */
1020 /* This is ok because RtlDosPathNameToNtPathName_U returns a nullterminated string.
1021 * So the nullterm is replaced with \
1024 if (size
&& ptr
[size
- 1] != '\\') ptr
[size
++] = '\\';
1026 memcpy( cd
->DosPath
.Buffer
, ptr
, size
* sizeof(WCHAR
));
1027 cd
->DosPath
.Buffer
[size
] = 0;
1028 cd
->DosPath
.Length
= size
* sizeof(WCHAR
);
1030 RtlFreeUnicodeString( &full
);
1031 RtlReleasePebLock();
1033 return STATUS_SUCCESS
;
1037 /******************************************************************
1040 * Helper for RtlGetFullPathName_U.
1041 * Get rid of . and .. components in the path.
1043 void FORCEINLINE
collapse_path( WCHAR
*path
, UINT mark
)
1047 /* convert every / into a \ */
1048 for (p
= path
; *p
; p
++) if (*p
== '/') *p
= '\\';
1050 /* collapse duplicate backslashes */
1051 next
= path
+ max( 1, mark
);
1052 for (p
= next
; *p
; p
++) if (*p
!= '\\' || next
[-1] != '\\') *next
++ = *p
;
1062 case '\\': /* .\ component */
1064 memmove( p
, next
, (wcslen(next
) + 1) * sizeof(WCHAR
) );
1066 case 0: /* final . */
1067 if (p
> path
+ mark
) p
--;
1071 if (p
[2] == '\\') /* ..\ component */
1074 if (p
> path
+ mark
)
1077 while (p
> path
+ mark
&& p
[-1] != '\\') p
--;
1079 memmove( p
, next
, (wcslen(next
) + 1) * sizeof(WCHAR
) );
1082 else if (!p
[2]) /* final .. */
1084 if (p
> path
+ mark
)
1087 while (p
> path
+ mark
&& p
[-1] != '\\') p
--;
1088 if (p
> path
+ mark
) p
--;
1096 /* skip to the next component */
1097 while (*p
&& *p
!= '\\') p
++;
1100 /* remove last dot in previous dir name */
1101 if (p
> path
+ mark
&& p
[-1] == '.') memmove( p
-1, p
, (wcslen(p
) + 1) * sizeof(WCHAR
) );
1106 /* remove trailing spaces and dots (yes, Windows really does that, don't ask) */
1107 while (p
> path
+ mark
&& (p
[-1] == ' ' || p
[-1] == '.')) p
--;
1113 /******************************************************************
1116 * Skip the \\share\dir\ part of a file name. Helper for RtlGetFullPathName_U.
1118 static const WCHAR
*skip_unc_prefix( const WCHAR
*ptr
)
1121 while (*ptr
&& !IS_PATH_SEPARATOR(*ptr
)) ptr
++; /* share name */
1122 while (IS_PATH_SEPARATOR(*ptr
)) ptr
++;
1123 while (*ptr
&& !IS_PATH_SEPARATOR(*ptr
)) ptr
++; /* dir name */
1124 while (IS_PATH_SEPARATOR(*ptr
)) ptr
++;
1129 /******************************************************************
1130 * get_full_path_helper
1132 * Helper for RtlGetFullPathName_U
1133 * Note: name and buffer are allowed to point to the same memory spot
1135 static ULONG
get_full_path_helper(
1140 SIZE_T reqsize
= 0, mark
= 0, dep
= 0, deplen
;
1141 LPWSTR ins_str
= NULL
;
1143 const UNICODE_STRING
* cd
;
1146 /* return error if name only consists of spaces */
1147 for (ptr
= name
; *ptr
; ptr
++) if (*ptr
!= ' ') break;
1148 if (!*ptr
) return 0;
1150 RtlAcquirePebLock();
1152 //cd = &((PCURDIR)&NtCurrentTeb()->ProcessEnvironmentBlock->ProcessParameters->CurrentDirectory.DosPath)->DosPath;
1153 cd
= &NtCurrentTeb()->ProcessEnvironmentBlock
->ProcessParameters
->CurrentDirectory
.DosPath
;
1155 switch (RtlDetermineDosPathNameType_U(name
))
1157 case RtlPathTypeUncAbsolute
: /* \\foo */
1158 ptr
= skip_unc_prefix( name
);
1159 mark
= (ptr
- name
);
1162 case RtlPathTypeLocalDevice
: /* \\.\foo */
1166 case RtlPathTypeDriveAbsolute
: /* c:\foo */
1167 reqsize
= sizeof(WCHAR
);
1168 tmp
[0] = towupper(name
[0]);
1174 case RtlPathTypeDriveRelative
: /* c:foo */
1176 if (towupper(name
[0]) != towupper(cd
->Buffer
[0]) || cd
->Buffer
[1] != ':')
1178 UNICODE_STRING var
, val
;
1184 var
.Length
= 3 * sizeof(WCHAR
);
1185 var
.MaximumLength
= 4 * sizeof(WCHAR
);
1188 val
.MaximumLength
= (USHORT
)size
;
1189 val
.Buffer
= RtlAllocateHeap(RtlGetProcessHeap(), 0, size
);
1190 if (val
.Buffer
== NULL
)
1196 switch (RtlQueryEnvironmentVariable_U(NULL
, &var
, &val
))
1198 case STATUS_SUCCESS
:
1199 /* FIXME: Win2k seems to check that the environment variable actually points
1200 * to an existing directory. If not, root of the drive is used
1201 * (this seems also to be the only spot in RtlGetFullPathName that the
1202 * existence of a part of a path is checked)
1205 case STATUS_BUFFER_TOO_SMALL
:
1206 reqsize
= val
.Length
+ sizeof(WCHAR
); /* append trailing '\\' */
1207 val
.Buffer
[val
.Length
/ sizeof(WCHAR
)] = '\\';
1208 ins_str
= val
.Buffer
;
1210 case STATUS_VARIABLE_NOT_FOUND
:
1211 reqsize
= 3 * sizeof(WCHAR
);
1216 RtlFreeHeap(RtlGetProcessHeap(), 0, val
.Buffer
);
1219 DPRINT1("Unsupported status code\n");
1220 RtlFreeHeap(RtlGetProcessHeap(), 0, val
.Buffer
);
1228 case RtlPathTypeRelative
: /* foo */
1229 reqsize
= cd
->Length
;
1230 ins_str
= cd
->Buffer
;
1231 if (cd
->Buffer
[1] != ':')
1233 ptr
= skip_unc_prefix( cd
->Buffer
);
1234 mark
= ptr
- cd
->Buffer
;
1239 case RtlPathTypeRooted
: /* \xxx */
1241 if (name
[0] == '/') /* may be a Unix path */
1243 const WCHAR
*ptr
= name
;
1244 int drive
= find_drive_root( &ptr
);
1247 reqsize
= 3 * sizeof(WCHAR
);
1248 tmp
[0] = 'A' + drive
;
1258 if (cd
->Buffer
[1] == ':')
1260 reqsize
= 2 * sizeof(WCHAR
);
1261 tmp
[0] = cd
->Buffer
[0];
1268 ptr
= skip_unc_prefix( cd
->Buffer
);
1269 reqsize
= (ptr
- cd
->Buffer
) * sizeof(WCHAR
);
1270 mark
= reqsize
/ sizeof(WCHAR
);
1271 ins_str
= cd
->Buffer
;
1275 case RtlPathTypeRootLocalDevice
: /* \\. */
1276 reqsize
= 4 * sizeof(WCHAR
);
1286 case RtlPathTypeUnknown
:
1290 /* enough space ? */
1291 deplen
= wcslen(name
+ dep
) * sizeof(WCHAR
);
1292 if (reqsize
+ deplen
+ sizeof(WCHAR
) > size
)
1294 /* not enough space, return need size (including terminating '\0') */
1295 reqsize
+= deplen
+ sizeof(WCHAR
);
1299 memmove(buffer
+ reqsize
/ sizeof(WCHAR
), name
+ dep
, deplen
+ sizeof(WCHAR
));
1300 if (reqsize
) memcpy(buffer
, ins_str
, reqsize
);
1303 if (ins_str
!= tmp
&& ins_str
!= cd
->Buffer
)
1304 RtlFreeHeap(RtlGetProcessHeap(), 0, ins_str
);
1306 collapse_path( buffer
, (ULONG
)mark
);
1307 reqsize
= wcslen(buffer
) * sizeof(WCHAR
);
1310 RtlReleasePebLock();
1311 return (ULONG
)reqsize
;
1315 /******************************************************************
1316 * RtlGetFullPathName_U (NTDLL.@)
1318 * Returns the number of bytes written to buffer (not including the
1319 * terminating NULL) if the function succeeds, or the required number of bytes
1320 * (including the terminating NULL) if the buffer is too small.
1322 * file_part will point to the filename part inside buffer (except if we use
1323 * DOS device name, in which case file_in_buf is NULL)
1327 ULONG NTAPI
RtlGetFullPathName_U(
1337 DPRINT("RtlGetFullPathName_U(%S %lu %p %p)\n", name
, size
, buffer
, file_part
);
1339 if (!name
|| !*name
) return 0;
1341 if (file_part
) *file_part
= NULL
;
1343 /* check for DOS device name */
1344 dosdev
= RtlIsDosDeviceName_U((WCHAR
*)name
);
1347 DWORD offset
= HIWORD(dosdev
) / sizeof(WCHAR
); /* get it in WCHARs, not bytes */
1348 DWORD sz
= LOWORD(dosdev
); /* in bytes */
1350 if (8 + sz
+ 2 > size
) return sz
+ 10;
1351 wcscpy(buffer
, DeviceRootW
);
1352 memmove(buffer
+ 4, name
+ offset
, sz
);
1353 buffer
[4 + sz
/ sizeof(WCHAR
)] = '\0';
1354 /* file_part isn't set in this case */
1358 reqsize
= get_full_path_helper(name
, buffer
, size
);
1359 if (!reqsize
) return 0;
1362 LPWSTR tmp
= RtlAllocateHeap(RtlGetProcessHeap(), 0, reqsize
);
1363 if (tmp
== NULL
) return 0;
1364 reqsize
= get_full_path_helper(name
, tmp
, reqsize
);
1365 if (reqsize
+ sizeof(WCHAR
) > size
) /* it may have worked the second time */
1367 RtlFreeHeap(RtlGetProcessHeap(), 0, tmp
);
1368 return reqsize
+ sizeof(WCHAR
);
1370 memcpy( buffer
, tmp
, reqsize
+ sizeof(WCHAR
) );
1371 RtlFreeHeap(RtlGetProcessHeap(), 0, tmp
);
1374 /* find file part */
1375 if (file_part
&& (ptr
= wcsrchr(buffer
, '\\')) != NULL
&& ptr
>= buffer
+ 2 && *++ptr
)
1385 RtlDosPathNameToNtPathName_U(IN PCWSTR DosName
,
1386 OUT PUNICODE_STRING NtName
,
1387 OUT PCWSTR
*PartName
,
1388 OUT PRTL_RELATIVE_NAME_U RelativeName
)
1390 /* Call the internal function */
1391 return NT_SUCCESS(RtlpDosPathNameToRelativeNtPathName_U(FALSE
,
1403 RtlDosPathNameToNtPathName_U_WithStatus(IN PCWSTR DosName
,
1404 OUT PUNICODE_STRING NtName
,
1405 OUT PCWSTR
*PartName
,
1406 OUT PRTL_RELATIVE_NAME_U RelativeName
)
1408 /* Call the internal function */
1409 return RtlpDosPathNameToRelativeNtPathName_U(FALSE
,
1421 RtlDosPathNameToRelativeNtPathName_U(IN PWSTR DosName
,
1422 OUT PUNICODE_STRING NtName
,
1423 OUT PCWSTR
*PartName
,
1424 OUT PRTL_RELATIVE_NAME_U RelativeName
)
1426 /* Call the internal function */
1427 ASSERT(RelativeName
);
1428 return NT_SUCCESS(RtlpDosPathNameToRelativeNtPathName_U(TRUE
,
1440 RtlDosPathNameToRelativeNtPathName_U_WithStatus(IN PWSTR DosName
,
1441 OUT PUNICODE_STRING NtName
,
1442 OUT PCWSTR
*PartName
,
1443 OUT PRTL_RELATIVE_NAME_U RelativeName
)
1445 /* Call the internal function */
1446 ASSERT(RelativeName
);
1447 return RtlpDosPathNameToRelativeNtPathName_U(TRUE
,
1458 RtlNtPathNameToDosPathName(ULONG Unknown1
, ULONG Unknown2
, ULONG Unknown3
, ULONG Unknown4
)
1460 DPRINT1("RtlNtPathNameToDosPathName: stub\n");
1461 return STATUS_NOT_IMPLEMENTED
;
1469 RtlDosSearchPath_U(IN PCWSTR Path
,
1471 IN PCWSTR Extension
,
1474 OUT PWSTR
*PartName
)
1477 ULONG ExtensionLength
, Length
, FileNameLength
, PathLength
;
1478 UNICODE_STRING TempString
;
1479 PWCHAR NewBuffer
, BufferStart
;
1482 /* Validate the input */
1483 if (!(Path
) || !(FileName
)) return 0;
1485 /* Check if this is an absolute path */
1486 if (RtlDetermineDosPathNameType_U(FileName
) != RtlPathTypeRelative
)
1488 /* Check if the file exists */
1489 if (RtlDoesFileExists_UEx(FileName
, TRUE
))
1491 /* Get the full name, which does the DOS lookup */
1492 return RtlGetFullPathName_U(FileName
, Size
, Buffer
, PartName
);
1495 /* Doesn't exist, so fail */
1499 /* Scan the filename */
1503 /* Looking for an extension */
1506 /* No extension string needed -- it's part of the filename */
1511 /* Next character */
1515 /* Do we have an extension? */
1518 /* Nope, don't worry about one */
1519 ExtensionLength
= 0;
1523 /* Build a temporary string to get the extension length */
1524 Status
= RtlInitUnicodeStringEx(&TempString
, Extension
);
1525 if (!NT_SUCCESS(Status
)) return 0;
1526 ExtensionLength
= TempString
.Length
;
1529 /* Build a temporary string to get the path length */
1530 Status
= RtlInitUnicodeStringEx(&TempString
, Path
);
1531 if (!NT_SUCCESS(Status
)) return 0;
1532 PathLength
= TempString
.Length
;
1534 /* Build a temporary string to get the filename length */
1535 Status
= RtlInitUnicodeStringEx(&TempString
, FileName
);
1536 if (!NT_SUCCESS(Status
)) return 0;
1537 FileNameLength
= TempString
.Length
;
1539 /* Allocate the buffer for the new string name */
1540 NewBuffer
= RtlAllocateHeap(RtlGetProcessHeap(),
1549 DbgPrint("%s: Failing due to out of memory (RtlAllocateHeap failure)\n",
1554 /* Final loop to build the path */
1557 /* Check if we have a valid character */
1558 BufferStart
= NewBuffer
;
1561 /* Loop as long as there's no semicolon */
1562 while (*Path
!= ';')
1564 /* Copy the next character */
1565 *BufferStart
++ = *Path
++;
1569 /* We found a semi-colon, to stop path processing on this loop */
1570 if (*Path
== ';') ++Path
;
1573 /* Add a terminating slash if needed */
1574 if ((BufferStart
!= NewBuffer
) && (BufferStart
[-1] != '\\'))
1576 *BufferStart
++ = '\\';
1579 /* Bail out if we reached the end */
1580 if (!*Path
) Path
= NULL
;
1582 /* Copy the file name and check if an extension is needed */
1583 RtlCopyMemory(BufferStart
, FileName
, FileNameLength
);
1584 if (ExtensionLength
)
1586 /* Copy the extension too */
1587 RtlCopyMemory((PCHAR
)BufferStart
+ FileNameLength
,
1589 ExtensionLength
+ sizeof(WCHAR
));
1593 /* Just NULL-terminate */
1594 *(PWCHAR
)((PCHAR
)BufferStart
+ FileNameLength
) = UNICODE_NULL
;
1597 /* Now, does this file exist? */
1598 if (RtlDoesFileExists_UEx(NewBuffer
, FALSE
))
1600 /* Call the full-path API to get the length */
1601 Length
= RtlGetFullPathName_U(NewBuffer
, Size
, Buffer
, PartName
);
1605 /* If we got here, path doesn't exist, so fail the call */
1610 /* Free the allocation and return the length */
1611 RtlFreeHeap(RtlGetProcessHeap(), 0, NewBuffer
);
1620 RtlGetFullPathName_UstrEx(IN PUNICODE_STRING FileName
,
1621 IN PUNICODE_STRING StaticString
,
1622 IN PUNICODE_STRING DynamicString
,
1623 IN PUNICODE_STRING
*StringUsed
,
1624 IN PSIZE_T FilePartSize
,
1625 OUT PBOOLEAN NameInvalid
,
1626 OUT RTL_PATH_TYPE
* PathType
,
1627 OUT PULONG LengthNeeded
)
1630 PWCHAR StaticBuffer
;
1633 USHORT StaticLength
;
1634 UNICODE_STRING TempDynamicString
;
1636 /* Initialize all our locals */
1638 StaticBuffer
= NULL
;
1639 TempDynamicString
.Buffer
= NULL
;
1641 /* Initialize the input parameters */
1642 if (StringUsed
) *StringUsed
= NULL
;
1643 if (LengthNeeded
) *LengthNeeded
= 0;
1644 if (FilePartSize
) *FilePartSize
= 0;
1646 /* Check for invalid parameters */
1647 if ((DynamicString
) && !(StringUsed
) && (StaticString
))
1649 return STATUS_INVALID_PARAMETER
;
1652 /* Check if we did not get an input string */
1656 StaticLength
= MAX_PATH
* sizeof(WCHAR
);
1657 StaticBuffer
= RtlpAllocateStringMemory(MAX_PATH
* sizeof(WCHAR
), TAG_USTR
);
1658 if (!StaticBuffer
) return STATUS_NO_MEMORY
;
1662 /* Use the one we received */
1663 StaticBuffer
= StaticString
->Buffer
;
1664 StaticLength
= StaticString
->MaximumLength
;
1667 /* Call the lower-level function */
1668 Length
= RtlGetFullPathName_Ustr(FileName
,
1674 DPRINT("Length: %d StaticBuffer: %S\n", Length
, StaticBuffer
);
1677 /* Fail if it failed */
1678 DbgPrint("%s(%d) - RtlGetFullPathName_Ustr() returned 0\n",
1681 Status
= STATUS_OBJECT_NAME_INVALID
;
1685 /* Check if it fits inside our static string */
1686 if ((StaticString
) && (Length
< StaticLength
))
1688 /* Set the final length */
1689 StaticString
->Length
= Length
;
1691 /* Set the file part size */
1692 if (FilePartSize
) *FilePartSize
= ShortName
? (ShortName
- StaticString
->Buffer
) : 0;
1694 /* Return the static string if requested */
1695 if (StringUsed
) *StringUsed
= StaticString
;
1697 /* We are done with success */
1698 Status
= STATUS_SUCCESS
;
1702 /* Did we not have an input dynamic string ?*/
1705 /* Return the length we need */
1706 if (LengthNeeded
) *LengthNeeded
= Length
;
1708 /* And fail such that the caller can try again */
1709 Status
= STATUS_BUFFER_TOO_SMALL
;
1713 /* Check if it fits in our static buffer */
1714 if ((StaticBuffer
) && (Length
< StaticLength
))
1716 /* NULL-terminate it */
1717 StaticBuffer
[Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1719 /* Set the settings for the dynamic string the caller sent */
1720 DynamicString
->MaximumLength
= StaticLength
;
1721 DynamicString
->Length
= Length
;
1722 DynamicString
->Buffer
= StaticBuffer
;
1724 /* Set the part size */
1725 if (FilePartSize
) *FilePartSize
= ShortName
? (ShortName
- StaticBuffer
) : 0;
1727 /* Return the dynamic string if requested */
1728 if (StringUsed
) *StringUsed
= DynamicString
;
1730 /* Do not free the static buffer on exit, and return success */
1731 StaticBuffer
= NULL
;
1732 Status
= STATUS_SUCCESS
;
1736 /* Now try again under the PEB lock */
1737 RtlAcquirePebLock();
1738 Length
= RtlGetFullPathName_Ustr(FileName
,
1747 DbgPrint("%s line %d: RtlGetFullPathName_Ustr() returned 0\n",
1748 __FUNCTION__
, __LINE__
);
1749 Status
= STATUS_OBJECT_NAME_INVALID
;
1753 /* Check if it fits inside our static string now */
1754 if ((StaticString
) && (Length
< StaticLength
))
1756 /* Set the final length */
1757 StaticString
->Length
= Length
;
1759 /* Set the file part size */
1760 if (FilePartSize
) *FilePartSize
= ShortName
? (ShortName
- StaticString
->Buffer
) : 0;
1762 /* Return the static string if requested */
1763 if (StringUsed
) *StringUsed
= StaticString
;
1765 /* We are done with success */
1766 Status
= STATUS_SUCCESS
;
1770 /* Check if the path won't even fit in a real string */
1771 if ((Length
+ sizeof(WCHAR
)) > UNICODE_STRING_MAX_BYTES
)
1773 /* Name is way too long, fail */
1774 Status
= STATUS_NAME_TOO_LONG
;
1778 /* Allocate the string to hold the path name now */
1779 TempDynamicString
.Buffer
= RtlpAllocateStringMemory(Length
+ sizeof(WCHAR
),
1781 if (!TempDynamicString
.Buffer
)
1783 /* Out of memory, fail */
1784 Status
= STATUS_NO_MEMORY
;
1788 /* Add space for a NULL terminator, and now check the full path */
1789 TempDynamicString
.MaximumLength
= Length
+ sizeof(UNICODE_NULL
);
1790 Length
= RtlGetFullPathName_Ustr(FileName
,
1792 TempDynamicString
.Buffer
,
1798 /* Some path error, so fail out */
1799 DbgPrint("%s line %d: RtlGetFullPathName_Ustr() returned 0\n",
1800 __FUNCTION__
, __LINE__
);
1801 Status
= STATUS_OBJECT_NAME_INVALID
;
1805 /* It should fit in the string we just allocated */
1806 ASSERT(Length
< (TempDynamicString
.MaximumLength
- sizeof(WCHAR
)));
1807 if (Length
> TempDynamicString
.MaximumLength
)
1809 /* This is really weird and would mean some kind of race */
1810 Status
= STATUS_INTERNAL_ERROR
;
1814 /* Return the file part size */
1815 if (FilePartSize
) *FilePartSize
= ShortName
? (ShortName
- TempDynamicString
.Buffer
) : 0;
1817 /* Terminate the whole string now */
1818 TempDynamicString
.Buffer
[Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
1820 /* Finalize the string and return it to the user */
1821 DynamicString
->Buffer
= TempDynamicString
.Buffer
;
1822 DynamicString
->Length
= Length
;
1823 DynamicString
->MaximumLength
= TempDynamicString
.MaximumLength
;
1824 if (StringUsed
) *StringUsed
= DynamicString
;
1826 /* Return success and make sure we don't free the buffer on exit */
1827 TempDynamicString
.Buffer
= NULL
;
1828 Status
= STATUS_SUCCESS
;
1831 /* Release the PEB lock */
1832 RtlReleasePebLock();
1835 /* Free any buffers we should be freeing */
1836 DPRINT("Status: %lx %S %S\n", Status
, StaticBuffer
, TempDynamicString
.Buffer
);
1837 if ((StaticBuffer
) && (StaticBuffer
!= StaticString
->Buffer
))
1839 RtlpFreeMemory(StaticBuffer
, TAG_USTR
);
1841 if (TempDynamicString
.Buffer
)
1843 RtlpFreeMemory(TempDynamicString
.Buffer
, TAG_USTR
);
1846 /* Print out any unusual errors */
1847 if ((NT_ERROR(Status
)) &&
1848 (Status
!= STATUS_NO_SUCH_FILE
) && (Status
!= STATUS_BUFFER_TOO_SMALL
))
1850 DbgPrint("RTL: %s - failing on filename %wZ with status %08lx\n",
1851 __FUNCTION__
, FileName
, Status
);
1854 /* Return, we're all done */
1863 RtlDosSearchPath_Ustr(IN ULONG Flags
,
1864 IN PUNICODE_STRING PathString
,
1865 IN PUNICODE_STRING FileNameString
,
1866 IN PUNICODE_STRING ExtensionString
,
1867 IN PUNICODE_STRING CallerBuffer
,
1868 IN OUT PUNICODE_STRING DynamicString OPTIONAL
,
1869 OUT PUNICODE_STRING
* FullNameOut OPTIONAL
,
1870 OUT PULONG FilePartSize OPTIONAL
,
1871 OUT PULONG LengthNeeded OPTIONAL
)
1873 WCHAR StaticCandidateBuffer
[MAX_PATH
];
1874 UNICODE_STRING StaticCandidateString
;
1876 RTL_PATH_TYPE PathType
;
1877 PWCHAR p
, End
, CandidateEnd
, SegmentEnd
;
1878 ULONG SegmentSize
, NamePlusExtLength
, PathSize
, MaxPathSize
= 0, WorstCaseLength
, ByteCount
;
1879 USHORT ExtensionLength
= 0;
1880 PUNICODE_STRING FullIsolatedPath
;
1881 DPRINT("DOS Path Search: %lx %wZ %wZ %wZ %wZ %wZ\n",
1882 Flags
, PathString
, FileNameString
, ExtensionString
, CallerBuffer
, DynamicString
);
1884 /* Initialize the input string */
1885 RtlInitEmptyUnicodeString(&StaticCandidateString
,
1886 StaticCandidateBuffer
,
1887 sizeof(StaticCandidateBuffer
));
1889 /* Initialize optional arguments */
1890 if (FullNameOut
) *FullNameOut
= NULL
;
1891 if (FilePartSize
) *FilePartSize
= 0;
1894 DynamicString
->Length
= DynamicString
->MaximumLength
= 0;
1895 DynamicString
->Buffer
= NULL
;
1898 /* Check for invalid parameters */
1901 !(FileNameString
) ||
1902 ((CallerBuffer
) && (DynamicString
) && !(FullNameOut
)))
1905 DbgPrint("%s: Invalid parameters passed\n", __FUNCTION__
);
1906 Status
= STATUS_INVALID_PARAMETER
;
1910 /* First check what kind of path this is */
1911 PathType
= RtlDetermineDosPathNameType_Ustr(FileNameString
);
1913 /* Check if the caller wants to prevent relative .\ and ..\ paths */
1915 (PathType
== RtlPathTypeRelative
) &&
1916 (FileNameString
->Length
>= (2 * sizeof(WCHAR
))) &&
1917 (FileNameString
->Buffer
[0] == L
'.') &&
1918 ((IS_PATH_SEPARATOR(FileNameString
->Buffer
[1])) ||
1919 ((FileNameString
->Buffer
[1] == L
'.') &&
1920 ((FileNameString
->Length
>= (3 * sizeof(WCHAR
))) &&
1921 (IS_PATH_SEPARATOR(FileNameString
->Buffer
[2]))))))
1923 /* Yes, and this path is like that, so make it seem unknown */
1924 PathType
= RtlPathTypeUnknown
;
1927 /* Now check relative vs non-relative paths */
1928 if (PathType
== RtlPathTypeRelative
)
1930 /* Does the caller want SxS? */
1933 /* Apply the SxS magic */
1934 FullIsolatedPath
= NULL
;
1935 Status
= RtlDosApplyFileIsolationRedirection_Ustr(TRUE
,
1944 if (NT_SUCCESS(Status
))
1946 /* We found the SxS path, return it */
1947 if (FullNameOut
) *FullNameOut
= FullIsolatedPath
;
1950 else if (Status
!= STATUS_SXS_KEY_NOT_FOUND
)
1952 /* Critical SxS error, fail */
1953 DbgPrint("%s: Failing because call to "
1954 "RtlDosApplyIsolationRedirection_Ustr(%wZ) failed with "
1963 /* No SxS key found, or not requested, check if there's an extension */
1964 if (ExtensionString
)
1966 /* Save the extension length, and check if there's a file name */
1967 ExtensionLength
= ExtensionString
->Length
;
1968 if (FileNameString
->Length
)
1970 /* Start parsing the file name */
1971 End
= &FileNameString
->Buffer
[FileNameString
->Length
/ sizeof(WCHAR
)];
1972 while (End
> FileNameString
->Buffer
)
1974 /* If we find a path separator, there's no extension */
1975 if (IS_PATH_SEPARATOR(*--End
)) break;
1977 /* Otherwise, did we find an extension dot? */
1980 /* Ignore what the caller sent it, use the filename's */
1981 ExtensionString
= NULL
;
1982 ExtensionLength
= 0;
1989 /* Check if we got a path */
1990 if (PathString
->Length
)
1992 /* Start parsing the path name, looking for path separators */
1993 End
= &PathString
->Buffer
[PathString
->Length
/ sizeof(WCHAR
)];
1995 while ((p
> PathString
->Buffer
) && (*--p
== L
';'))
1997 /* This is the size of the path -- handle a trailing slash */
1998 PathSize
= End
- p
- 1;
1999 if ((PathSize
) && !(IS_PATH_SEPARATOR(*(End
- 1)))) PathSize
++;
2001 /* Check if we found a bigger path than before */
2002 if (PathSize
> MaxPathSize
) MaxPathSize
= PathSize
;
2004 /* Keep going with the path after this path separator */
2008 /* This is the trailing path, run the same code as above */
2010 if ((PathSize
) && !(IS_PATH_SEPARATOR(*(End
- 1)))) PathSize
++;
2011 if (PathSize
> MaxPathSize
) MaxPathSize
= PathSize
;
2013 /* Finally, convert the largest path size into WCHAR */
2014 MaxPathSize
*= sizeof(WCHAR
);
2017 /* Use the extension, the file name, and the largest path as the size */
2018 WorstCaseLength
= ExtensionLength
+
2019 FileNameString
->Length
+
2021 sizeof(UNICODE_NULL
);
2022 if (WorstCaseLength
> UNICODE_STRING_MAX_BYTES
)
2024 /* It has to fit in a registry string, if not, fail here */
2025 DbgPrint("%s returning STATUS_NAME_TOO_LONG because the computed "
2026 "worst case file name length is %Iu bytes\n",
2029 Status
= STATUS_NAME_TOO_LONG
;
2033 /* Scan the path now, to see if we can find the file */
2034 p
= PathString
->Buffer
;
2035 End
= &p
[PathString
->Length
/ sizeof(WCHAR
)];
2038 /* Find out where this path ends */
2039 for (SegmentEnd
= p
;
2040 ((SegmentEnd
!= End
) && (*SegmentEnd
!= L
';'));
2043 /* Compute the size of this path */
2044 ByteCount
= SegmentSize
= (SegmentEnd
- p
) * sizeof(WCHAR
);
2046 /* Handle trailing slash if there isn't one */
2047 if ((SegmentSize
) && !(IS_PATH_SEPARATOR(*(SegmentEnd
- 1))))
2049 /* Add space for one */
2050 SegmentSize
+= sizeof(OBJ_NAME_PATH_SEPARATOR
);
2053 /* Now check if our initial static buffer is too small */
2054 if (StaticCandidateString
.MaximumLength
<
2055 (SegmentSize
+ ExtensionLength
+ FileNameString
->Length
))
2057 /* At this point we should've been using our static buffer */
2058 ASSERT(StaticCandidateString
.Buffer
== StaticCandidateBuffer
);
2059 if (StaticCandidateString
.Buffer
!= StaticCandidateBuffer
)
2061 /* Something is really messed up if this was the dynamic string */
2062 DbgPrint("%s: internal error #1; "
2063 "CandidateString.Buffer = %p; "
2064 "StaticCandidateBuffer = %p\n",
2066 StaticCandidateString
.Buffer
,
2067 StaticCandidateBuffer
);
2068 Status
= STATUS_INTERNAL_ERROR
;
2072 /* We checked before that the maximum possible size shoudl fit! */
2073 ASSERT((SegmentSize
+ FileNameString
->Length
+ ExtensionLength
) <
2074 UNICODE_STRING_MAX_BYTES
);
2075 if ((SegmentSize
+ ExtensionLength
+ FileNameString
->Length
) >
2076 (UNICODE_STRING_MAX_BYTES
- sizeof(WCHAR
)))
2078 /* For some reason it's not fitting anymore. Something messed up */
2079 DbgPrint("%s: internal error #2; SegmentSize = %u, "
2080 "FileName->Length = %u, DefaultExtensionLength = %u\n",
2083 FileNameString
->Length
,
2085 Status
= STATUS_INTERNAL_ERROR
;
2089 /* Now allocate the dynamic string */
2090 StaticCandidateString
.MaximumLength
= FileNameString
->Length
+
2092 StaticCandidateString
.Buffer
= RtlpAllocateStringMemory(WorstCaseLength
,
2094 if (!StaticCandidateString
.Buffer
)
2096 /* Out of memory, fail */
2097 DbgPrint("%s: Unable to allocate %u byte buffer for path candidate\n",
2099 StaticCandidateString
.MaximumLength
);
2100 Status
= STATUS_NO_MEMORY
;
2105 /* Copy the path in the string */
2106 RtlCopyMemory(StaticCandidateString
.Buffer
, p
, ByteCount
);
2108 /* Get to the end of the string, and add the trailing slash if missing */
2109 CandidateEnd
= &StaticCandidateString
.Buffer
[ByteCount
/ sizeof(WCHAR
)];
2110 if ((SegmentSize
) && (SegmentSize
!= ByteCount
))
2112 *CandidateEnd
++ = OBJ_NAME_PATH_SEPARATOR
;
2115 /* Copy the filename now */
2116 RtlCopyMemory(CandidateEnd
,
2117 FileNameString
->Buffer
,
2118 FileNameString
->Length
);
2119 CandidateEnd
+= (FileNameString
->Length
/ sizeof(WCHAR
));
2121 /* Check if there was an extension */
2122 if (ExtensionString
)
2124 /* Copy the extension too */
2125 RtlCopyMemory(CandidateEnd
,
2126 ExtensionString
->Buffer
,
2127 ExtensionString
->Length
);
2128 CandidateEnd
+= (ExtensionString
->Length
/ sizeof(WCHAR
));
2131 /* We are done, terminate it */
2132 *CandidateEnd
= UNICODE_NULL
;
2134 /* Now set the final length of the string so it becomes valid */
2135 StaticCandidateString
.Length
= (CandidateEnd
-
2136 StaticCandidateString
.Buffer
) *
2139 /* Check if this file exists */
2140 DPRINT("BUFFER: %S\n", StaticCandidateString
.Buffer
);
2141 if (RtlDoesFileExists_UEx(StaticCandidateString
.Buffer
, FALSE
))
2143 /* Awesome, it does, now get the full path */
2144 Status
= RtlGetFullPathName_UstrEx(&StaticCandidateString
,
2147 (PUNICODE_STRING
*)FullNameOut
,
2152 if (!(NT_SUCCESS(Status
)) &&
2153 ((Status
!= STATUS_NO_SUCH_FILE
) &&
2154 (Status
!= STATUS_BUFFER_TOO_SMALL
)))
2156 DbgPrint("%s: Failing because we thought we found %wZ on "
2157 "the search path, but RtlGetfullPathNameUStrEx() "
2162 DPRINT("STatus: %lx BUFFER: %S\n", Status
, CallerBuffer
->Buffer
);
2167 /* Otherwise, move to the next path */
2168 if (SegmentEnd
!= End
)
2170 /* Handle the case of the path separator trailing */
2180 /* Loop finished and we didn't break out -- fail */
2181 Status
= STATUS_NO_SUCH_FILE
;
2185 /* We have a full path, so check if it does exist */
2186 DPRINT("%wZ\n", FileNameString
);
2187 if (!RtlDoesFileExists_UstrEx(FileNameString
, TRUE
))
2189 /* It doesn't exist, did we have an extension? */
2190 if (!(ExtensionString
) || !(ExtensionString
->Length
))
2192 /* No extension, so just fail */
2193 Status
= STATUS_NO_SUCH_FILE
;
2197 /* There was an extension, check if the filename already had one */
2198 if (!(Flags
& 4) && (FileNameString
->Length
))
2200 /* Parse the filename */
2201 p
= FileNameString
->Buffer
;
2202 End
= &p
[FileNameString
->Length
/ sizeof(WCHAR
)];
2205 /* If there's a path separator, there's no extension */
2206 if (IS_PATH_SEPARATOR(*--End
)) break;
2208 /* Othwerwise, did we find an extension dot? */
2211 /* File already had an extension, so fail */
2212 Status
= STATUS_NO_SUCH_FILE
;
2218 /* So there is an extension, we'll try again by adding it */
2219 NamePlusExtLength
= FileNameString
->Length
+
2220 ExtensionString
->Length
+
2221 sizeof(UNICODE_NULL
);
2222 if (NamePlusExtLength
> UNICODE_STRING_MAX_BYTES
)
2224 /* It won't fit in any kind of valid string, so fail */
2225 DbgPrint("%s: Failing because filename plus extension (%Iu bytes) is too big\n",
2228 Status
= STATUS_NAME_TOO_LONG
;
2232 /* Fill it fit in our temporary string? */
2233 if (NamePlusExtLength
> StaticCandidateString
.MaximumLength
)
2235 /* It won't fit anymore, allocate a dynamic string for it */
2236 StaticCandidateString
.MaximumLength
= NamePlusExtLength
;
2237 StaticCandidateString
.Buffer
= RtlpAllocateStringMemory(NamePlusExtLength
,
2239 if (!StaticCandidateString
.Buffer
)
2241 /* Ran out of memory, so fail */
2242 DbgPrint("%s: Failing because allocating the dynamic filename buffer failed\n",
2244 Status
= STATUS_NO_MEMORY
;
2249 /* Copy the filename */
2250 RtlCopyMemory(StaticCandidateString
.Buffer
,
2251 FileNameString
->Buffer
,
2252 FileNameString
->Length
);
2254 /* Copy the extension */
2255 RtlCopyMemory(&StaticCandidateString
.Buffer
[FileNameString
->Length
/ sizeof(WCHAR
)],
2256 ExtensionString
->Buffer
,
2257 ExtensionString
->Length
);
2259 /* Now NULL-terminate */
2260 StaticCandidateString
.Buffer
[StaticCandidateString
.Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
2262 /* Finalize the length of the string to make it valid */
2263 StaticCandidateString
.Length
= FileNameString
->Length
+ ExtensionString
->Length
;
2264 DPRINT("SB: %wZ\n", &StaticCandidateString
);
2266 /* And check if this file now exists */
2267 if (!RtlDoesFileExists_UstrEx(&StaticCandidateString
, TRUE
))
2269 /* Still no joy, fail out */
2270 Status
= STATUS_NO_SUCH_FILE
;
2274 /* File was found, get the final full path */
2275 Status
= RtlGetFullPathName_UstrEx(&StaticCandidateString
,
2278 (PUNICODE_STRING
*)FullNameOut
,
2283 if (!(NT_SUCCESS(Status
)) && (Status
!= STATUS_NO_SUCH_FILE
))
2285 DbgPrint("%s: Failing on \"%wZ\" because RtlGetfullPathNameUStrEx() "
2286 "failed with status %08lx\n",
2288 &StaticCandidateString
,
2291 DPRINT("STatus: %lx BUFFER: %S\n", Status
, CallerBuffer
->Buffer
);
2295 /* File was found on the first try, get the final full path */
2296 Status
= RtlGetFullPathName_UstrEx(FileNameString
,
2299 (PUNICODE_STRING
*)FullNameOut
,
2304 if (!(NT_SUCCESS(Status
)) &&
2305 ((Status
!= STATUS_NO_SUCH_FILE
) &&
2306 (Status
!= STATUS_BUFFER_TOO_SMALL
)))
2308 DbgPrint("%s: Failing because RtlGetfullPathNameUStrEx() on %wZ "
2309 "failed with status %08lx\n",
2314 DPRINT("STatus: %lx BUFFER: %S\n", Status
, CallerBuffer
->Buffer
);
2319 /* Anything that was not an error, turn into STATUS_SUCCESS */
2320 if (NT_SUCCESS(Status
)) Status
= STATUS_SUCCESS
;
2322 /* Check if we had a dynamic string */
2323 if ((StaticCandidateString
.Buffer
) &&
2324 (StaticCandidateString
.Buffer
!= StaticCandidateBuffer
))
2327 RtlFreeUnicodeString(&StaticCandidateString
);
2330 /* Return the status */
2339 RtlDoesFileExists_U(IN PCWSTR FileName
)
2341 /* Call the new function */
2342 return RtlDoesFileExists_UEx(FileName
, TRUE
);