有没有一种方法可以根据 printf / 更简单的函数(轻松地)定义 fprintf?

Is there a way to define fprintf in terms of printf / simpler functions (easily)?

我正在尝试 link 使用 MSVC 构建的程序针对使用 MinGW 编译的 DLL。问题是 DLL 假定函数 fprintf 存在,但 MSVC 在它 link 反对的任何库中都没有定义它。我不能更改 MSVC 和 MinGW 的版本,所以我能想到的唯一方法是编写我自己的 fprintf,但我希望有一个简单的实现不需要我维护整个代码库...

Is there a way to define fprintf in terms of printf / simpler functions (easily)?"

是,如果图书馆有 vfprintf()

#include <stdarg.h>
#include <stdio.h>

int my_own_fprintf(FILE * stream, const char * format, ...) {
  int y;
  va_list args;
  va_start(args, format);
  y = vfprintf(stream, format, args);
  va_end(args);
  return y;
}