On Wed, May 23, 2001 at 02:04:51PM -0400, Tom Lane wrote:
> Chris Jones <chris@mt.sri.com> writes:
> > If write didn't return -1, it shouldn't have set errno. A short write
> > count isn't an error condition.
>
> On disk files it certainly is; there's no non-error reason to do that,
> and AFAICS no reason for the application to try again.
i've tried to get partial write on disk shortage condition and had no
success. on OpenBSD, if there is no space write() seems to write the
whole buffer or fail with -1/errno. i used such proggie attached to
the and (owell, i'm not sure about forks, but it adds more
simultaneosity... huh?). BTW. i didn't see anywhere i looked whetjer
write on disk files can fail after writting some part of data.
--
Denis A. Doroshenko [GPRS/IN/WAP, VAS group engineer] .-. _|_ |
[Omnitel Ltd., T.Sevcenkos st. 25, Vilnius, Lithuania] | | _ _ _ .| _ |
[Phone: +370 9863486 E-mail: d.doroshenko@omnitel.net] |_|| | || |||(/_|_
---[a.c]------------------------------------------------------------
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define SIZ (12345)
#define CHILDREN (5)
#define FILE "/tmp/garbage.XXXXXXXXXX"
int
main (void)
{
char *buf;
char *file;
int fd, i, j, rc;
warnx("[%d] allocating %d of memory", getpid(), SIZ);
if ( (buf = malloc(SIZ)) == NULL )
err(1, "malloc()");
file = strdup(FILE);
warnx("[%d] creating %s", getpid(), file);
if ( (fd = mkstemp(file)) == -1 )
err(1, "open()");
warnx("[%d] forking...", getpid());
for ( j = 0; j < CHILDREN; j++ ) {
if ( fork() == 0 ) {
warnx("[%d:%d]: filling %s with junk",
getppid(), j, file);
for ( i = 0; ; i++ ) {
if ( (rc = write(fd, buf, SIZ)) == -1 ) {
warn("[%d:%d] write()", getppid(), j);
break;
}
if ( rc == SIZ ) {
(void)fputc(j + '0', stderr);
continue;
}
warn("[%d:%d] write(%d written)",
getppid(), j, rc);
}
(void)close(fd);
return (0);
}
}
/* father */
while ( (j = wait(&i)) != - 1 )
;
warnx("[%d] destroying %s", getpid(), file);
(void)close(fd);
(void)unlink(file);
return (0);
}