8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libbc / libc / sys / 4.2 / writev.c
blob2e54aa1439d0a6b0690cde6e579916a8ac2c4a21
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
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 <sys/uio.h>
37 * If writing to a utmp-like file, map the utmp structure to
38 * new format on the fly.
40 extern int errno;
42 extern int conv2utmpx(char *, char *, int);
44 int
45 writev(int fd, struct iovec *iov, int iovcnt)
47 return (bc_writev(fd, iov, iovcnt));
50 int
51 bc_writev(int fd, struct iovec *iov, int iovcnt)
53 int ret, off;
54 int nsize, total = 0;
55 char *nbuf;
56 int i;
58 if (fd_get(fd) != -1) { /* writing utmp (utmpx, actually) */
59 for (i = 0; i < iovcnt; i++) {
60 nsize = getmodsize(iov[i].iov_len,
61 sizeof (struct compat_utmp),
62 sizeof (struct utmpx));
64 if ((nbuf = (void *)malloc(nsize)) == NULL) {
65 fprintf(stderr, "writev: malloc failed\n");
66 exit(-1);
69 (void) memset(nbuf, 0, nsize);
71 ret = conv2utmpx(nbuf, iov[i].iov_base, iov[i].iov_len);
73 if ((ret = _write(fd, nbuf, ret)) == -1) {
74 if (errno == EAGAIN)
75 errno = EWOULDBLOCK;
76 free(nbuf);
77 return (-1);
80 free(nbuf);
82 ret = getmodsize(ret, sizeof (struct utmpx),
83 sizeof (struct compat_utmp));
84 total += ret;
86 return (total);
89 if ((ret = _writev(fd, iov, iovcnt)) == -1) {
90 if (errno == EAGAIN)
91 errno = EWOULDBLOCK;
94 return (ret);