Template InterceptCall

Intercept a library of a system call

template InterceptCall(alias F) ;
template InterceptCall(alias F) ;
template InterceptCall(alias F) ;
template InterceptCall(alias F) ;

To use: define a function (typically, with extern(C) linkage) that performs the alternative implementation of the library call. Then expand the template mixin here, giving it your function as a template argument.

The template mixin will define a function called next_ yourfunction

Example

extern(C) int socket(int domain, int type, int protocol) {
    import std.stdio;
    int ret = next_socket(domain, type, protocol);

    writefln("socket(%s, %s, %s) = %s", domain, type, protocol, ret);

    return ret;
}

mixin InterceptCall!socket;