Reputation: 11
there is this function from the book "Unix network programming where there is a function "writen" declared as following:
ssize_t writen(int fd, const void *vptr, size_t n){
ssize_t nleft, nwritten;
const char *ptr;
ptr = vptr;
nleft = n;
while (nleft > 0) {
if ((nwritten = write(fd, ptr, nleft)) <= 0)
return nwritten; // error
nleft -= nwritten;
ptr += nwritten;
}
return n;
}
From what I checked in linux manual page:
size_t
Used for a count of bytes. It is the result of the sizeof() operator. It is an unsigned integer type capable of storing values in the range [0, SIZE_MAX].
ssize_t
Used for a count of bytes or an error indication. It is a signed integer type capable of storing values at least in the range [-1, SSIZE_MAX].
but {SIZE_MAX} = 65535 and SSIZE_MAX >= 32 767
Does this mean that whe using writen with n > 32767 I could get an overflow and the function would return fewer bytes then it actually had writen to the descriptor?
Upvotes: 0
Views: 20