/** @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 <Library/BaseMemoryLib.h>\r
#include <Library/BaseLib.h>\r
**/\r
BOOLEAN\r
EFIAPI\r
-PathRemoveLastItem(\r
- IN OUT CHAR16 *Path\r
+PathRemoveLastItem (\r
+ IN OUT CHAR16 *Path\r
)\r
{\r
- CHAR16 *Walker;\r
- CHAR16 *LastSlash;\r
+ CHAR16 *Walker;\r
+ CHAR16 *LastSlash;\r
+\r
//\r
// get directory name from path... ('chop' off extra)\r
//\r
for ( Walker = Path, LastSlash = NULL\r
- ; Walker != NULL && *Walker != CHAR_NULL\r
- ; Walker++\r
- ){\r
- if (*Walker == L'\\' && *(Walker + 1) != CHAR_NULL) {\r
+ ; Walker != NULL && *Walker != CHAR_NULL\r
+ ; Walker++\r
+ )\r
+ {\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
+ } else if ((*Walker == L':') && (*(Walker + 1) != L'\\') && (*(Walker + 1) != CHAR_NULL)) {\r
LastSlash = Walker+1;\r
}\r
}\r
+\r
if (LastSlash != NULL) {\r
*LastSlash = CHAR_NULL;\r
return (TRUE);\r
}\r
+\r
return (FALSE);\r
}\r
\r
\r
@param[in] Path The pointer to the string containing the path.\r
\r
- @return Returns Path, otherwise returns NULL to indicate that an error has occured.\r
+ @return Returns Path, otherwise returns NULL to indicate that an error has occurred.\r
**/\r
-CHAR16*\r
+CHAR16 *\r
EFIAPI\r
-PathCleanUpDirectories(\r
- IN CHAR16 *Path\r
-)\r
+PathCleanUpDirectories (\r
+ IN CHAR16 *Path\r
+ )\r
{\r
CHAR16 *TempString;\r
\r
}\r
}\r
\r
+ //\r
+ // Replace the "\\" with "\"\r
+ //\r
+ while ((TempString = StrStr (Path, L"\\\\")) != NULL) {\r
+ CopyMem (TempString, TempString + 1, StrSize (TempString + 1));\r
+ }\r
+\r
//\r
// Remove all the "\.". E.g.: fs0:\abc\.\def\.\r
//\r
while ((TempString = StrStr (Path, L"\\.\\")) != NULL) {\r
CopyMem (TempString, TempString + 2, StrSize (TempString + 2));\r
}\r
- if (StrCmp (Path + StrLen (Path) - 2, L"\\.") == 0) {\r
+\r
+ if ((StrLen (Path) >= 2) && (StrCmp (Path + StrLen (Path) - 2, L"\\.") == 0)) {\r
Path[StrLen (Path) - 1] = CHAR_NULL;\r
}\r
\r
//\r
// Remove all the "\..". E.g.: fs0:\abc\..\def\..\r
//\r
- while (((TempString = StrStr(Path, L"\\..")) != NULL) &&\r
+ while (((TempString = StrStr (Path, L"\\..")) != NULL) &&\r
((*(TempString + 3) == L'\\') || (*(TempString + 3) == CHAR_NULL))\r
- ) {\r
+ )\r
+ {\r
*(TempString + 1) = CHAR_NULL;\r
- PathRemoveLastItem(Path);\r
- CopyMem (Path + StrLen (Path), TempString + 3, StrSize (TempString + 3));\r
- }\r
-\r
- //\r
- // Replace the "\\" with "\"\r
- //\r
- while ((TempString = StrStr (Path, L"\\\\")) != NULL) {\r
- CopyMem (TempString, TempString + 1, StrSize (TempString + 1));\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
}\r
-\r