Simultaneously opening a file multiple times has implementation-defined behavior. On some platforms, this is not allowed. On others, it might result in race conditions.
...
| Code Block | ||
|---|---|---|
| ||
void do_stuff(void) {
FILE *logfile = fopen("log", "a");
/* Check for errors, write logs pertaining to do_stuff(), etc. */
}
int main(void)
{
FILE *logfile = fopen("log", "a"); /* Check for errors, write logs pertaining to main(), etc. */
do_stuff();
/* ... */
}
|
However, the file log is opened twice simultaneously. The result is implementation-defined and potentially dangerous.
...