Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fputs

Status
Not open for further replies.

lzdanny

Programmer
Jul 7, 2004
5
GB
I am trying to write to a file using fputs() but when the disk is full, EOF is not returned. Despite this, errno is set to ENOSPC (28) as expected. Has anyone encountered this problem before, as I need to know there is an error when writing to the file before I can handle what type of error it is?

Thanks, lzdanny.
 
Does ferror() also fail to indicate a failure when the disk is full?

--
 
ferror does report the error, providing you don't use clearerr before you call it!

i can change the code but i would just like to know why fputs isn't returning EOF...

cheers, dan.
 
It's not a full explanation, supposition only...
Let's see RTL fputs() epilogue sources (VS 6.0 EE):
Code:
  ndone = _fwrite_lk(string,1,length,stream);
  _ftbuf(buffing, stream);
  _unlock_str(stream);

  return(ndone == length ? 0 : EOF);
Probably _ftbuf() can flush buffer but fgets returns its value on the previous returned ndone base only.
2nd scenario: fputs() puts data in buffer successfully, after that implicit flush (for example, on close()) failed with ENOSPC...

In 1st case that behaviour is probably wrong, but in the 2nd case - alas - fgets() can't recognaze future troubles...

Well, in any case you may debug full code with disk overflowed (F11 to enter into RTL stuff)...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top