Answer the question
In order to leave comments, you need to log in
Why doesn't fwrite return an error when deleting a file?
There is such a very simple code that adds data to the end of the file once a second.
int main()
{
FILE* file = fopen("test.file", "a");
int i = 0;
char str[100];
while (1) {
sprintf(str, "heeeey %d\n", i);
int w = fwrite(str, sizeof(char), strlen(str), file);
int fl = fflush(file);
printf("fwrite = %d, fflush = %d \n", w, fl);
sleep(1);
++i;
}
return EXIT_SUCCESS;
}
Answer the question
In order to leave comments, you need to log in
While the program is running, I delete the file and see that fwrite continues to return the number of bytes written, while the file does not exist, and it is not recreated.
/proc/<pid>/fd
your process.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question