home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / mntlib16.lzh / MNTLIB16 / WTMP.C < prev   
C/C++ Source or Header  |  1993-07-29  |  792b  |  42 lines

  1. /*
  2.  * BSD style wtmp updating routine Version 1.0 (c) S.R.Usher 1991.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <utmp.h>
  8.  
  9. #define WTMP_FILE    "/var/adm/wtmp"
  10.  
  11. void write_wtmp(line, name, host, time)
  12. char *line;
  13. char *name;
  14. char *host;
  15. unsigned long time;
  16. {
  17.     FILE *fp;
  18.     struct utmp entry;
  19.  
  20.     if ((fp = fopen(WTMP_FILE, "a")) == NULL)
  21.     {
  22. #ifdef DEBUG
  23.         perror("write_wtmp");
  24. #endif
  25.         return;
  26.     }
  27.  
  28. /*
  29.  * Note, doing this in this order means that it doesn't matter about the Null
  30.  * bytes strncpy adds the the strings if they are greater than 8/16 bytes!
  31.  */
  32.  
  33.     strncpy(entry.ut_line, line, 8);
  34.     strncpy(entry.ut_name, name, 8);
  35.     strncpy(entry.ut_host, host, 16);
  36.     entry.ut_time = time;
  37.  
  38.     fwrite(&entry, sizeof(struct utmp), 1, fp);
  39.  
  40.     fclose(fp);
  41. }
  42.