home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2286 / sulog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  1.1 KB  |  65 lines

  1. /*
  2.  * Copyright 1989, 1990, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Use, duplication, and disclosure prohibited without
  6.  * the express written permission of the author.
  7.  */
  8.  
  9. #include <sys/types.h>
  10. #include <stdio.h>
  11. #include <time.h>
  12. #ifndef    BSD
  13. #include <string.h>
  14. #include <memory.h>
  15. #else
  16. #include <strings.h>
  17. #define    strchr    index
  18. #define    strrchr    rindex
  19. #endif
  20. #include "config.h"
  21.  
  22. #ifndef    lint
  23. static    char    sccsid[] = "@(#)sulog.c    2.2.1.1    09:09:55    11/26/90";
  24. #endif
  25.  
  26. extern    char    name[];
  27. extern    char    oldname[];
  28.  
  29. time_t    time ();
  30.  
  31. void    sulog (success)
  32. int    success;
  33. {
  34. #ifdef    SULOG
  35.     char    *tty;
  36.     char    *cp;
  37.     char    *ttyname ();
  38.     time_t    clock;
  39.     struct    tm    *tm;
  40.     struct    tm    *localtime ();
  41.     FILE    *fp;
  42.  
  43.     if ((fp = fopen (SULOG, "a+")) == (FILE *) 0)
  44.         return;            /* can't open or create logfile */
  45.  
  46.     (void) time (&clock);
  47.     tm = localtime (&clock);
  48.  
  49.     if (isatty (0) && (cp = ttyname (0))) {
  50.         if (tty = strrchr (cp, '/'))
  51.             tty++;
  52.         else
  53.             tty = cp;
  54.     } else
  55.         tty = "???";
  56.  
  57.     (void) fprintf (fp, "SU %.02d/%0.2d %.02d:%.02d %c %.6s %s-%s\n",
  58.         tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min,
  59.         success ? '+':'-', tty, oldname, name);
  60.  
  61.     fflush (fp);
  62.     fclose (fp);
  63. #endif
  64. }
  65.