Interpositioning fscanf only under certain conditions

180 Views Asked by At

So I'm trying to override the fscanf function in c, but I only want different behavior to occur if certain conditions are met; if those conditions are not met, I want to just call the original fscanf. I know that you can use dlsym to use the original version of a function while interpositioning it, but the problem with fscanf is that it's variadic. I can get all of the parameters passed into my function using va_list and va_arg, but how am I supposed to call the original fscanf on these parameters when I don't actually know how many parameters there are?

1

There are 1 best solutions below

0
On BEST ANSWER

You can't call the original fscanf from the interposed fscanf. You just have to call vfscanf(). Your interposed function would look like:

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;
 }