仅在特定条件下插入 fscanf

Interpositioning fscanf only under certain conditions

所以我试图覆盖 c 中的 fscanf 函数,但我只希望在满足某些条件时发生不同的行为;如果不满足这些条件,我只想调用原始的 fscanf。我知道您可以使用 dlsym 在插入函数时使用函数的原始版本,但 fscanf 的问题在于它是可变的。我可以使用 va_list 和 va_arg 将所有参数传递到我的函数中,但是当我实际上不知道有多少参数时,我应该如何调用这些参数的原始 fscanf?

您不能从插入的 fscanf 中调用原始 fscanf。您只需致电 vfscanf()。您的插入函数如下所示:

int fscanf(FILE *stream, const char *format, ...)
{
    ....
    ....

    va_list ap; 
    va_start(ap, format);
    int rc = vfscanf(stream, format, ap);
    va_end(ap);
    return rc;
 }