On Sat, Dec 05, 2009 at 08:08:27PM +0300, malc wrote:
> ret = read (fd, p, 0);
> if (ret != 0) err (1, "read");
> return 0;
> read$ ./a.out
> a.out: read: Bad address
> Even though that linux's read(2) man page claims :
> read() attempts to read up to count bytes from file descriptor fd into
> the buffer starting at buf.
> If count is zero, read() returns zero and has no other results. If
> count is greater than SSIZE_MAX, the result is unspecified.
> P.S. It would be interesting to know how this code behaves under OpenBSD, with
> p = malloc (0);
>  As does, in essence,
Which simply means that the linux man page was based on SUSv2 which obviously
was quite badly written.
SUSv3 gets it right (proving along the way it is better to use the POSIX man
pages, i.e. "man 3 read").
It might be good to suggest them to update the linux man page though.