When trying to wrap a system call in C++, such as lseek, the compiled code would call the actual system call instead of my mock.
Here's an example:
/* Mock the file operation lseek. */
off_t lseek(int fd, off_t offset, int whence)
{
printf("%s \n", __PRETTY_FUNCTION__);
}
How to get the compiler to call my mocked system call rather than the one in unistd.h?
I tried using the -Wl,--wrap=lseek flag, but this failed as the linker could not find the __wrap_lseek symbol.
GNU gcc/ld - wrapping a call to symbol with caller and callee defined in the same object file