0

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?

Jarod42
  • 203,559
  • 14
  • 181
  • 302
Karthik K M
  • 619
  • 2
  • 9
  • 24

0 Answers0