file system query
Guy Harris
guy at sun.uucp
Thu May 9 17:22:12 AEST 1985
> Opening for append using [see] fopen(3) does not cause anything
> of great magic to happen to the op system. The basic procedure
> involved is:
> (1) open file
> (2) seek to end
> (3) fill buffer and write to file in current position
Not in System V. In System V, opening for append using "fopen" *does* turn
on the "forced append" bit for the underlying file descriptor. This solves
the problem you mention of two processes appending to the same file. (For
System III or 4.NBSD for N >= 2, which have the same forced append bit but
don't use it in the standard I/O library,
#include <fcntl.h>
int fdflags;
if ((fdflags = fcntl(fileno(stream), F_GETFD, 0) < 0) {
perror("Hell just froze over");
exit(69);
}
if (fcntl(fileno(stream), F_SETFD, fdflags|O_APPEND) < 0) {
perror("The Mets just won the World Series");
/*
* No statement is being made here about the relative
* probability of the two "fcntl" calls failing :-)
*/
exit(17);
}
should do the trick.
Guy Harris
More information about the Comp.unix
mailing list