xref: /csrg-svn/lib/libutil/logwtmp.c (revision 41464)
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*41464Skarels static char sccsid[] = "@(#)logwtmp.c	5.4 (Berkeley) 05/08/90";
2035456Sbostic #endif /* LIBC_SCCS and not lint */
2135456Sbostic 
2235456Sbostic #include <sys/types.h>
2335456Sbostic #include <sys/file.h>
2435456Sbostic #include <sys/time.h>
2535605Sbostic #include <sys/stat.h>
2635456Sbostic #include <utmp.h>
2735456Sbostic 
2835605Sbostic logwtmp(line, name, host)
2935605Sbostic 	char *line, *name, *host;
3035456Sbostic {
3135456Sbostic 	struct utmp ut;
3235605Sbostic 	struct stat buf;
3335456Sbostic 	int fd;
3435456Sbostic 	time_t time();
3535456Sbostic 	char *strncpy();
3635456Sbostic 
3737273Sbostic 	if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
3835456Sbostic 		return;
39*41464Skarels 	if (fstat(fd, &buf) == 0) {
40*41464Skarels 		(void) strncpy(ut.ut_line, line, sizeof(ut.ut_line));
41*41464Skarels 		(void) strncpy(ut.ut_name, name, sizeof(ut.ut_name));
42*41464Skarels 		(void) strncpy(ut.ut_host, host, sizeof(ut.ut_host));
43*41464Skarels 		(void) time(&ut.ut_time);
4435605Sbostic 		if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
4535605Sbostic 		    sizeof(struct utmp))
4635605Sbostic 			(void) ftruncate(fd, buf.st_size);
4735605Sbostic 	}
48*41464Skarels 	(void) close(fd);
4935456Sbostic }
50