original netbsd's tr(1)
[minix.git] / commands / zoneinfo / logwtmp.c
blob9840df4c4fef166e7a41135f11bf9894477977d8
1 #ifndef lint
2 #ifndef NOID
3 static char elsieid[] = "@(#)logwtmp.c 7.7";
4 /* As received from UCB, with include reordering and OLD_TIME condition. */
5 #endif /* !defined NOID */
6 #endif /* !defined lint */
8 /*
9 * Copyright (c) 1988 The Regents of the University of California.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms are permitted
13 * provided that the above copyright notice and this paragraph are
14 * duplicated in all such forms and that any documentation,
15 * advertising materials, and other materials related to such
16 * distribution and use acknowledge that the software was developed
17 * by the University of California, Berkeley. The name of the
18 * University may not be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
22 * WARRANTIES OF MERCHANT[A]BILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25 #ifndef lint
26 #ifdef LIBC_SCCS
27 static char sccsid[] = "@(#)logwtmp.c 5.2 (Berkeley) 9/20/88";
28 #endif /* defined LIBC_SCCS */
29 #endif /* !defined lint */
31 #include <sys/types.h>
32 #include <time.h>
33 #include <utmp.h>
34 #include <fcntl.h>
35 #include <stdlib.h>
36 #include <unistd.h>
37 #include <string.h>
39 #ifdef OLD_TIME
41 char dummy_to_keep_linker_happy;
43 #endif /* defined OLD_TIME */
45 #ifndef OLD_TIME
47 #include <sys/file.h>
48 #include <sys/time.h>
49 #include <sys/stat.h>
51 #define WTMPFILE "/usr/adm/wtmp"
53 void logwtmp( char *line, char *name, char *host)
55 struct utmp ut;
56 struct stat buf;
57 int fd;
59 if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
60 return;
61 if (!fstat(fd, &buf)) {
62 (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
63 (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
64 (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
65 (void)time(&ut.ut_time);
66 if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
67 sizeof(struct utmp))
68 (void)ftruncate(fd, buf.st_size);
70 (void)close(fd);
73 #endif /* !defined OLD_TIME */