TianoCore EDK2 master
Loading...
Searching...
No Matches
FilePaths.c
Go to the documentation of this file.
1
9#include <Library/BaseLib.h>
10
20BOOLEAN
21EFIAPI
23 IN OUT CHAR16 *Path
24 )
25{
26 CHAR16 *Walker;
27 CHAR16 *LastSlash;
28
29 //
30 // get directory name from path... ('chop' off extra)
31 //
32 for ( Walker = Path, LastSlash = NULL
33 ; Walker != NULL && *Walker != CHAR_NULL
34 ; Walker++
35 )
36 {
37 if ((*Walker == L'\\') && (*(Walker + 1) != CHAR_NULL)) {
38 LastSlash = Walker+1;
39 } else if ((*Walker == L':') && (*(Walker + 1) != L'\\') && (*(Walker + 1) != CHAR_NULL)) {
40 LastSlash = Walker+1;
41 }
42 }
43
44 if (LastSlash != NULL) {
45 *LastSlash = CHAR_NULL;
46 return (TRUE);
47 }
48
49 return (FALSE);
50}
51
66CHAR16 *
67EFIAPI
69 IN CHAR16 *Path
70 )
71{
72 CHAR16 *TempString;
73
74 if (Path == NULL) {
75 return NULL;
76 }
77
78 //
79 // Replace the '/' with '\'
80 //
81 for (TempString = Path; *TempString != CHAR_NULL; TempString++) {
82 if (*TempString == L'/') {
83 *TempString = L'\\';
84 }
85 }
86
87 //
88 // Replace the "\\" with "\"
89 //
90 while ((TempString = StrStr (Path, L"\\\\")) != NULL) {
91 CopyMem (TempString, TempString + 1, StrSize (TempString + 1));
92 }
93
94 //
95 // Remove all the "\.". E.g.: fs0:\abc\.\def\.
96 //
97 while ((TempString = StrStr (Path, L"\\.\\")) != NULL) {
98 CopyMem (TempString, TempString + 2, StrSize (TempString + 2));
99 }
100
101 if ((StrLen (Path) >= 2) && (StrCmp (Path + StrLen (Path) - 2, L"\\.") == 0)) {
102 Path[StrLen (Path) - 1] = CHAR_NULL;
103 }
104
105 //
106 // Remove all the "\..". E.g.: fs0:\abc\..\def\..
107 //
108 while (((TempString = StrStr (Path, L"\\..")) != NULL) &&
109 ((*(TempString + 3) == L'\\') || (*(TempString + 3) == CHAR_NULL))
110 )
111 {
112 *(TempString + 1) = CHAR_NULL;
113 PathRemoveLastItem (Path);
114 if (*(TempString + 3) != CHAR_NULL) {
115 CopyMem (Path + StrLen (Path), TempString + 4, StrSize (TempString + 4));
116 }
117 }
118
119 return Path;
120}
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
Definition: String.c:224
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
CHAR16 *EFIAPI PathCleanUpDirectories(IN CHAR16 *Path)
Definition: FilePaths.c:68
BOOLEAN EFIAPI PathRemoveLastItem(IN OUT CHAR16 *Path)
Definition: FilePaths.c:22
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284