The header file wrap.h define various macros of the form WRAP[V]([], , ..., , ,
, , )

The macro invocation will define a function named  which "wraps" an
existing function by the same name.  We assume that a function named 
already exists.  The digit  is the number of arguments to .
Currently  must be between 0 and 5.  The optional "V" suffix in the
macro name indicates that  returns void, and no result type is specified.

If WRAP is defined as above then every call to (arg, ...) will
instead perform the logical actions:

	
(arg, ...);
	result = (arg, ...);
	(result);
	return result;

It is acceptable for 
 and  to actually be defined as a macro
and for 
 to declare variables used in .

Two other arguments are required in that they are needed by some
implementations:

 is the library in which  is defined.  We assume that we are wrapping
the previously visible definition of , but it is sometimes easier for the
implementation to obtain access to it if it knows the name of the library
in which it is defined.

(arg, ...) is invoked instead of  if  is invoked before we
have completed the wrapping operation.  This may happen if standard C library
calls are wrapped, and those calls are needed, for example, to look up
the original function.  The function  should complete correctly without
calling .  (In many cases it will be acceptable to supply a function
which simply aborts.  For a function like "malloc", something more
sophisticated is necessary.)

Function wrapping is currently accomplished in one of two ways:

WRAP_LD:  If the WRAP_LD macro is defined, the wrapper function will be
called __wrap_, and it will refer to __real_.  This is normally
used with the "--wrap " GNU ld option (or the -Wl,--wrap -Wl,
gcc option).  This will cause  to be properly wrapped for code that
is linked at the same time as the wrapper function.  The  and
 arguments are ignored in this case.

WRAP_PRELOAD (the default): The wrapper function is called  and it looks
up the original function using dlsym().  This allows the wrapper to be placed
into e.g. a Linux shared library, and preloaded via the LD_PRELOAD
environment variable.  This can be used to wrap symbols in dynamically-
linked executables without relinking.  On Linux systems, it is recommended
that the file including wrap.h be compiled with _GNU_SOURCE defined.

EXAMPLE: See malloc_trace.c in the qprof distribution.

BUGS: This has only been tested to the extent it is used by the rest of
qprof.  That means many lines of code have never even been compiled.
But most of the undiscovered bugs are probably easy to fix.