问题
I need your suggestion to wrap my existing function.
I am from testing team I need to write unit test cases, so I don't want to depend on original definition so trying to write my own definiton.
Following is the source code which should not be changed.
source.c:
#include <stdio.h>
const char *getObjectName (int *anObject);
void func()
{
int *p;
getObjectName(p);
}
const char *getObjectName (int *anObject)
{
printf("i am in original\n");
}
From the above code I want to wrap getObjectName() function so that I can give my own definition.
I have googled a lot and tried following methods but didn't work out:
- Method 1. using ld --wrap method
- Method 2. using -DINTERCEPT
- Method 3. using function pointer
I cannot use above 3 methods because calling function and called function are in same file.
So please suggest me any other methods to write my own defintion for getObjectName().
来源:https://stackoverflow.com/questions/43203723/wrapping-of-function-in-the-same-file