]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/FilePaths.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseLib / FilePaths.c
index c8da6bb3ea7fc87d330d15b0626f84da6a98e784..40e8d773ce7f5943c25661d87916ebbbd8254bf4 100644 (file)
@@ -1,24 +1,16 @@
 /** @file\r
   Defines file-path manipulation functions.\r
 \r
-  Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2018, Dell Technologies. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 **/\r
-#include  <Uefi/UefiBaseType.h>\r
 #include  <Library/BaseMemoryLib.h>\r
 #include  <Library/BaseLib.h>\r
-#include  <Protocol/SimpleTextIn.h>\r
 \r
 /**\r
-  Removes the last directory or file entry in a path by changing the last\r
-  L'\' to a CHAR_NULL. For a path which is like L"fs0:startup.nsh",\r
-  it's converted to L"fs0:".\r
+  Removes the last directory or file entry in a path. For a path which is\r
+  like L"fs0:startup.nsh", it's converted to L"fs0:".\r
 \r
   @param[in,out] Path     A pointer to the path to modify.\r
 \r
@@ -40,7 +32,9 @@ PathRemoveLastItem(
       ; Walker != NULL && *Walker != CHAR_NULL\r
       ; Walker++\r
      ){\r
-    if ((*Walker == L'\\' || *Walker == L':') && *(Walker + 1) != CHAR_NULL) {\r
+    if (*Walker == L'\\' && *(Walker + 1) != CHAR_NULL) {\r
+      LastSlash = Walker+1;\r
+    } else if (*Walker == L':' && *(Walker + 1) != L'\\' && *(Walker + 1) != CHAR_NULL) {\r
       LastSlash = Walker+1;\r
     }\r
   }\r
@@ -69,61 +63,53 @@ CHAR16*
 EFIAPI\r
 PathCleanUpDirectories(\r
   IN CHAR16 *Path\r
-  )\r
+)\r
 {\r
   CHAR16  *TempString;\r
-  UINTN   TempSize;\r
 \r
-  if (Path==NULL) {\r
-    return(NULL);\r
+  if (Path == NULL) {\r
+    return NULL;\r
   }\r
+\r
   //\r
-  // Fix up the '/' vs '\'\r
+  // Replace the '/' with '\'\r
   //\r
-  for (TempString = Path ; TempString != NULL && *TempString != CHAR_NULL ; TempString++) {\r
+  for (TempString = Path; *TempString != CHAR_NULL; TempString++) {\r
     if (*TempString == L'/') {\r
       *TempString = L'\\';\r
     }\r
   }\r
+\r
   //\r
-  // Fix up the ..\r
+  // Replace the "\\" with "\"\r
   //\r
-  while ((TempString = StrStr(Path, L"\\..\\")) != NULL) {\r
-    *TempString = CHAR_NULL;\r
-    TempString  += 4;\r
-    PathRemoveLastItem(Path);\r
-    TempSize = StrSize(TempString);\r
-    CopyMem(Path+StrLen(Path), TempString, TempSize);\r
-  }\r
-  if ((TempString = StrStr(Path, L"\\..")) != NULL && *(TempString + 3) == CHAR_NULL) {\r
-    *TempString = CHAR_NULL;\r
-    if (!PathRemoveLastItem(Path)) {\r
-      *TempString = L'\\';\r
-    }\r
+  while ((TempString = StrStr (Path, L"\\\\")) != NULL) {\r
+    CopyMem (TempString, TempString + 1, StrSize (TempString + 1));\r
   }\r
+\r
   //\r
-  // Fix up the .\r
+  // Remove all the "\.". E.g.: fs0:\abc\.\def\.\r
   //\r
-  while ((TempString = StrStr(Path, L"\\.\\")) != NULL) {\r
-    *TempString = CHAR_NULL;\r
-    TempString  += 2;\r
-    TempSize = StrSize(TempString);\r
-    CopyMem(Path+StrLen(Path), TempString, TempSize);\r
+  while ((TempString = StrStr (Path, L"\\.\\")) != NULL) {\r
+    CopyMem (TempString, TempString + 2, StrSize (TempString + 2));\r
   }\r
-  if ((TempString = StrStr(Path, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) {\r
-    *(TempString + 1) = CHAR_NULL;\r
+  if ((StrLen (Path) >= 2) && (StrCmp (Path + StrLen (Path) - 2, L"\\.") == 0)) {\r
+    Path[StrLen (Path) - 1] = CHAR_NULL;\r
   }\r
 \r
-  while ((TempString = StrStr(Path, L"\\\\")) != NULL) {\r
-    *TempString = CHAR_NULL;\r
-    TempString  += 1;\r
-    TempSize = StrSize(TempString);\r
-    CopyMem(Path+StrLen(Path), TempString, TempSize);\r
-  }\r
-  if ((TempString = StrStr(Path, L"\\\\")) != NULL && *(TempString + 1) == CHAR_NULL) {\r
-    *(TempString) = CHAR_NULL;\r
+  //\r
+  // Remove all the "\..". E.g.: fs0:\abc\..\def\..\r
+  //\r
+  while (((TempString = StrStr(Path, L"\\..")) != NULL) &&\r
+         ((*(TempString + 3) == L'\\') || (*(TempString + 3) == CHAR_NULL))\r
+        ) {\r
+    *(TempString + 1) = CHAR_NULL;\r
+    PathRemoveLastItem(Path);\r
+    if (*(TempString + 3) != CHAR_NULL) {\r
+      CopyMem (Path + StrLen (Path), TempString + 4, StrSize (TempString + 4));\r
+    }\r
   }\r
 \r
-  return (Path);\r
+  return Path;\r
 }\r
 \r