X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Fdos%2Flogger.c;h=f7e9256e5a85993f20dcc5952f762ee4b257ee17;hp=73860e3cb44428fd94b0ba085d147100de9658de;hb=0b870b76705b3e597da3f6a11e0499deedbeee30;hpb=07ce18b114e1e01b2a85a04079128f3eb754de1d diff --git a/src/dos/logger.c b/src/dos/logger.c index 73860e3..f7e9256 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_WRONLY)) == -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; }