-// Replaces a filename extension of ".efi" with the specified string
-// (Extension). If the input Path doesn't end in ".efi", Extension
-// is added to the existing filename.
-VOID ReplaceEfiExtension(IN OUT CHAR16 *Path, IN CHAR16 *Extension)
-{
- UINTN PathLen;
-
- PathLen = StrLen(Path);
- // Note: Do StriCmp() twice to work around Gigabyte Hybrid EFI case-sensitivity bug....
- if ((PathLen >= 4) && ((StriCmp(&Path[PathLen - 4], L".efi") == 0) || (StriCmp(&Path[PathLen - 4], L".EFI") == 0))) {
- Path[PathLen - 4] = 0;
- } // if
- StrCat(Path, Extension);
-} // VOID ReplaceEfiExtension()
+// Remove the .efi extension from FileName -- for instance, if FileName is
+// "fred.efi", returns "fred". If the filename contains no .efi extension,
+// returns a copy of the original input.
+CHAR16 * StripEfiExtension(CHAR16 *FileName) {
+ UINTN Length;
+ CHAR16 *Copy = NULL;
+
+ if ((FileName != NULL) && ((Copy = StrDuplicate(FileName)) != NULL)) {
+ Length = StrLen(Copy);
+ // Note: Do StriCmp() twice to work around Gigabyte Hybrid EFI case-sensitivity bug....
+ if ((Length >= 4) && ((StriCmp(&Copy[Length - 4], L".efi") == 0) || (StriCmp(&Copy[Length - 4], L".EFI") == 0))) {
+ Copy[Length - 4] = 0;
+ } // if
+ } // if
+ return Copy;
+} // CHAR16 * StripExtension()