home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / zoneinfo / src / logwtmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-12  |  2.0 KB  |  72 lines

  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 */
  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. #ifdef OLD_TIME
  35.  
  36. char dummy_to_keep_linker_happy;
  37.  
  38. #endif /* defined OLD_TIME */
  39.  
  40. #ifndef OLD_TIME
  41.  
  42. #include <sys/file.h>
  43. #include <sys/time.h>
  44. #include <sys/stat.h>
  45.  
  46. #define WTMPFILE    "/usr/adm/wtmp"
  47.  
  48. logwtmp(line, name, host)
  49.     char *line, *name, *host;
  50. {
  51.     struct utmp ut;
  52.     struct stat buf;
  53.     int fd;
  54.     time_t time();
  55.     char *strncpy();
  56.  
  57.     if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
  58.         return;
  59.     if (!fstat(fd, &buf)) {
  60.         (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
  61.         (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
  62.         (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
  63.         (void)time(&ut.ut_time);
  64.         if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
  65.             sizeof(struct utmp))
  66.                 (void)ftruncate(fd, buf.st_size);
  67.     }
  68.     (void)close(fd);
  69. }
  70.  
  71. #endif /* !defined OLD_TIME */
  72.