10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*3224Sraf * Common Development and Distribution License (the "License").
6*3224Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*3224Sraf
220Sstevel@tonic-gate /*
23*3224Sraf * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24*3224Sraf * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include "../common/compat.h"
300Sstevel@tonic-gate #include <stdio.h>
31*3224Sraf #include <errno.h>
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <unistd.h>
34*3224Sraf #include <sys/syscall.h>
350Sstevel@tonic-gate #include <sys/uio.h>
360Sstevel@tonic-gate
370Sstevel@tonic-gate /*
380Sstevel@tonic-gate * If reading from the utmp file, map the data to the SunOS 4.1
39*3224Sraf * format on the fly.
400Sstevel@tonic-gate */
410Sstevel@tonic-gate extern void to_utmp(char *, char *, int);
420Sstevel@tonic-gate
430Sstevel@tonic-gate int
readv(int fd,struct iovec * iov,int iovcnt)440Sstevel@tonic-gate readv(int fd, struct iovec *iov, int iovcnt)
450Sstevel@tonic-gate {
460Sstevel@tonic-gate return (bc_readv(fd, iov, iovcnt));
470Sstevel@tonic-gate }
480Sstevel@tonic-gate
490Sstevel@tonic-gate int
bc_readv(int fd,struct iovec * iov,int iovcnt)500Sstevel@tonic-gate bc_readv(int fd, struct iovec *iov, int iovcnt)
510Sstevel@tonic-gate {
520Sstevel@tonic-gate int fds, ret, off;
530Sstevel@tonic-gate int i, size, total = 0;
540Sstevel@tonic-gate char *nbuf;
55*3224Sraf
560Sstevel@tonic-gate if (fd_get(fd) != -1) { /* we're reading utmp (utmpx really) */
570Sstevel@tonic-gate for (i = 0; i < iovcnt; i++) {
580Sstevel@tonic-gate size = getmodsize(iov[i].iov_len,
590Sstevel@tonic-gate sizeof (struct compat_utmp),
600Sstevel@tonic-gate sizeof (struct utmpx));
610Sstevel@tonic-gate
620Sstevel@tonic-gate if ((nbuf = (void *)malloc(size)) == NULL) {
630Sstevel@tonic-gate fprintf(stderr, "readv: malloc failed\n");
640Sstevel@tonic-gate exit(-1);
650Sstevel@tonic-gate }
66*3224Sraf
670Sstevel@tonic-gate if ((ret = _read(fd, nbuf, size)) == -1) {
680Sstevel@tonic-gate if (errno == EAGAIN)
69*3224Sraf errno = EWOULDBLOCK;
700Sstevel@tonic-gate free(nbuf);
710Sstevel@tonic-gate return (-1);
720Sstevel@tonic-gate }
730Sstevel@tonic-gate
74*3224Sraf to_utmp(iov[i].iov_base, nbuf, ret);
75*3224Sraf
76*3224Sraf ret = getmodsize(ret, sizeof (struct utmpx),
77*3224Sraf sizeof (struct compat_utmp));
780Sstevel@tonic-gate total += ret;
790Sstevel@tonic-gate
800Sstevel@tonic-gate free(nbuf);
810Sstevel@tonic-gate }
820Sstevel@tonic-gate
830Sstevel@tonic-gate return (total);
840Sstevel@tonic-gate }
850Sstevel@tonic-gate
860Sstevel@tonic-gate if ((ret = _readv(fd, iov, iovcnt)) == -1) {
870Sstevel@tonic-gate if (errno == EAGAIN)
880Sstevel@tonic-gate errno = EWOULDBLOCK;
890Sstevel@tonic-gate }
900Sstevel@tonic-gate return (ret);
910Sstevel@tonic-gate }
92