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
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.
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]
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "../common/compat.h"
31 #include <sys/errno.h>
32 #include <sys/types.h>
36 * If writing to a utmp-like file, map the utmp structure to
37 * new format on the fly.
41 extern int conv2utmp(char *, char *, int);
42 extern int conv2utmpx(char *, char *, int);
45 write(int fd
, char *buf
, int size
)
47 return (bc_write(fd
, buf
, size
));
51 bc_write(int fd
, char *buf
, int size
)
57 if (fd_get(fd
) != -1) { /* writing utmp (utmpx actually) */
58 nsize
= getmodsize(size
, sizeof (struct compat_utmp
),
59 sizeof (struct utmpx
));
61 if ((nbuf
= (void *)malloc(nsize
)) == NULL
) {
62 (void) fprintf(stderr
, "write: malloc failed\n");
66 (void) memset(nbuf
, 0, nsize
);
68 ret
= conv2utmpx(nbuf
, buf
, size
);
70 if ((ret
= _write(fd
, nbuf
, ret
)) == -1) {
79 ret
= getmodsize(ret
, sizeof (struct utmpx
),
80 sizeof (struct compat_utmp
));
85 if ((ret
= _write(fd
, buf
, size
)) == -1) {
93 /* From SunOS/SVR4 utmp.h */
94 #define USER_PROCESS 7
95 #define DEAD_PROCESS 8
98 conv2utmpx(char *nbuf
, char *buf
, int len
)
100 struct compat_utmp
*ut
;
103 utx
= (struct utmpx
*) nbuf
;
104 ut
= (struct compat_utmp
*) buf
;
106 while ((char *)ut
< (buf
+ len
)) {
107 (void) strcpy(utx
->ut_user
, ut
->ut_name
);
108 (void) memset(utx
->ut_id
, 0, sizeof (utx
->ut_id
));
109 (void) strcpy(utx
->ut_line
, ut
->ut_line
);
111 if ((strcmp(utx
->ut_user
, "") == 0) &&
112 (strcmp(utx
->ut_host
, "") == 0))
113 utx
->ut_type
= DEAD_PROCESS
;
115 utx
->ut_type
= USER_PROCESS
;
116 utx
->ut_exit
.e_termination
= 0;
117 utx
->ut_exit
.e_exit
= 0;
118 utx
->ut_tv
.tv_sec
= ut
->ut_time
;
119 utx
->ut_tv
.tv_usec
= 0;
121 utx
->ut_syslen
= sizeof (ut
->ut_name
) + 1;
122 (void) strcpy(utx
->ut_host
, ut
->ut_host
);
126 return ((char *) utx
- nbuf
);