lundi 29 juin 2015

Pass variable number of arguments received to another function


Before you say it's duplicated, I already read this: How to pass variable number of arguments from one function to another?

I have a function like this:

void tlog_function(t_log* logger, const char* message_template, ...) {
    pthread_mutex_lock(&loggerLock);
    log_function(logger, message_template, ...); // What I want to do..
    pthread_mutex_unlock(&loggerLock);
}

And another function like this, which is not mine, I use it from a third-party library:

void log_function(t_log* logger, const char* message_template, ...);

As you can see, what I want to do is just add a mutex to this function to make it thread-safe, I know I can use va_list but in this case I cannot change the code of the second function, because it is inside a library and I only have the .h file.

So, is there any way to achieve this?


Aucun commentaire:

Enregistrer un commentaire