xref: /original-bsd/lib/libutil/logwtmp.c (revision 89a39cb6)
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[] = "@(#)logwtmp.c	5.5 (Berkeley) 06/01/90";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/types.h>
13 #include <sys/file.h>
14 #include <sys/time.h>
15 #include <sys/stat.h>
16 #include <utmp.h>
17 
18 logwtmp(line, name, host)
19 	char *line, *name, *host;
20 {
21 	struct utmp ut;
22 	struct stat buf;
23 	int fd;
24 	time_t time();
25 	char *strncpy();
26 
27 	if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
28 		return;
29 	if (fstat(fd, &buf) == 0) {
30 		(void) strncpy(ut.ut_line, line, sizeof(ut.ut_line));
31 		(void) strncpy(ut.ut_name, name, sizeof(ut.ut_name));
32 		(void) strncpy(ut.ut_host, host, sizeof(ut.ut_host));
33 		(void) time(&ut.ut_time);
34 		if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
35 		    sizeof(struct utmp))
36 			(void) ftruncate(fd, buf.st_size);
37 	}
38 	(void) close(fd);
39 }
40