xref: /original-bsd/lib/libutil/login.c (revision bea2661b)
18ebd71b4Sbostic /*
2*bea2661bSbostic  * Copyright (c) 1988, 1993
3*bea2661bSbostic  *	The Regents of the University of California.  All rights reserved.
48ebd71b4Sbostic  *
5c8db0038Sbostic  * %sccs.include.redist.c%
68ebd71b4Sbostic  */
78ebd71b4Sbostic 
88ebd71b4Sbostic #if defined(LIBC_SCCS) && !defined(lint)
9*bea2661bSbostic static char sccsid[] = "@(#)login.c	8.1 (Berkeley) 06/04/93";
108ebd71b4Sbostic #endif /* LIBC_SCCS and not lint */
118ebd71b4Sbostic 
128ebd71b4Sbostic #include <sys/types.h>
13e54999ffSbostic 
14e54999ffSbostic #include <fcntl.h>
15e54999ffSbostic #include <unistd.h>
16e54999ffSbostic #include <stdlib.h>
178ebd71b4Sbostic #include <utmp.h>
188ebd71b4Sbostic #include <stdio.h>
198ebd71b4Sbostic 
208ebd71b4Sbostic void
login(ut)218ebd71b4Sbostic login(ut)
228ebd71b4Sbostic 	struct utmp *ut;
238ebd71b4Sbostic {
248ebd71b4Sbostic 	register int fd;
258ebd71b4Sbostic 	int tty;
268ebd71b4Sbostic 
278ebd71b4Sbostic 	tty = ttyslot();
28f6ec0890Smckusick 	if (tty > 0 && (fd = open(_PATH_UTMP, O_WRONLY|O_CREAT, 0644)) >= 0) {
29e54999ffSbostic 		(void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), L_SET);
30e54999ffSbostic 		(void)write(fd, ut, sizeof(struct utmp));
318ebd71b4Sbostic 		(void)close(fd);
328ebd71b4Sbostic 	}
33955b1cc8Sbostic 	if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) {
34e54999ffSbostic 		(void)write(fd, ut, sizeof(struct utmp));
358ebd71b4Sbostic 		(void)close(fd);
368ebd71b4Sbostic 	}
378ebd71b4Sbostic }
38