sgl

view src/log.c @ 40:f7de32814f34

sortof made the ios backend to compile and run ... sortof
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 28 Jun 2012 03:42:26 +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 }