Commit | Line | Data |
---|---|---|
b27de394 KB |
1 | /* |
2 | * Copyright (c) 1988 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
1343342a | 5 | * %sccs.include.redist.c% |
b27de394 KB |
6 | */ |
7 | ||
8 | #if defined(LIBC_SCCS) && !defined(lint) | |
1343342a | 9 | static char sccsid[] = "@(#)logwtmp.c 5.5 (Berkeley) %G%"; |
b27de394 KB |
10 | #endif /* LIBC_SCCS and not lint */ |
11 | ||
12 | #include <sys/types.h> | |
13 | #include <sys/file.h> | |
14 | #include <sys/time.h> | |
fdb7c742 | 15 | #include <sys/stat.h> |
b27de394 KB |
16 | #include <utmp.h> |
17 | ||
fdb7c742 KB |
18 | logwtmp(line, name, host) |
19 | char *line, *name, *host; | |
b27de394 KB |
20 | { |
21 | struct utmp ut; | |
fdb7c742 | 22 | struct stat buf; |
b27de394 KB |
23 | int fd; |
24 | time_t time(); | |
25 | char *strncpy(); | |
26 | ||
4a07d1a5 | 27 | if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0) |
b27de394 | 28 | return; |
a53c2dd2 MK |
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); | |
fdb7c742 KB |
34 | if (write(fd, (char *)&ut, sizeof(struct utmp)) != |
35 | sizeof(struct utmp)) | |
36 | (void) ftruncate(fd, buf.st_size); | |
37 | } | |
a53c2dd2 | 38 | (void) close(fd); |
b27de394 | 39 | } |