如何在 UEFI 中使用 fprintf

How to use fprintf in UEFI

Stdio 库中有 fprintf 函数。

但是怎么用呢?

第一个参数是 FILE 类型。

但是我有 EFI_FILE_PROTOCOL* File 是我从 EFIOpenFile 函数中得到的。如何映射到 FILE 类型?

有托管环境和独立环境。

来自 C 标准:

The two forms of conforming implementation are hosted and freestanding. A conforming hosted implementation shall accept any strictly conforming program. A conforming freestanding implementation shall accept any strictly conforming program in which the use of the features specified in the library clause (clause 7) is confined to the contents of the standard headers <float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h>, and <stdnoreturn.h>. A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any strictly conforming program.

因此在独立环境中(如您描述的 UEFI 环境)C 标准不要求 fprintf() 函数是 defined/declared 并且不需要 FILE 类型来定义。因此,您需要自己编写代码。