/* Look up FileName with QemuFwCfgFindFile() from QemuFwCfgLib. Read the fw_cfg file into the caller-provided CHAR8 array. NUL-terminate the array. */
STATIC RETURN_STATUS QemuFwCfgGetAsString(IN CONST CHAR8 *FileName, IN OUT UINTN *BufferSize, OUT CHAR8 *Buffer)
/* Look up FileName with QemuFwCfgFindFile() from QemuFwCfgLib. Read the fw_cfg file into the caller-provided CHAR8 array. NUL-terminate the array. */
STATIC RETURN_STATUS QemuFwCfgGetAsString(IN CONST CHAR8 *FileName, IN OUT UINTN *BufferSize, OUT CHAR8 *Buffer)
{
  RETURN_STATUS         Status;
  FIRMWARE_CONFIG_ITEM  FwCfgItem;
  UINTN                 FwCfgSize;
  if (!QemuFwCfgIsAvailable ()) {
    return RETURN_UNSUPPORTED;
  }
  Status = QemuFwCfgFindFile (FileName, &FwCfgItem, &FwCfgSize);
  if (RETURN_ERROR (Status)) {
    return Status;
  }
  if (FwCfgSize > *BufferSize) {
    return RETURN_PROTOCOL_ERROR;
  }
  QemuFwCfgSelectItem (FwCfgItem);
  QemuFwCfgReadBytes (FwCfgSize, Buffer);
  if ((FwCfgSize > 0) && (Buffer[FwCfgSize - 1] == '\0')) {
    *BufferSize = FwCfgSize;
    return RETURN_SUCCESS;
  }
  if (FwCfgSize == *BufferSize) {
    return RETURN_PROTOCOL_ERROR;
  }
  Buffer[FwCfgSize] = '\0';
  *BufferSize       = FwCfgSize + 1;
  return RETURN_SUCCESS;
}