Just to make my previous mail more concrete, the following program
illustrates a problem with current implementation of pread(2). Namely,
reading beyond the end of file should (by Single UNIX spec) set
errno=EOVERFLOW. Currently it returns 0, and sets errno =0 (Success),
whilst leaving the buffer intact.
Btw, if one tries to pread() on a socket it does return ESPIPE which is
what I expect.
However, if you set the offset to something negative, it does not set
errno=EINVAL (again required by Single UNIX) but sets it to 0 and returns
0.
So, there are some, at least minor bugs with the current implementation of
pread(2) (and I dare guess pwrite(2) also).
Regards,
------
Tigran A. Aivazian | http://www.sco.com
Escalations Research Group | tel: +44-(0)1923-813796
Santa Cruz Operation Ltd | http://www.aivazian.demon.co.uk
PS. File "pread.dat" can look like anything that "tickles your fancy"
as long as it is not too (<40 bytes) big.
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <linux/unistd.h>
_syscall4(ssize_t, pread, unsigned int, fd, char *, buf, size_t, count, loff_t, pos)
int main(int argc, char *argv[])
{
int fd, len;
char buf[100];
buf[0] = '\0';
fd = open("pread.dat", O_RDWR);
if (fd < 0) {
perror("open()");
exit(1);
}
len = pread(fd, buf, 10, 40);
buf[len]='\0';
if (len != 10) {
fprintf(stderr, "pread(), len=%d, %s, errno=%d\n", len, strerror(errno), errno);
}
fprintf(stderr, "buf=<%s>\n", buf);
(void)close(fd);
return 0;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/