home *** CD-ROM | disk | FTP | other *** search
- #include <sys/types.h>
- #include <sys/uio.h>
- #include <errno.h>
-
- int readv(fd, iov, iovcnt)
- int fd;
- struct iovec *iov;
- int iovcnt;
- {
- int i,len, total;
- char *base;
-
- errno = 0;
- for (i=0,total=0; i<iovcnt; i++,iov++) {
- len = iov->iov_len;
- base = iov->iov_base;
- while (len > 0) {
- register int nbytes;
- nbytes = read(fd, base, len);
- if (nbytes < 0 && total == 0) {
- return(-1);
- }
- if (nbytes <= 0) {
- return(total);
- }
- errno = 0;
- len -= nbytes;
- total += nbytes;
- base += nbytes;
- }
- }
- return(total);
- }
-
- int
- writev(fd,iov,iovcnt)
- int fd;
- struct iovec *iov;
- int iovcnt;
- {
- int i,len,total;
- char *base;
-
- errno = 0;
- for (i=0,total=0; i<iovcnt; i++, iov++) {
- len = iov->iov_len;
- base = iov->iov_base;
- while (len > 0) {
- register int nbytes;
- nbytes = write(fd, base, len);
- if (nbytes < 0 && total == 0) {
- return(-1);
- }
- if (nbytes <= 0) {
- return(total);
- }
-
- errno = 0;
- len -= nbytes;
- total += nbytes;
- base += nbytes;
- }
- }
- return(total);
- }
-