home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / wtmp.c < prev   
C/C++ Source or Header  |  1992-10-09  |  850b  |  44 lines

  1. /*
  2.  * BSD style wtmp updating routine Version 1.0 (c) S.R.Usher 1991.
  3.  * Modified 910126 dpg: uses non-buffered file ops, like utmp.c
  4.  */
  5.  
  6. #include <fcntl.h>
  7. #include <unistd.h>
  8. #include <string.h>
  9. #include <utmp.h>
  10.  
  11. #define WTMP_FILE    "/var/adm/wtmp"
  12.  
  13. void write_wtmp(line, name, host, time)
  14. char *line;
  15. char *name;
  16. char *host;
  17. unsigned long time;
  18. {
  19.     int fd;
  20.     struct utmp entry;
  21.  
  22.     if ((fd = open(WTMP_FILE, O_WRONLY | O_APPEND)) < 0)
  23.     {
  24. #ifdef DEBUG
  25.         perror("write_wtmp");
  26. #endif
  27.         return;
  28.     }
  29.  
  30. /*
  31.  * Note, doing this in this order means that it doesn't matter about the Null
  32.  * bytes strncpy adds the the strings if they are greater than 8/16 bytes!
  33.  */
  34.  
  35.     strncpy(entry.ut_line, line, 8);
  36.     strncpy(entry.ut_name, name, 8);
  37.     strncpy(entry.ut_host, host, 16);
  38.     entry.ut_time = time;
  39.  
  40.     write(fd, &entry, (unsigned) sizeof(struct utmp));
  41.  
  42.     close(fd);
  43. }
  44.