sgl

diff 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 diff
     1.1 --- a/src/log.c	Tue Jun 28 13:52:02 2011 +0300
     1.2 +++ b/src/log.c	Sun Jul 03 04:33:32 2011 +0300
     1.3 @@ -1,15 +1,27 @@
     1.4  #include <stdio.h>
     1.5  #include <stdlib.h>
     1.6 +#include <string.h>
     1.7 +#include <errno.h>
     1.8  #include <stdarg.h>
     1.9  #include "log.h"
    1.10  
    1.11  void sgl_log(const char *fmt, ...)
    1.12  {
    1.13 +	static int first_run = 1;
    1.14  	va_list ap;
    1.15  	const char *logfile;
    1.16  	FILE *fp;
    1.17  
    1.18 -	if(!(logfile = getenv("SGL_LOG")) || !(fp = fopen(logfile, "a"))) {
    1.19 +	if((logfile = getenv("SGL_LOG"))) {
    1.20 +		if(first_run) {
    1.21 +			remove(logfile);
    1.22 +			first_run = 0;
    1.23 +		}
    1.24 +		if(!(fp = fopen(logfile, "a"))) {
    1.25 +			fprintf(stderr, "failed to open logfile: %s: %s\n", logfile, strerror(errno));
    1.26 +			fp = stderr;
    1.27 +		}
    1.28 +	} else {
    1.29  		fp = stderr;
    1.30  	}
    1.31