home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / nntp1.5 / part01 / server / fakesyslog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-18  |  1.5 KB  |  84 lines

  1. #ifndef lint
  2. static char    *sccsid = "@(#)fakesyslog.c    1.3    (Berkeley) 2/6/88";
  3. #endif
  4.  
  5. /*
  6.  * Fake syslog routines for systems that don't have syslog.
  7.  * Taken from an idea by Paul McKenny, <mckenny@sri-unix.arpa>.
  8.  * (Unfortunately, Paul, I can't distribute the real syslog code
  9.  * as you suggested ... sigh.)
  10.  *
  11.  * Warning: this file contains joe code that may offend you.
  12.  */
  13.  
  14. #include <stdio.h>
  15.  
  16. #include "../common/conf.h"
  17.  
  18. #ifdef FAKESYSLOG
  19.  
  20. extern    int    errno;
  21. extern    int    sys_nerr;
  22. extern    char    *sys_errlist[];
  23.  
  24. static FILE    *logfp;
  25.  
  26. char    *strcpy(), *strcat(), *ctime();
  27.  
  28. openlog()
  29. {
  30.     logfp = fopen(FAKESYSLOG, "a");
  31. }
  32.  
  33.  
  34. syslog(pri, msg, x1, x2, x3, x4, x5, x6)
  35.     int    pri;
  36.     char    *msg, *x1, *x2, *x3, *x4, *x5, *x6;
  37. {
  38.     char        buf[1024];
  39.     char        *cp, *bp;
  40.     long        clock;
  41.     static int    failed = 0;
  42.  
  43.     if (failed)
  44.         return;
  45.  
  46.     if (logfp == NULL) {
  47.         openlog();
  48.         if (logfp == NULL) {
  49.             failed = 1;
  50.             return;
  51.         }
  52.     }
  53.  
  54.     (void) time(&clock);
  55.     (void) strcpy(buf, ctime(&clock));
  56.  
  57.     bp = buf + strlen(buf)-1;
  58.     *bp++ = ' ';
  59.     *bp = '\0';
  60.     for (cp = msg; *cp; cp++) {
  61.         if (*cp == '%' && cp[1] == 'm') {
  62.             *bp = '\0';
  63.             if (errno >= sys_nerr || errno < 0) {
  64.                 char    work[32];
  65.                 sprintf(work, "unknown error #%d", errno);
  66.                 (void) strcat(bp, work);
  67.             } else
  68.                 (void) strcat(bp, sys_errlist[errno]);
  69.             bp = buf + strlen(buf);
  70.             cp++;
  71.         } else {
  72.             *bp++ = *cp;
  73.         }
  74.     }
  75.     *bp = '\0';
  76.     /* Ah, the semantic security of C ... */
  77.     if (bp[-1] != '\n')
  78.         (void) strcat(bp, "\n");
  79.  
  80.     fprintf(logfp, buf, x1, x2, x3, x4, x5, x6);
  81. }
  82.  
  83. #endif
  84.