I have a legacy program which outputs to either stdout or a file if given a -o option.
if (<-o option exists>) {
fn = fopen(file_name, "w");
} else {
fn = stdout;
}
I want to change this program to output to nowhere (minimal fileio overhead). At first, I'm considering:
if (<-o option exists>) {
fn = fopen(file_name, "w");
} else {
fn = fopen("/dev/null", "w");
}
I'm trying to simply measure the compute time of the program without any fileio. Since I don't want GCC to just blow away the compute parts (and also it's legacy code), I would like the code path to actually output the results to exist, but have the program have the option to fputc, putc, printf, etc. to nothing. The program seems to mix all 3 methods of printing unfortunately and I'd have to do a lot of surgery to remove it.
Is there a FILE* pointer I can give to those functions that would cause them not to do anything and not throw exceptions? And one that's preferably portable.