On Tue, May 3, 2011 at 03:00, fykc...@gmail.com <fykc...@gmail.com> wrote: > 2011/5/3 Kay Sievers <kay.siev...@vrfy.org> >> >> On Mon, May 2, 2011 at 05:18, fykc...@gmail.com <fykc...@gmail.com> wrote: >> > loop_read/write will try to fill/read 'nbytes' of caller supplying buffer. >> > This argument is currently of type size_t, which is always true >> > for loop quit condition "while (nbytes > 0)", hence we change it to >> > type ssize_t here. >> >> Where would that be useful? It's the size of the buffer supplied to >> the function, just like read() itself has. > Note "while(nbytes > 0)" is equal to "while(true)"
Why? nbytes can be zero, and then it's false. It's counting down with every read(). > if the supplying > buffer is smaller than contents of a file, read syscall may overwrite > memory after 'buf', or return with errno EFAULT. How, when p moves forward, and nbytes counts down to zero? >> > This also helps to detect passed-in 'nbytes' of value -1 >> > for example. >> >> Detect what that way, a negative sizeof()? > This 'nbytes' maybe a variable, and happens to be -1? No, it can't. Why would it? > Also, it is > symmetric if the range of return value(number of bytes read) is equal > to the range of 'nbytes'. But nbytes is a size of a buffer, just like the native read() has. What has it to do with a return value of a function that can be negative too? There is never anything returned, it's only ever passed in, it's just a size parameter. Kay _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel