This is an assignment from my C class, it's supposed to be an exercise in dynamic libraries. I figured out how to do most of it, but I am stuck on the last step.
Basically, I am given a function from a specified file, which i can call using dlsym. However, the number and types of arguments can vary function to function. I am given the shortened function signature and the arguments themselves through argv[]. The shortened function signature for a function like printf('Hello: %s, %d, %f', abc, 10, 12.4) will look something like this:
vccid { which is short for void func(char *, char *, int, double) }
For example, if I need to call the described printf function, my argv will look like this:
[ ],[ Name of file where function is located ],[ name of function ],[ vccid ],[ 'Hello: %s, %d, %f' ],[ abc ],[ 10 ],[ 12.4 ]
I use dlopen and dlsym to get the function itself
typedef void *(*arbitrary1)();
...
int main(int argc, const char * argv[]) {
arbitrary1 f1;
void *handle = dlopen(argv[1], RTLD_LAZY);
*(void**)f1 = dlsym(handle, argv[2]);
...
}
Now, my question is this: Is there any way to pass the arguments i get from argv into my function call? So the end result will be
f1('Hello: %s %d %f', abc, 10, 12.4);
Thank you in advance for your help