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; > } > eof > read$ ./a.out > a.out: read: Bad address > > Even though that linux's read(2) man page claims [1]: > > DESCRIPTION > 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. > > [..snip..] > > P.S. It would be interesting to know how this code behaves under OpenBSD, with > p = malloc (0); > > [1] As does, in essence, > http://www.opengroup.org/onlinepubs/7990989775/xsh/read.html
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.