]>
git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/BasePathLib/BasePathLib.c
2 Provides interface to path manipulation functions.
4 Copyright (c) 2011, 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>
20 Removes the last directory or file entry in a path by changing the last
23 @param[in, out] Path The pointer to the path to modify.
25 @retval FALSE Nothing was found to remove.
26 @retval TRUE A directory or file was removed.
37 // get directory name from path... ('chop' off extra)
39 for ( Walker
= Path
, LastSlash
= NULL
40 ; Walker
!= NULL
&& *Walker
!= CHAR_NULL
43 if (*Walker
== L
'\\' && *(Walker
+ 1) != CHAR_NULL
) {
47 if (LastSlash
!= NULL
) {
48 *LastSlash
= CHAR_NULL
;
55 Function to clean up paths.
57 - Single periods in the path are removed.
58 - Double periods in the path are removed along with a single parent directory.
59 - Forward slashes L'/' are converted to backward slashes L'\'.
61 This will be done inline and the existing buffer may be larger than required
64 @param[in] Path The pointer to the string containing the path.
66 @retval NULL An error occured.
67 @return Path in all other instances.
71 PathCleanUpDirectories(
82 // Fix up the '/' vs '\'
84 for (TempString
= Path
; TempString
!= NULL
&& *TempString
!= CHAR_NULL
; TempString
++) {
85 if (*TempString
== L
'/') {
93 while ((TempString
= StrStr(Path
, L
"\\..\\")) != NULL
) {
94 *TempString
= CHAR_NULL
;
96 PathRemoveLastItem(Path
);
97 TempSize
= StrSize(TempString
);
98 CopyMem(Path
+StrLen(Path
), TempString
, TempSize
);
100 if ((TempString
= StrStr(Path
, L
"\\..")) != NULL
&& *(TempString
+ 3) == CHAR_NULL
) {
101 *TempString
= CHAR_NULL
;
102 PathRemoveLastItem(Path
);
108 while ((TempString
= StrStr(Path
, L
"\\.\\")) != NULL
) {
109 *TempString
= CHAR_NULL
;
111 TempSize
= StrSize(TempString
);
112 CopyMem(Path
+StrLen(Path
), TempString
, TempSize
);
114 if ((TempString
= StrStr(Path
, L
"\\.")) != NULL
&& *(TempString
+ 2) == CHAR_NULL
) {
115 *TempString
= CHAR_NULL
;