wrapping a vararg C function (specifically, log() in the kernel)

From: Luigi Rizzo <rizzo_at_iet.unipi.it>
Date: Thu, 18 Dec 2014 15:21:15 +0100
Hi,
in the porting of some kernel code to FreeBSD, i need to remap one
function with a variable number of arguments to the log() function
from the freebsd kernel.

Normally i would do

	#define WARN(x, args...)	log(LOG_WARNING, args)

but this does not work in my case because the function is called in
(many) blocks where there is already a local variable with the same name

	bool log;

which is used a ton of times.

I was wondering if there is some C compiler magic i can use to do the
remapping without going through a macro; I haven't found any direct one,
though perhaps something like

	extern void (*freebsd_log)(int level, const char *fmt, ...);

	#define WARN(x, args...)    freebsd_log(LOG_WARNING, args)

followed somewhere in a safe place by

		freebsd_log = log;

may do the job.

Any other option ?

	cheers
	luigi
Received on Thu Dec 18 2014 - 13:17:01 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:54 UTC