]>
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 <Uefi/UefiBaseType.h>
14 #include <Library/BaseMemoryLib.h>
15 #include <Library/BaseLib.h>
16 #include <Protocol/SimpleTextIn.h>
19 Removes the last directory or file entry in a path by changing the last
20 L'\' to a CHAR_NULL. For a path which is like L"fs0:startup.nsh",
21 it's converted to L"fs0:".
23 @param[in,out] Path A 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
== 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 @return Returns Path, otherwise returns NULL to indicate that an error has occured.
70 PathCleanUpDirectories(
81 // Fix up the '/' vs '\'
83 for (TempString
= Path
; TempString
!= NULL
&& *TempString
!= CHAR_NULL
; TempString
++) {
84 if (*TempString
== L
'/') {
91 while ((TempString
= StrStr(Path
, L
"\\..\\")) != NULL
) {
92 *TempString
= CHAR_NULL
;
94 PathRemoveLastItem(Path
);
95 TempSize
= StrSize(TempString
);
96 CopyMem(Path
+StrLen(Path
), TempString
, TempSize
);
98 if ((TempString
= StrStr(Path
, L
"\\..")) != NULL
&& *(TempString
+ 3) == CHAR_NULL
) {
99 *TempString
= CHAR_NULL
;
100 if (!PathRemoveLastItem(Path
)) {
107 while ((TempString
= StrStr(Path
, L
"\\.\\")) != NULL
) {
108 *TempString
= CHAR_NULL
;
110 TempSize
= StrSize(TempString
);
111 CopyMem(Path
+StrLen(Path
), TempString
, TempSize
);
113 if ((TempString
= StrStr(Path
, L
"\\.")) != NULL
&& *(TempString
+ 2) == CHAR_NULL
) {
114 *(TempString
+ 1) = CHAR_NULL
;
117 while ((TempString
= StrStr(Path
, L
"\\\\")) != NULL
) {
118 *TempString
= CHAR_NULL
;
120 TempSize
= StrSize(TempString
);
121 CopyMem(Path
+StrLen(Path
), TempString
, TempSize
);
123 if ((TempString
= StrStr(Path
, L
"\\\\")) != NULL
&& *(TempString
+ 1) == CHAR_NULL
) {
124 *(TempString
) = CHAR_NULL
;