sgl
view src/log.c @ 32:fc2dba4c5a5f
fuck yeah, I fixed the motherfucker, now let's roll
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 03 Jul 2011 05:23:30 +0300 |
parents | 0570e27e5ebc |
children |
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <stdarg.h>
6 #include "log.h"
8 void sgl_log(const char *fmt, ...)
9 {
10 static int first_run = 1;
11 va_list ap;
12 const char *logfile;
13 FILE *fp;
15 if((logfile = getenv("SGL_LOG"))) {
16 if(first_run) {
17 remove(logfile);
18 first_run = 0;
19 }
20 if(!(fp = fopen(logfile, "a"))) {
21 fprintf(stderr, "failed to open logfile: %s: %s\n", logfile, strerror(errno));
22 fp = stderr;
23 }
24 } else {
25 fp = stderr;
26 }
28 va_start(ap, fmt);
29 vfprintf(fp, fmt, ap);
30 va_end(ap);
32 if(fp != stderr) {
33 fclose(fp);
34 }
35 }