In a software baseline I am maintaining, there are 150 statements spread out amongst various C applications that make a call to either another Linux command (e.g. rm -
How to write a wrapper
Following an example on how to apply a wrapper around the libc function system().
Create a new module (translation units) called system_wrapper.c like so:
The header system_wrapper.h:
#ifndef _SYSTEM_WRAPPER
#define _SYSTEM_WRAPPER
#define system(cmd) system_wrapper(cmd)
int system_wrapper(const char *);
#endif
The module system_wrapper.c:
#include /* to prototype the original function, that is libc's system() */
#include "system_wrapper.h"
#undef system
int system_wrapper(const char * cmd)
{
int result = system(cmd);
/* Log result here. */
return result;
}
Add this line to all modules using system():
#include "system_wrapper.h"