X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellCommandLib%2FUefiShellCommandLib.c;h=b91ba27af04d9375356bb7c6f9a392ea49490113;hb=a49016b117dceddc8b44fe3e5e4e3623cee133e5;hp=9e7cd0e6e1464a1b9074f50a7528ad8431aef37a;hpb=1a63ec8f82705d4fb97e4034c1471c8e2a5c9cc5;p=mirror_edk2.git diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c index 9e7cd0e6e1..b91ba27af0 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c @@ -1545,3 +1545,51 @@ ChopLastSlash( return (FALSE); } +/** + Function to clean up paths. Removes the following items: + single periods in the path (no need for the current directory tag) + double periods in the path and removes a single parent directory. + + This will be done inline and the resultant string may be be 'too big'. + + @param[in] PathToReturn The pointer to the string containing the path. + + @return PathToReturn is always returned. +**/ +CHAR16* +EFIAPI +CleanPath( + IN CHAR16 *PathToReturn + ) +{ + CHAR16 *TempString; + UINTN TempSize; + if (PathToReturn==NULL) { + return(NULL); + } + // + // Fix up the directory name + // + while ((TempString = StrStr(PathToReturn, L"\\..\\")) != NULL) { + *TempString = CHAR_NULL; + TempString += 4; + ChopLastSlash(PathToReturn); + TempSize = StrSize(TempString); + CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize); + } + if ((TempString = StrStr(PathToReturn, L"\\..")) != NULL && *(TempString + 3) == CHAR_NULL) { + *TempString = CHAR_NULL; + ChopLastSlash(PathToReturn); + } + while ((TempString = StrStr(PathToReturn, L"\\.\\")) != NULL) { + *TempString = CHAR_NULL; + TempString += 2; + TempSize = StrSize(TempString); + CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize); + } + if ((TempString = StrStr(PathToReturn, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) { + *TempString = CHAR_NULL; + } + return (PathToReturn); +} +