sgl

annotate 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
rev   line source
nuclear@4 1 #include <stdio.h>
nuclear@4 2 #include <stdlib.h>
nuclear@31 3 #include <string.h>
nuclear@31 4 #include <errno.h>
nuclear@4 5 #include <stdarg.h>
nuclear@4 6 #include "log.h"
nuclear@4 7
nuclear@4 8 void sgl_log(const char *fmt, ...)
nuclear@4 9 {
nuclear@31 10 static int first_run = 1;
nuclear@4 11 va_list ap;
nuclear@4 12 const char *logfile;
nuclear@4 13 FILE *fp;
nuclear@4 14
nuclear@31 15 if((logfile = getenv("SGL_LOG"))) {
nuclear@31 16 if(first_run) {
nuclear@31 17 remove(logfile);
nuclear@31 18 first_run = 0;
nuclear@31 19 }
nuclear@31 20 if(!(fp = fopen(logfile, "a"))) {
nuclear@31 21 fprintf(stderr, "failed to open logfile: %s: %s\n", logfile, strerror(errno));
nuclear@31 22 fp = stderr;
nuclear@31 23 }
nuclear@31 24 } else {
nuclear@4 25 fp = stderr;
nuclear@4 26 }
nuclear@4 27
nuclear@4 28 va_start(ap, fmt);
nuclear@4 29 vfprintf(fp, fmt, ap);
nuclear@4 30 va_end(ap);
nuclear@4 31
nuclear@5 32 if(fp != stderr) {
nuclear@5 33 fclose(fp);
nuclear@5 34 }
nuclear@4 35 }