I have a school assignment that is calling for the replacement of the standard memory allocation functions within the standard library of C. I am not sure how to do this but here is the brief description my teacher is using to outline his process.
Next, I'm going to #define the standard C memory allocation and free functions to be replaced by their memcheck counterparts. In each case, I'm looking up the number and names of the arguments in the man page and using them in both the original function and its redefinition. In addition, to the arguments that are listed in the man page, I am also passing
(underscore, underscore)FILE(underscore, underscore) and LINE(underscore, underscore)
to the replacement versions as the last two arguments of each function. I am being careful not to include a semi-colon on either of the two functions in the #define statement.
right now I am just working on the header file:
#ifndef MEMCHECK_H
#define MEMCHECK_H
#include<stdlib.h>
#define malloc _memcheck_malloc
#define free _memcheck_free
#endif
The point of this project is to replace the standard malloc and free functions with one that is our own and that is being utilised within a linked list.
ultimately what i am asking for is "How do i begin defining my own function that will replace a standard function?" I need to used the #define method as well as a few compiler marcos stated above.
Here is a link to another question that i have found that appears to be the right answer but i am not sure. How to replace C standard library function ? (3rd answer).