[LTP] [PATCH] syscalls/write06: Add new test
Cyril Hrubis
chrubis@suse.cz
Fri Dec 10 11:57:08 CET 2021
Hi!
> What I want to test is the following description of open(2) man-pages:
>
> O_APPEND
> ?????? ?? The file is opened in append mode.?? Before each write(2), the
> file offset is positioned at the end of the file, as if with lseek(2).??
> The modification of the file offset and the write operation are
> performed as a single atomic step.
Ah, now it makes much more sense.
I think part of the problem is that the code is actually confusing. I do
not like the l_seek() function at all, it's confusing at best because it
does several different things at the same time. So it would be much
better to write the offset check as:
off = SAFE_LSEEK(fd, 1K, SEEK_SET)
if (off != 1K)
tst_brk(TBROK, "Failed to seek to 1K");
SAFE_WRITE(1, fd, write_buf[1], K1);
off = SAFE_LSEEK(fd, 0, SEEK_CUR);
if (off != K3)
tst_res(TFAIL, "Wrong offset after write %zu expected %u", off, K3)
else
tst_res(TPASS, "Offset is correct after write %zu", off);
SAFE_FSTAT(fd, &statbuf);
if (statbuf.st_size != K3) {
tst_res(TFAIL, "Wrong file size after append %zu expected %u",
statubuf.st_size, K3);
} else {
tst_res(TPASS, "Correct file size after append %u", K3);
}
This makes it much clearer what happens here and the TPASS message
actually says what has passed...
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list