135456Sbostic /*
2*61346Sbostic * Copyright (c) 1988, 1993
3*61346Sbostic * The Regents of the University of California. All rights reserved.
435456Sbostic *
542662Sbostic * %sccs.include.redist.c%
635456Sbostic */
735456Sbostic
835456Sbostic #if defined(LIBC_SCCS) && !defined(lint)
9*61346Sbostic static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 06/04/93";
1035456Sbostic #endif /* LIBC_SCCS and not lint */
1135456Sbostic
1235456Sbostic #include <sys/types.h>
1335456Sbostic #include <sys/file.h>
1435456Sbostic #include <sys/time.h>
1535605Sbostic #include <sys/stat.h>
1660133Sbostic
1760133Sbostic #include <unistd.h>
1835456Sbostic #include <utmp.h>
1935456Sbostic
logwtmp(line,name,host)2035605Sbostic logwtmp(line, name, host)
2135605Sbostic char *line, *name, *host;
2235456Sbostic {
2335456Sbostic struct utmp ut;
2435605Sbostic struct stat buf;
2535456Sbostic int fd;
2635456Sbostic time_t time();
2735456Sbostic char *strncpy();
2835456Sbostic
2937273Sbostic if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
3035456Sbostic return;
3141464Skarels if (fstat(fd, &buf) == 0) {
3241464Skarels (void) strncpy(ut.ut_line, line, sizeof(ut.ut_line));
3341464Skarels (void) strncpy(ut.ut_name, name, sizeof(ut.ut_name));
3441464Skarels (void) strncpy(ut.ut_host, host, sizeof(ut.ut_host));
3541464Skarels (void) time(&ut.ut_time);
3635605Sbostic if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
3735605Sbostic sizeof(struct utmp))
3835605Sbostic (void) ftruncate(fd, buf.st_size);
3935605Sbostic }
4041464Skarels (void) close(fd);
4135456Sbostic }
42