X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fdos%2Flogger.c;h=70489ad8c09da828b78153433422191635411ea6;hb=c912e59b898fe1ac461a1468e4a2e1937de286d7;hp=73860e3cb44428fd94b0ba085d147100de9658de;hpb=8a64d603ee67cd98070360b40938e123ea845154;p=dosdemo diff --git a/src/dos/logger.c b/src/dos/logger.c index 73860e3..70489ad 100644 --- a/src/dos/logger.c +++ b/src/dos/logger.c @@ -1,46 +1,21 @@ -/* -colcycle - color cycling image viewer -Copyright (C) 2016 John Tsiombikas - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ #include -#include +#include +#include +#include +#include #include "logger.h" -#define LOGFNAME "demo.log" - -static FILE *logfile; - -void logger_output(FILE *fp) +int init_logger(const char *fname) { - if(logfile) fclose(logfile); - logfile = fp; -} - -void printlog(const char *fmt, ...) -{ - va_list ap; - - if(!logfile) { - if(!(logfile = fopen(LOGFNAME, "w"))) { - return; - } - setvbuf(logfile, 0, _IOLBF, 0); + int fd; + if((fd = open(fname, O_CREAT | O_WRONLY | O_TRUNC, 0644)) == -1) { + fprintf(stderr, "init_logger: failed to open %s: %s\n", fname, strerror(errno)); + return -1; } - va_start(ap, fmt); - vfprintf(logfile, fmt, ap); - va_end(ap); + close(1); + close(2); + dup(fd); + dup(fd); + return 0; }