xref: /original-bsd/lib/libutil/logwtmp.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1988, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)logwtmp.c	8.1 (Berkeley) 06/04/93";
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 
17 #include <unistd.h>
18 #include <utmp.h>
19 
20 logwtmp(line, name, host)
21 	char *line, *name, *host;
22 {
23 	struct utmp ut;
24 	struct stat buf;
25 	int fd;
26 	time_t time();
27 	char *strncpy();
28 
29 	if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
30 		return;
31 	if (fstat(fd, &buf) == 0) {
32 		(void) strncpy(ut.ut_line, line, sizeof(ut.ut_line));
33 		(void) strncpy(ut.ut_name, name, sizeof(ut.ut_name));
34 		(void) strncpy(ut.ut_host, host, sizeof(ut.ut_host));
35 		(void) time(&ut.ut_time);
36 		if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
37 		    sizeof(struct utmp))
38 			(void) ftruncate(fd, buf.st_size);
39 	}
40 	(void) close(fd);
41 }
42