From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: To: 9fans@cse.psu.edu Subject: Re: [9fans] what a mess the Unix world has become From: Geoff Collyer In-Reply-To: <3E48ABC5.6050205@null.net> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Tue, 11 Feb 2003 02:25:20 -0800 Topicbox-Message-UUID: 56ad3110-eacb-11e9-9e20-41e7f4b1d025 Checking close() return values after writing on a descriptor is good hygiene, but as I recall, NFS made error detection harder by not necessarily reporting write errors (even synchronous ones like ENOSPC) via either write() or close(); one had to use fsync() just before the close() to force any write errors to be reported. From code I wrote in the late 1980s: /* * nfclose(stream) - flush the stream, fsync its file descriptor and * fclose the stream, checking for errors at all stages. This dance * is needed to work around the lack of Unix file system semantics * in Sun's NFS. Returns EOF on error. */ #include int nfclose(stream) register FILE *stream; { register int ret = 0; if (fflush(stream) == EOF) ret = EOF; if (fsync(fileno(stream)) < 0) /* may get delayed error here */ ret = EOF; if (fclose(stream) == EOF) ret = EOF; return ret; }