Re: question



Serve Lau wrote:

"Keith Thompson" <kst-u@xxxxxxx> schreef in bericht
news:87fxx2s8al.fsf@xxxxxxxxxxxxxxxxxx
fclose(fp);}

No error checking (yes, fclose can fail).

Yes, I also changed the code layout. Whitespace is not in short
supply; use as much as you need to make the code clear and readable.

I'm wondering how to handle failure of fclose. Has anyone ever had it fail
and for what reasons?

Consider an output stream which is buffered, and the buffered data,
once written, will cause the file to grow, and the filesystem on which
the file resides is currently full.

You now call fclose() on that stream.

Without knowing how your implementation handles an fwrite()/fflush()
failure within fclose(), I can't say whether fclose() will fail, or
ignore the internal failure. However, it's certainly possible that
the fwrite()/fflush() failure will cause fclose() to fail.

Now, as to how to handle it? That's another issue entirely.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@xxxxxxxxx>


.



Relevant Pages

  • Re: How to tell a file is been close.
    ... obviously fail if I make some programming error, like fclose; ... where the second call is quite likely to fail. ... can't write to the output device that your user is monitoring (be it ... Richard Heathfield ...
    (comp.lang.c)
  • Re: fclose failure conditions
    ... Those in which CBFalconer replies to you. ... The quality of the answer did reflect the quality of the question. ... I don't think I've seen any manuals which explain why fclose() might ... fail". ...
    (comp.lang.c)
  • Re: How to tell a file is been close.
    ... obviously fail if I make some programming error, like fclose; ... where the second call is quite likely to fail. ... Mark McIntyre ...
    (comp.lang.c)
  • Re: Plz explain me the following code
    ... Yeah fair enough, I don't check the return of fclose() either, but you ... input file might fail. ... data to the file buffer in memory. ... that the data is actually written to disk -- and that could fail ...
    (comp.lang.c)
  • Re: fclose memory fault
    ... CX marks extensions to the C Standard, not extensions to the old POSIX.1. ... The original POSIX.1 required fclose() to set errno to EBADF *if* it ... fclosewould have to fail with EBADF, but if there was no data to ...
    (comp.unix.programmer)