home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / slackwar / a / util / util-lin.2 / util-lin / util-linux-2.2 / time / logwtmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-22  |  1.9 KB  |  66 lines

  1. #ifndef lint
  2. #ifndef NOID
  3. static char    elsieid[] = "@(#)logwtmp.c    7.4";
  4. /* As received from UCB, with include reordering and OLD_TIME condition. */
  5. #endif /* !defined NOID */
  6. #endif /* !defined lint */
  7.  
  8. /*
  9.  * Copyright (c) 1988 The Regents of the University of California.
  10.  * All rights reserved.
  11.  *
  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.
  23.  */
  24.  
  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 */
  30.  
  31. #include <sys/types.h>
  32. #include <utmp.h>
  33.  
  34. #ifndef OLD_TIME
  35.  
  36. #include <sys/file.h>
  37. #include <sys/time.h>
  38. #include <sys/stat.h>
  39.  
  40. #define WTMPFILE    "/usr/adm/wtmp"
  41.  
  42. logwtmp(line, name, host)
  43.     char *line, *name, *host;
  44. {
  45.     struct utmp ut;
  46.     struct stat buf;
  47.     int fd;
  48.     time_t time();
  49.     char *strncpy();
  50.  
  51.     if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
  52.         return;
  53.     if (!fstat(fd, &buf)) {
  54.         (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
  55.         (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
  56.         (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
  57.         (void)time(&ut.ut_time);
  58.         if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
  59.             sizeof(struct utmp))
  60.                 (void)ftruncate(fd, buf.st_size);
  61.     }
  62.     (void)close(fd);
  63. }
  64.  
  65. #endif /* !defined OLD_TIME */
  66.