/* Extract filename from device path. The returned buffer is allocated using AllocateCopyPool. The caller is responsible for freeing the allocated buffer using FreePool(). */
CHAR16* ExtractFileNameFromDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
/* Extract filename from device path. The returned buffer is allocated using AllocateCopyPool. The caller is responsible for freeing the allocated buffer using FreePool(). */
CHAR16* ExtractFileNameFromDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
{
  CHAR16  *String;
  CHAR16  *MatchString;
  CHAR16  *LastMatch;
  CHAR16  *FileName;
  UINTN   Length;
  ASSERT (DevicePath != NULL);
  String      = UiDevicePathToStr (DevicePath);
  MatchString = String;
  LastMatch   = String;
  FileName    = NULL;
  while (MatchString != NULL) {
    LastMatch   = MatchString + 1;
    MatchString = StrStr (LastMatch, L"\\");
  }
  Length   = StrLen (LastMatch);
  FileName = AllocateCopyPool ((Length + 1) * sizeof (CHAR16), LastMatch);
  if (FileName != NULL) {
    *(FileName + Length) = 0;
  }
  FreePool (String);
  return FileName;
}