The easiest and cleanest way would be something like a wrapper function to open the file.
Code:
void wrapper ( char *filename ) {
FILE *fp = fopen(filename,"r");
recursive(fp);
fclose(fp);
}
This is fugly
Code:
void recursive ( char *filename ) {
static FILE *fp = NULL;
if ( !fp ) {
fp = fopen(filename,"r");
// read from static fp
recursive(filename);
fclose(fp);
fp = NULL;
} else {
// read from static fp
recursive(filename);
}
}
Finding out whether the file is open would involve expensive OS calls (and be very non-portable).