Determine Original Exit Status Code

前端 未结 2 977

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 -

2条回答
  •  没有蜡笔的小新
    2020-12-11 12:06

    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"
    

提交回复
热议问题