]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/FilePaths.c
2 Defines file-path manipulation functions.
4 Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #include <Library/BaseMemoryLib.h>
14 #include <Library/BaseLib.h>
17 Removes the last directory or file entry in a path. For a path which is
18 like L"fs0:startup.nsh", it's converted to L"fs0:".
20 @param[in,out] Path A pointer to the path to modify.
22 @retval FALSE Nothing was found to remove.
23 @retval TRUE A directory or file was removed.
34 // get directory name from path... ('chop' off extra)
36 for ( Walker
= Path
, LastSlash
= NULL
37 ; Walker
!= NULL
&& *Walker
!= CHAR_NULL
40 if (*Walker
== L
'\\' && *(Walker
+ 1) != CHAR_NULL
) {
42 } else if (*Walker
== L
':' && *(Walker
+ 1) != L
'\\' && *(Walker
+ 1) != CHAR_NULL
) {
46 if (LastSlash
!= NULL
) {
47 *LastSlash
= CHAR_NULL
;
54 Function to clean up paths.
56 - Single periods in the path are removed.
57 - Double periods in the path are removed along with a single parent directory.
58 - Forward slashes L'/' are converted to backward slashes L'\'.
60 This will be done inline and the existing buffer may be larger than required
63 @param[in] Path The pointer to the string containing the path.
65 @return Returns Path, otherwise returns NULL to indicate that an error has occured.
69 PathCleanUpDirectories(
80 // Replace the '/' with '\'
82 for (TempString
= Path
; *TempString
!= CHAR_NULL
; TempString
++) {
83 if (*TempString
== L
'/') {
89 // Remove all the "\.". E.g.: fs0:\abc\.\def\.
91 while ((TempString
= StrStr (Path
, L
"\\.\\")) != NULL
) {
92 CopyMem (TempString
, TempString
+ 2, StrSize (TempString
+ 2));
94 if (StrCmp (Path
+ StrLen (Path
) - 2, L
"\\.") == 0) {
95 Path
[StrLen (Path
) - 1] = CHAR_NULL
;
99 // Remove all the "\..". E.g.: fs0:\abc\..\def\..
101 while (((TempString
= StrStr(Path
, L
"\\..")) != NULL
) &&
102 ((*(TempString
+ 3) == L
'\\') || (*(TempString
+ 3) == CHAR_NULL
))
104 *(TempString
+ 1) = CHAR_NULL
;
105 PathRemoveLastItem(Path
);
106 CopyMem (Path
+ StrLen (Path
), TempString
+ 3, StrSize (TempString
+ 3));
110 // Replace the "\\" with "\"
112 while ((TempString
= StrStr (Path
, L
"\\\\")) != NULL
) {
113 CopyMem (TempString
, TempString
+ 1, StrSize (TempString
+ 1));