Override global function like fopen/ofstream

130 views Asked by At

I want to know what file is opened and in what mode and for this I want to override the global functions like fopen/ofstream and other file handling function

Required:

    FILE* fopen(filename, mode){ //Our own fopen
    printf("%s-%s",filename, mode)// print filename na dmode
    return fopen(filename, mode); // actual fopen
    }

    void main(){
    FILE * fp = fopen("name.txt", "w");
    fprintf(fp, "%s", "hello World");
    fclose(fp);
    }

Output should be: name.txt-w

One solution is to create a wrapper with some other name for fopen but as fopen is called from various places I don't want to use different name

Is there a way to implement above scenario?

0

There are 0 answers