xref: /csrg-svn/lib/libutil/logwtmp.c (revision 35605)
135456Sbostic /*
235456Sbostic  * Copyright (c) 1988 The Regents of the University of California.
335456Sbostic  * All rights reserved.
435456Sbostic  *
535456Sbostic  * Redistribution and use in source and binary forms are permitted
635456Sbostic  * provided that the above copyright notice and this paragraph are
735456Sbostic  * duplicated in all such forms and that any documentation,
835456Sbostic  * advertising materials, and other materials related to such
935456Sbostic  * distribution and use acknowledge that the software was developed
1035456Sbostic  * by the University of California, Berkeley.  The name of the
1135456Sbostic  * University may not be used to endorse or promote products derived
1235456Sbostic  * from this software without specific prior written permission.
1335456Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1435456Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1535456Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1635456Sbostic  */
1735456Sbostic 
1835456Sbostic #if defined(LIBC_SCCS) && !defined(lint)
19*35605Sbostic static char sccsid[] = "@(#)logwtmp.c	5.2 (Berkeley) 09/20/88";
2035456Sbostic #endif /* LIBC_SCCS and not lint */
2135456Sbostic 
2235456Sbostic #include <sys/types.h>
2335456Sbostic #include <sys/file.h>
2435456Sbostic #include <sys/time.h>
25*35605Sbostic #include <sys/stat.h>
2635456Sbostic #include <utmp.h>
2735456Sbostic 
2835456Sbostic #define	WTMPFILE	"/usr/adm/wtmp"
2935456Sbostic 
30*35605Sbostic logwtmp(line, name, host)
31*35605Sbostic 	char *line, *name, *host;
3235456Sbostic {
3335456Sbostic 	struct utmp ut;
34*35605Sbostic 	struct stat buf;
3535456Sbostic 	int fd;
3635456Sbostic 	time_t time();
3735456Sbostic 	char *strncpy();
3835456Sbostic 
3935456Sbostic 	if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
4035456Sbostic 		return;
41*35605Sbostic 	if (!fstat(fd, &buf)) {
42*35605Sbostic 		(void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
43*35605Sbostic 		(void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
44*35605Sbostic 		(void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
45*35605Sbostic 		(void)time(&ut.ut_time);
46*35605Sbostic 		if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
47*35605Sbostic 		    sizeof(struct utmp))
48*35605Sbostic 			(void) ftruncate(fd, buf.st_size);
49*35605Sbostic 	}
5035456Sbostic 	(void)close(fd);
5135456Sbostic }
52