"SfR Fresh" - the SfR Freeware/Shareware Archive 
Member "tulp-4.2.1/src/fakesyslog.c" of archive tulp-4.2.1.tar.gz:
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1 /*
2 * Fake syslog routines for systems that don't have syslog.
3 * Taken from an idea by Paul McKenny, <mckenny@sri-unix.arpa>.
4 * (Unfortunately, Paul, I can't distribute the real syslog code
5 * as you suggested ... sigh.)
6 *
7 * Warning: this file contains joe code that may offend you.
8 */
9
10 #include "conf.h"
11
12 RCSID("@(#)fakesyslog.c,v 1.3 1997/02/28 00:38:03 kim Exp")
13
14 #ifdef FAKESYSLOG
15
16 #include "fakesyslog.h"
17
18 #include <stdio.h>
19 #include <sys/signal.h>
20 #include <sys/types.h>
21
22 #ifdef FCNTL
23 #include <fcntl.h>
24 #endif
25
26 extern int errno;
27 extern int sys_nerr;
28 extern char *sys_errlist[];
29
30 static FILE *logfp;
31 static int failed = 0;
32 static char *ident = "syslog";
33 static int opt = 0;
34 static int fac = 0;
35
36 extern char *strcpy(), *strcat(), *ctime();
37 extern time_t time();
38
39 /* ARGSUSED */
40 void resetlog(int notused)
41 {
42 closelog();
43 failed = 0;
44 if (logfp == NULL) {
45 openlog(ident, opt, fac);
46 if (logfp == NULL) {
47 failed = 1;
48 return;
49 }
50 }
51 }
52
53 void openlog(char *newident, int logopt, int facility)
54 {
55 logfp = fopen(FAKESYSLOG, "a");
56
57 (void) signal(SIGHUP, resetlog);
58
59 if (newident && *newident)
60 ident = newident;
61 opt = logopt;
62 fac = facility;
63 }
64
65 void closelog()
66 {
67 if (logfp) {
68 (void) fclose(logfp);
69 failed = 0;
70 logfp = NULL;
71 }
72 }
73
74 /*ARGSUSED */
75 void setlogmask(int maskpri)
76 {
77 }
78
79 void syslog(int pri, char *msg,
80 char *x1, char *x2, char *x3, char *x4, char *x5, char *x6)
81 {
82 char buf[1024];
83 char *cp, *bp;
84 time_t clock;
85
86 if (failed)
87 return;
88
89 if (logfp == NULL) {
90 openlog(ident, opt, fac);
91 if (logfp == NULL) {
92 failed = 1;
93 return;
94 }
95 }
96 (void) time(&clock);
97 (void) strcpy(buf, ctime(&clock) + 4);
98 *(bp = buf + 16) = '\0';
99
100 (void) sprintf(bp, "localhost %s", ident ? ident : "");
101 bp += strlen(bp);
102
103 if (opt & LOG_PID) {
104 /* don't cache getpid() - who knows when we'll fork() */
105 (void) sprintf(bp, "[%d]", getpid());
106 bp += strlen(bp);
107 }
108 if (ident) {
109 (void) strcat(bp, ": ");
110 bp += 2;
111 } else {
112 (void) strcat(bp, " ");
113 bp++;
114 }
115
116 for (cp = msg; *cp; cp++) {
117 if (*cp == '%' && cp[1] == 'm') {
118 *bp = '\0';
119 if (errno >= sys_nerr || errno < 0) {
120 char work[32];
121
122 (void) sprintf(work, "unknown error #%d", errno);
123 (void) strcat(bp, work);
124 } else
125 (void) strcat(bp, sys_errlist[errno]);
126 bp = buf + strlen(buf);
127 cp++;
128 } else {
129 *bp++ = *cp;
130 }
131 }
132 *bp = '\0';
133 /* Ah, the semantic security of C ... */
134 if (bp[-1] != '\n')
135 (void) strcat(bp, "\n");
136
137 fprintf(logfp, buf, x1, x2, x3, x4, x5, x6);
138 (void) fflush(logfp);
139 }
140
141 #endif /* FAKESYSLOG */