Date: Wed, 28 Apr 1999 10:17:54 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: Rob Kramer cc: djgpp AT delorie DOT com Subject: Re: open() / write() doesn't fail on disk full? In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Tue, 27 Apr 1999, Rob Kramer wrote: > I noticed that open/write or fopen/fwrite seem to handle my disk running > out of space as if nothting special is going on. This depends on how did you call `write' and `fwrite'. There *is* a way to get them to return an error, see below. > I would expect them to bomb and set errno appropriately. Sorry, you expect too much. When a filesystem fills, neither DOS nor Windows 9X don't fail the call; they simply write as many bytes as would fit, and return the count of what was actually written to the caller. Since a library function cannot easily know why the OS wrote only part of the buffer, it doesn't automatically set errno to ENOSPC, unless it has some corroborating evidence: it only returns ENOSPC if ZERO bytes were written. So, to get what you want, do something like this (given a pointer to a buffer in buf_ptr and its length in buf_len): while (buf_len > 0) { int written = write (desc, buf_ptr, len); if (written <= 0) break; buf_ptr += written; len -= written; } This will set errno to ENOSPC if the disk fills. The trick is to call `write' one more time after it fills the disk, so that it fails to write anything.