07-17-04 10:52 PM
On Sat, 17 Jul 2004 16:34:32 +0100, James wrote:
> On Fri, 16 Jul 2004 17:02:17 -0400, James Antill
> <james-netnews@and.org> wrote:
>
>
> No - as above, the end of file is that at the time write() is called.
No, it writes the end of the file ... so if you extend the file, the hole
isn't created by the seek. But the return value is defined as:
Upon successful completion, the resulting offset, as meas-
ured in bytes from the beginning of the file, is returned.
...this means the seek to END can't happen in an atomic transaction with
the write call. O_APPEND is there for a reason.
>
> No, each of them will atomically seek to the current EOF, append their
> data, then the next one will write at the new EOF.
While I don't currently have access to try it myself on a Solaris
box, feel free to run a few instances of the following. I'm 99% sure
Solaris isn't completely broken in the way you suggest, and the file will
only grow by 50 bytes for the entire interval...
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <err.h>
#define CONF_FNAME "abcd"
#define CONF_DATA "123456789 123456789 123456789 123456789 1234567890"
#define CONF_INTERVAL 10
int main(void)
{
int fd = open(CONF_FNAME, O_WRONLY);
if (fd == -1) err(EXIT_FAILURE, "open");
if (lseek(fd, 0, SEEK_END) == -1)
err(EXIT_FAILURE, "seek");
sleep(CONF_INTERVAL);
if (write(fd, CONF_DATA, sizeof(CONF_DATA) - 1) == -1)
err(EXIT_FAILURE, "write");
return EXIT_SUCCESS;
}
--
James Antill -- james@and.org
Need an efficient and powerful string library for C?
http://www.and.org/vstr/
[ Post a follow-up to this message ]
|