sgl

annotate 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
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 }