How to access variable values of a variadic print function?

129 views Asked by At

I am trying to test a function (bar()) which uses a module specific print function (foo_print) to output to the console, seen below:

#define foo_print(...) foo_log(FOO_LOGTYPE_PRINT, ## __VA_ARGS__)

where foo_log() is defined as an item of type

typedef (*foo_log_fct)(mkqfs_logtype type, const char *fmt, ...) __attribute__((format(printf, 2, 3)));

Without changing this definition, I need to access and store numeric values that are passed into foo_print inside of bar(). I need to do this because this is the only output of bar().

I am planning on creating a stub function my_foo_print(const char *fmt, ...) and redefining foo_print to call this instead, so that I can capture the output and make sure it is correct.

I have two questions:

  1. Is my function stub correct? Have I asked for the right arguments
  2. How can I access and store the variable arguments to this function without knowing how many there will be and what type? My understanding is that sequential calls to va_args(va_list, type) require you to know these things. Is there any way around this?
1

There are 1 answers

0
Matt Salem On

No VA ARGS is the way. Every time you call it it will switch the argument that you are referring to