xref: /original-bsd/lib/libutil/login.c (revision 3b6250d9)
1 /*
2  * Copyright (c) 1988 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)login.c	5.4 (Berkeley) 06/01/90";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/types.h>
13 #include <sys/file.h>
14 #include <utmp.h>
15 #include <stdio.h>
16 
17 void
18 login(ut)
19 	struct utmp *ut;
20 {
21 	register int fd;
22 	int tty;
23 	off_t lseek();
24 
25 	tty = ttyslot();
26 	if (tty > 0 && (fd = open(_PATH_UTMP, O_WRONLY|O_CREAT, 0644)) >= 0) {
27 		(void)lseek(fd, (long)(tty * sizeof(struct utmp)), L_SET);
28 		(void)write(fd, (char *)ut, sizeof(struct utmp));
29 		(void)close(fd);
30 	}
31 	if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) {
32 		(void)write(fd, (char *)ut, sizeof(struct utmp));
33 		(void)close(fd);
34 	}
35 }
36