ReactOS 0.4.15-dev-8235-gcd88a97
RtlGetLengthWithoutLastFullDosOrNtPathElement.c File Reference
#include "precomp.h"
Include dependency graph for RtlGetLengthWithoutLastFullDosOrNtPathElement.c:

Go to the source code of this file.

Classes

struct  _rtl_test_data
 

Typedefs

typedef struct _rtl_test_data rtl_test_data
 

Functions

NTSTATUS NTAPI RtlGetLengthWithoutLastFullDosOrNtPathElement (IN ULONG Flags, IN PCUNICODE_STRING Path, OUT PULONG LengthOut)
 
 START_TEST (RtlGetLengthWithoutLastFullDosOrNtPathElement)
 

Variables

rtl_test_data tests []
 

Typedef Documentation

◆ rtl_test_data

Function Documentation

◆ RtlGetLengthWithoutLastFullDosOrNtPathElement()

NTSTATUS NTAPI RtlGetLengthWithoutLastFullDosOrNtPathElement ( IN ULONG  Flags,
IN PCUNICODE_STRING  Path,
OUT PULONG  LengthOut 
)

Definition at line 496 of file path.c.

499{
500 static const UNICODE_STRING PathDividers = RTL_CONSTANT_STRING(L"\\/");
503
504 /* All failure paths have this in common, so simplify code */
505 if (LengthOut)
506 *LengthOut = 0;
507
508 if (Flags || !Path || !LengthOut)
509 {
511 }
512
513 if ((Path->Length / sizeof(WCHAR)) == 0)
514 {
515 /* Nothing to do here */
516 return STATUS_SUCCESS;
517 }
518
519
521 switch (PathType)
522 {
524 // Handle \\\\?\\C:\\ with the last ':' or '\\' missing:
525 if (Path->Length / sizeof(WCHAR) < 7 ||
526 Path->Buffer[5] != ':' ||
527 !IS_PATH_SEPARATOR(Path->Buffer[6]))
528 {
530 }
531 break;
533 // "\\??\\"
534 break;
536 // "\\\\"
537 break;
539 // "C:\\"
540 break;
541 default:
543 }
544
545 /* Find the last path separator */
547 Position = 0;
548
549 /* Is it the last char of the string? */
550 if (Position && Position + sizeof(WCHAR) == Path->Length)
551 {
552 UNICODE_STRING Tmp = *Path;
553 Tmp.Length = Position;
554
555 /* Keep walking path separators to eliminate multiple next to eachother */
556 while (Tmp.Length > sizeof(WCHAR) && IS_PATH_SEPARATOR(Tmp.Buffer[Tmp.Length / sizeof(WCHAR)]))
557 Tmp.Length -= sizeof(WCHAR);
558
559 /* Find the previous occurence */
561 Position = 0;
562 }
563
564 /* Simplify code by working in chars instead of bytes */
565 if (Position)
566 Position /= sizeof(WCHAR);
567
568 if (Position)
569 {
570 // Keep walking path separators to eliminate multiple next to eachother, but ensure we leave one in place!
571 while (Position > 1 && IS_PATH_SEPARATOR(Path->Buffer[Position - 1]))
572 Position--;
573 }
574
575 if (Position > 0)
576 {
577 /* Return a length, not an index */
578 *LengthOut = Position + 1;
579 }
580
581 return STATUS_SUCCESS;
582}
static IN ULONG IN PWSTR OUT PCWSTR OUT PBOOLEAN OUT PATH_TYPE_AND_UNKNOWN * PathType
PRTL_UNICODE_STRING_BUFFER Path
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
@ RtlPathTypeUncAbsolute
Definition: rtltypes.h:472
@ RtlPathTypeRooted
Definition: rtltypes.h:475
@ RtlPathTypeLocalDevice
Definition: rtltypes.h:477
@ RtlPathTypeDriveAbsolute
Definition: rtltypes.h:473
enum _RTL_PATH_TYPE RTL_PATH_TYPE
#define RTL_FIND_CHAR_IN_UNICODE_STRING_START_AT_END
Definition: rtl.h:25
NTSTATUS NTAPI RtlFindCharInUnicodeString(_In_ ULONG Flags, _In_ PCUNICODE_STRING SearchString, _In_ PCUNICODE_STRING MatchString, _Out_ PUSHORT Position)
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
RTL_PATH_TYPE NTAPI RtlDetermineDosPathNameType_Ustr(IN PCUNICODE_STRING PathString)
Definition: path.c:61
#define IS_PATH_SEPARATOR(x)
Definition: path.c:24
#define STATUS_SUCCESS
Definition: shellext.h:65
static COORD Position
Definition: mouse.c:34
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ START_TEST()

Definition at line 75 of file RtlGetLengthWithoutLastFullDosOrNtPathElement.c.

76{
80 RtlInitUnicodeString(&Dum, L"c:\\test\\");
81
82 Length = 333;
84 ok_int(Length, 0);
86
89
90 for (ULONG n = 0; n < 32; ++n)
91 {
92 Length = 333;
94 ok_int(Length, 0);
96 }
97
98 for (ULONG n = 0; n < ARRAYSIZE(tests); ++n)
99 {
101 Length = 333;
102
104
106 ok(Status == tests[n].Status, "Got Status=0x%lx, expected 0x%lx (%S)\n", Status, tests[n].Status, Str.Buffer);
107 ok(Length == tests[n].Length, "Got Length=0x%lx, expected 0x%lx (%S)\n", Length, tests[n].Length, Str.Buffer);
108 }
109}
NTSTATUS NTAPI RtlGetLengthWithoutLastFullDosOrNtPathElement(IN ULONG Flags, IN PCUNICODE_STRING Path, OUT PULONG LengthOut)
Definition: path.c:496
#define ok_hex(expression, result)
Definition: atltest.h:94
#define ok(value,...)
Definition: atltest.h:57
#define ok_int(expression, result)
Definition: atltest.h:134
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
Status
Definition: gdiplustypes.h:25
GLdouble n
Definition: glext.h:7729
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
uint32_t ULONG
Definition: typedefs.h:59

Variable Documentation

◆ tests

rtl_test_data tests[]

Definition at line 27 of file RtlGetLengthWithoutLastFullDosOrNtPathElement.c.

Referenced by START_TEST().