xref: /titanic_41/usr/src/lib/libbc/libc/sys/4.2/readv.c (revision 25cf1a301a396c38e8adf52c15f537b80d2483f7)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include "../common/compat.h"
30 #include <stdio.h>
31 #include <sys/errno.h>
32 #include <sys/types.h>
33 #include <unistd.h>
34 #include <syscall.h>
35 #include <sys/uio.h>
36 
37 extern int errno;
38 
39 /*
40  * If reading from the utmp file, map the data to the SunOS 4.1
41  * format on the fly.
42  */
43 extern void to_utmp(char *, char *, int);
44 
45 int
46 readv(int fd, struct iovec *iov, int iovcnt)
47 {
48 	return (bc_readv(fd, iov, iovcnt));
49 }
50 
51 int
52 bc_readv(int fd, struct iovec *iov, int iovcnt)
53 {
54 	int fds, ret, off;
55 	int i, size, total = 0;
56 	char *nbuf;
57 
58 	if (fd_get(fd) != -1) {	/* we're reading utmp (utmpx really) */
59 		for (i = 0; i < iovcnt; i++) {
60 			size = getmodsize(iov[i].iov_len,
61 			    sizeof (struct compat_utmp),
62 			    sizeof (struct utmpx));
63 
64 			if ((nbuf = (void *)malloc(size)) == NULL) {
65 				fprintf(stderr, "readv: malloc failed\n");
66 				exit(-1);
67 			}
68 
69 			if ((ret = _read(fd, nbuf, size)) == -1) {
70 				if (errno == EAGAIN)
71 					errno = EWOULDBLOCK;
72 				free(nbuf);
73 				return (-1);
74 			}
75 
76 			total += ret;
77 
78 			to_utmp(iov[i].iov_base, nbuf, ret);
79 
80 			ret = getmodsize(ret, sizeof (struct utmpx),
81 			    sizeof (struct compat_utmp));
82 			free(nbuf);
83 		}
84 
85 		return (total);
86 	}
87 
88 	if ((ret = _readv(fd, iov, iovcnt)) == -1) {
89 		if (errno == EAGAIN)
90 			errno = EWOULDBLOCK;
91 	}
92 	return (ret);
93 
94 }
95