【问题标题】:Interpositioning fscanf only under certain conditions仅在特定条件下插入 fscanf
【发布时间】:2017-10-20 20:05:13
【问题描述】:

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

【问题讨论】:

  • 关于转发可变参数参数,你会调用 vfscanf。

标签: c scanf library-interposition


【解决方案1】:

您不能从插入的 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;
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 1970-01-01
    • 2020-04-21
    • 2021-05-17
    • 2021-10-21
    • 2021-11-15
    相关资源
    最近更新 更多