[NTOSKRNL]
[reactos.git] / reactos / ntoskrnl / fsrtl / dbcsname.c
index 64359a5..cdde126 100644 (file)
@@ -48,6 +48,7 @@ FsRtlDissectDbcs(IN ANSI_STRING Name,
 {
     ULONG FirstPosition, i;
     ULONG SkipFirstSlash = 0;
+    PAGED_CODE();
 
     /* Zero the strings before continuing */
     RtlZeroMemory(FirstPart, sizeof(ANSI_STRING));
@@ -116,6 +117,7 @@ NTAPI
 FsRtlDoesDbcsContainWildCards(IN PANSI_STRING Name)
 {
     ULONG i;
+    PAGED_CODE();
 
     /* Check every character */
     for (i = 0; i < Name->Length; i++)
@@ -150,7 +152,7 @@ FsRtlDoesDbcsContainWildCards(IN PANSI_STRING Name)
  *
  * @return TRUE if Name is found in Expression, FALSE otherwise
  *
- * @remarks None
+ * @remarks
  *
  *--*/
 BOOLEAN
@@ -158,52 +160,78 @@ NTAPI
 FsRtlIsDbcsInExpression(IN PANSI_STRING Expression,
                         IN PANSI_STRING Name)
 {
-    ULONG ExpressionPosition, NamePosition, MatchingChars = 0;
+    USHORT ExpressionPosition = 0, NamePosition = 0, MatchingChars, StarFound = MAXUSHORT;
+    PAGED_CODE();
 
+    ASSERT(Name->Length);
+    ASSERT(Expression->Length);
     ASSERT(!FsRtlDoesDbcsContainWildCards(Name));
 
-    /* One can't be null, both can be */
-    if (!Expression->Length || !Name->Length)
-    {
-        return !(Expression->Length ^ Name->Length);
-    }
-
-    for (ExpressionPosition = 0; ExpressionPosition < Expression->Length; ExpressionPosition++)
+    while (NamePosition < Name->Length && ExpressionPosition < Expression->Length)
     {
-        if ((Expression->Buffer[ExpressionPosition] == Name->Buffer[MatchingChars]) ||
-            (Expression->Buffer[ExpressionPosition] == '?') ||
-            (Expression->Buffer[ExpressionPosition] == ANSI_DOS_QM) ||
-            (Expression->Buffer[ExpressionPosition] == ANSI_DOS_DOT &&
-            (Name->Buffer[MatchingChars] == '.' || Name->Buffer[MatchingChars] == '0')))
+        if ((Expression->Buffer[ExpressionPosition] == Name->Buffer[NamePosition]))
+        {
+            NamePosition++;
+            ExpressionPosition++;
+        }
+        else if ((Expression->Buffer[ExpressionPosition] == '?') || (Expression->Buffer[ExpressionPosition] == ANSI_DOS_QM) ||
+                 (Expression->Buffer[ExpressionPosition] == ANSI_DOS_DOT && Name->Buffer[NamePosition] == '.'))
         {
-            MatchingChars++;
+            NamePosition++;
+            ExpressionPosition++;
+            StarFound = MAXUSHORT;
         }
         else if (Expression->Buffer[ExpressionPosition] == '*')
         {
-            MatchingChars = Name->Length;
+            StarFound = ExpressionPosition++;
+            if (StarFound < (Expression->Length - 1))
+            {
+                while (Name->Buffer[NamePosition] != Expression->Buffer[ExpressionPosition] &&
+                       NamePosition < Name->Length)
+                {
+                    NamePosition++;
+                }
+            }
+            else
+            {
+                NamePosition = Name->Length;
+            }
         }
         else if (Expression->Buffer[ExpressionPosition] == ANSI_DOS_STAR)
         {
-            for (NamePosition = MatchingChars; NamePosition < Name->Length; NamePosition++)
+            StarFound = MAXUSHORT;
+            MatchingChars = NamePosition;
+            while (MatchingChars < Name->Length)
             {
-                if (Name->Buffer[NamePosition] == '.')
+                if (Name->Buffer[MatchingChars] == '.')
                 {
-                    MatchingChars = NamePosition;
-                    break;
+                    NamePosition = MatchingChars;
                 }
+                MatchingChars++;
             }
+            ExpressionPosition++;
         }
-        else
+        else if (StarFound != MAXUSHORT)
         {
-            MatchingChars = 0;
+            ExpressionPosition = StarFound + 1;
+            while (Name->Buffer[NamePosition] != Expression->Buffer[ExpressionPosition] &&
+                   NamePosition < Name->Length)
+            {
+                NamePosition++;
+            }
         }
-        if (MatchingChars == Name->Length)
+        else
         {
-            return TRUE;
+            NamePosition = Name->Length;
         }
     }
+    if (ExpressionPosition + 1 == Expression->Length && NamePosition == Name->Length &&
+        Expression->Buffer[ExpressionPosition] == ANSI_DOS_DOT)
+    {
+        ExpressionPosition++;
+    }
 
-    return FALSE;
+    return (ExpressionPosition == Expression->Length && NamePosition == Name->Length);
 }
 
 /*++
@@ -242,6 +270,7 @@ FsRtlIsFatDbcsLegal(IN ANSI_STRING DbcsName,
     ANSI_STRING FirstPart, RemainingPart, Name;
     BOOLEAN LastDot;
     ULONG i;
+    PAGED_CODE();
 
     /* Just quit if the string is empty */
     if (!DbcsName.Length)
@@ -378,6 +407,7 @@ FsRtlIsHpfsDbcsLegal(IN ANSI_STRING DbcsName,
 {
     ANSI_STRING FirstPart, RemainingPart, Name;
     ULONG i;
+    PAGED_CODE();
 
     /* Just quit if the string is empty */
     if (!DbcsName.Length)