]>
git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/BasePathLib/BasePathLib.c
cc46c0fc33122baadfa58f4e20e8778d5aea3056
2 Provides interface to path manipulation functions.
4 Copyright (c) 2011 - 2014, 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.
15 #include <Library/BaseMemoryLib.h>
16 #include <Library/PathLib.h>
17 #include <Library/BaseLib.h>
18 #include <Protocol/SimpleTextIn.h>
21 Removes the last directory or file entry in a path by changing the last
24 @param[in, out] Path The pointer to the path to modify.
26 @retval FALSE Nothing was found to remove.
27 @retval TRUE A directory or file was removed.
38 // get directory name from path... ('chop' off extra)
40 for ( Walker
= Path
, LastSlash
= NULL
41 ; Walker
!= NULL
&& *Walker
!= CHAR_NULL
44 if (*Walker
== L
'\\' && *(Walker
+ 1) != CHAR_NULL
) {
48 if (LastSlash
!= NULL
) {
49 *LastSlash
= CHAR_NULL
;
56 Function to clean up paths.
58 - Single periods in the path are removed.
59 - Double periods in the path are removed along with a single parent directory.
60 - Forward slashes L'/' are converted to backward slashes L'\'.
62 This will be done inline and the existing buffer may be larger than required
65 @param[in] Path The pointer to the string containing the path.
67 @retval NULL An error occured.
68 @return Path in all other instances.
72 PathCleanUpDirectories(
83 // Fix up the '/' vs '\'
85 for (TempString
= Path
; TempString
!= NULL
&& *TempString
!= CHAR_NULL
; TempString
++) {
86 if (*TempString
== L
'/') {
94 while ((TempString
= StrStr(Path
, L
"\\..\\")) != NULL
) {
95 *TempString
= CHAR_NULL
;
97 PathRemoveLastItem(Path
);
98 TempSize
= StrSize(TempString
);
99 CopyMem(Path
+StrLen(Path
), TempString
, TempSize
);
101 if ((TempString
= StrStr(Path
, L
"\\..")) != NULL
&& *(TempString
+ 3) == CHAR_NULL
) {
102 *TempString
= CHAR_NULL
;
103 PathRemoveLastItem(Path
);
109 while ((TempString
= StrStr(Path
, L
"\\.\\")) != NULL
) {
110 *TempString
= CHAR_NULL
;
112 TempSize
= StrSize(TempString
);
113 CopyMem(Path
+StrLen(Path
), TempString
, TempSize
);
115 if ((TempString
= StrStr(Path
, L
"\\.")) != NULL
&& *(TempString
+ 2) == CHAR_NULL
) {
116 *(TempString
+ 1) = CHAR_NULL
;