分类: LINUX
2010-06-20 13:39:42
#include
ssize_t writen(int fd, const
void *vptr, size_t n)
{
const char *ptr = vptr;
size_t nleft = n;
ssize_t nwriten;
while (nleft > 0) {
if (
(nwriten = write(fd, ptr, nleft)) <= 0)
return (nwriten);
nleft
-= nwriten;
ptr
+= nwriten;
}
return(n);
}
ssize_t readn(int fd, const void
*vptr, size_t n)
{
const char *ptr = vptr;
size_t nleft = n;
ssize_t nread;
while (nleft > 0) {
if (
(nread = read(fd, ptr, nleft)) <= 0)
return (nread);
nleft
-= nread;
ptr
+= nread;
}
return(n - nleft);
}