ReactOS  0.4.15-dev-3173-g40ee59d
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;
532  case RtlPathTypeRooted:
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 }
#define RTL_FIND_CHAR_IN_UNICODE_STRING_START_AT_END
Definition: rtl.h:25
RTL_PATH_TYPE NTAPI RtlDetermineDosPathNameType_Ustr(IN PCUNICODE_STRING PathString)
Definition: path.c:61
enum _RTL_PATH_TYPE RTL_PATH_TYPE
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
static COORD Position
Definition: mouse.c:34
#define IS_PATH_SEPARATOR(x)
Definition: path.c:24
NTSTATUS NTAPI RtlFindCharInUnicodeString(_In_ ULONG Flags, _In_ PCUNICODE_STRING SearchString, _In_ PCUNICODE_STRING MatchString, _Out_ PUSHORT Position)
static IN ULONG IN PWSTR OUT PCWSTR OUT PBOOLEAN OUT PATH_TYPE_AND_UNKNOWN * PathType
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
PRTL_UNICODE_STRING_BUFFER Path
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by START_TEST().

◆ START_TEST()

Definition at line 75 of file RtlGetLengthWithoutLastFullDosOrNtPathElement.c.

76 {
77  UNICODE_STRING Dum;
79  ULONG Length;
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 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
GLdouble n
Definition: glext.h:7729
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define ok_hex(expression, result)
Definition: atltest.h:94
#define ok_int(expression, result)
Definition: atltest.h:134
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
PRTL_UNICODE_STRING_BUFFER Path
#define ok(value,...)
Definition: atltest.h:57
NTSTATUS NTAPI RtlGetLengthWithoutLastFullDosOrNtPathElement(IN ULONG Flags, IN PCUNICODE_STRING Path, OUT PULONG LengthOut)
Definition: path.c:496
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

Variable Documentation

◆ tests

rtl_test_data tests[]

Definition at line 27 of file RtlGetLengthWithoutLastFullDosOrNtPathElement.c.

Referenced by START_TEST().