K
kid joe
Hi all,
I was thinking about interfaces like this one for Unix read
ssize_t read(int fd, void *buf, size_t count);
(I know that read isnt an ISO C function, but the question is nothing to
do with read, just the function interface).
The return value is -1 in case of error, or an integer between 0 and count
giving the number of bytes read into buf.
This seems like a poor choice to me.... If I pass SIZE_MAX for count, then
there's no way of distinguishing between an error (-1) and a successful
read of ((size_t) -1) bytes.
Wouldn't it be better for the function to return an unsigned size_t and
notify the caller of errors in another way (eg an extra parameter)?
Cheers,
Joe
I was thinking about interfaces like this one for Unix read
ssize_t read(int fd, void *buf, size_t count);
(I know that read isnt an ISO C function, but the question is nothing to
do with read, just the function interface).
The return value is -1 in case of error, or an integer between 0 and count
giving the number of bytes read into buf.
This seems like a poor choice to me.... If I pass SIZE_MAX for count, then
there's no way of distinguishing between an error (-1) and a successful
read of ((size_t) -1) bytes.
Wouldn't it be better for the function to return an unsigned size_t and
notify the caller of errors in another way (eg an extra parameter)?
Cheers,
Joe