]>
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 by changing the last
18 L'\' to a CHAR_NULL. For a path which is like L"fs0:startup.nsh",
19 it's converted to L"fs0:".
21 @param[in,out] Path A pointer to the path to modify.
23 @retval FALSE Nothing was found to remove.
24 @retval TRUE A directory or file was removed.
35 // get directory name from path... ('chop' off extra)
37 for ( Walker
= Path
, LastSlash
= NULL
38 ; Walker
!= NULL
&& *Walker
!= CHAR_NULL
41 if ((*Walker
== L
'\\' || *Walker
== L
':') && *(Walker
+ 1) != CHAR_NULL
) {
45 if (LastSlash
!= NULL
) {
46 *LastSlash
= CHAR_NULL
;
53 Function to clean up paths.
55 - Single periods in the path are removed.
56 - Double periods in the path are removed along with a single parent directory.
57 - Forward slashes L'/' are converted to backward slashes L'\'.
59 This will be done inline and the existing buffer may be larger than required
62 @param[in] Path The pointer to the string containing the path.
64 @return Returns Path, otherwise returns NULL to indicate that an error has occured.
68 PathCleanUpDirectories(
79 // Fix up the '/' vs '\'
81 for (TempString
= Path
; TempString
!= NULL
&& *TempString
!= CHAR_NULL
; TempString
++) {
82 if (*TempString
== L
'/') {
89 while ((TempString
= StrStr(Path
, L
"\\..\\")) != NULL
) {
90 *TempString
= CHAR_NULL
;
92 PathRemoveLastItem(Path
);
93 TempSize
= StrSize(TempString
);
94 CopyMem(Path
+StrLen(Path
), TempString
, TempSize
);
96 if ((TempString
= StrStr(Path
, L
"\\..")) != NULL
&& *(TempString
+ 3) == CHAR_NULL
) {
97 *TempString
= CHAR_NULL
;
98 if (!PathRemoveLastItem(Path
)) {
105 while ((TempString
= StrStr(Path
, L
"\\.\\")) != NULL
) {
106 *TempString
= CHAR_NULL
;
108 TempSize
= StrSize(TempString
);
109 CopyMem(Path
+StrLen(Path
), TempString
, TempSize
);
111 if ((TempString
= StrStr(Path
, L
"\\.")) != NULL
&& *(TempString
+ 2) == CHAR_NULL
) {
112 *(TempString
+ 1) = CHAR_NULL
;
115 while ((TempString
= StrStr(Path
, L
"\\\\")) != NULL
) {
116 *TempString
= CHAR_NULL
;
118 TempSize
= StrSize(TempString
);
119 CopyMem(Path
+StrLen(Path
), TempString
, TempSize
);
121 if ((TempString
= StrStr(Path
, L
"\\\\")) != NULL
&& *(TempString
+ 1) == CHAR_NULL
) {
122 *(TempString
) = CHAR_NULL
;