Subject: [clisp-list] Problems with latest CVS version of comment5.c

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Thu Aug 1 00:50:02 2002

>   120    /* close files: */
>   121    fclose(infile);
>   122    fclose(outfile);
>   123    if (ferror(infile))
>   124      { perror(infilenamebuffer); exit(__LINE__); }
>   125    if (ferror(outfile))
>   126      { perror(outfilenamebuffer); exit(__LINE__); }
>   127    exit(0); /* OK */
>
>Does it make sense to test file error after closing the file? I moved
>the tests before fclose and it worked as usual.

In computing theory: yes

In practice: don't know. It depends on lots of libraries, specifications, broken code etc.
What you could try out is move the test for infile befor closing outfile.

It makes sense (in theory) to check the close status because for example the last writes to a file may be issued only when close() is encoutered, thanks to internal buffering. Thus checking the status of the last write (or of any write) is no guarantee that stuff gots successfully written. E.g. suppose you write less than 8000 bytes to a file, while many UNIX write in 8192 byte blocks. It's only after the close() that the file will really be written. Every write before that is one to memory only.

Even worse, closing the file still does not give you a guarantee that something has really been written to disk. E.g., on Sun machines, the sync process runs every 30 seconds to flush buffers. It also means that things get eventually written to disk long after an application has terminated. So in general, an application cannot know for sure whether a write to a file actually hit the disk. It is out of the scope of the application to ensure this. It involves file-systems etc. (journaling or loggin file systems etc.).

Regards,
	Jorg.

---

From: Aurelio Bignoli <[email-masked]>
Date: Fri Aug 2 03:24:11 2002

>>>>> "Jorg" == Hoehle, Joerg-Cyril <[email-masked]> writes:

    Jorg> It makes sense (in theory) to check the close status because

this can be done testing the return value of fclose. According to
ANSI C Standard (section 7.9.5.1):

"The fclose function returns zero if the stream was successfully
closed, or EOF if any errors were detected."

Ciao,
Aurelio