readn.c

时间:2021-01-25 15:10:47
#include <errno.h>
#include <unistd.h> ssize_t readn(int fd, void *vptr, size_t n) {
size_t nleft;
ssize_t nread;
char *ptr; ptr = vptr;
nleft = n;
while (nleft > ) {
if ( (nread = read(fd, ptr, nleft)) < ) {
if (errno == EINTR) {
nread = ; /* call read() again */
} else {
return (-);
}
} else if (nread == ) {
break; /* EOF */
}
nleft -= nread;
ptr += nread;
}
return (n - nleft);
} 函数功能:从一个描述符读n字节

相关文章