sgl

view src/log.c @ 31:124195562f7e

FUCKING AUTORELEASE POOL
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 03 Jul 2011 04:33:32 +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 }