In order to avoid depending on a library at run-time I have written a dynamic loader that uses dlopen
/ dlsym
to load functions form a library at run-time.
To link at build time I use wrapper functions which call into the function pointers set by dlsym
.
I've run into a problem with variadic functions, where there doesn't seem to be a way to dynamically load the function and have it forward the variadic arguments.
Is there a way to write a wrapper library that supports varargs that doesn't...
- Depend on knowing the number of variadic arguments or ending the arguments with a sentinel value.
- Depend on working around the problem by changing the code which calls into the variadic function (which I happen not to have control over in this case).
It seems like this might be supported but most existing answers suggest to workaround the problem in a way that isn't practical in my use case.
For context the function signature I'm wrapping is:
struct wl_proxy *wl_proxy_marshal_flags(
struct wl_proxy *proxy,
uint32_t opcode,
const struct wl_interface *interface,
uint32_t version,
uint32_t flags,
...);
This function is called by generated code (see wayland-scanner
), although I rather not make this question specifically about Wayland.
Note that similar questions have been asked already, such as:
But they suggest alternatives such as using vfprintf
which don't work in my use case.