home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 February
/
CHIP_2_98.iso
/
misc
/
src
/
install
/
log.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-09-17
|
1KB
|
70 lines
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "log.h"
static FILE * logfile = NULL;
static int logfd;
static int logDebugMessages = 0;
static void doLogMessage(char * s, va_list args);
void logMessage(char * s, ...) {
va_list args;
va_start(args, s);
doLogMessage(s, args);
va_end(args);
return;
}
void doLogDebugMessage(char * s, ...) {
va_list args;
if (!logDebugMessages) return;
va_start(args, s);
doLogMessage(s, args);
va_end(args);
return;
}
static void doLogMessage(char * s, va_list args) {
if (!logfile) return;
fprintf(logfile, "* ");
vfprintf(logfile, s, args);
fprintf(logfile, "\n");
fflush(logfile);
}
void openLog(void) {
if (!testing) {
logfile = fopen("/dev/tty3", "w");
if (logfile)
logfd = open("/dev/tty3", O_WRONLY);
else {
logfile = fopen("/tmp/install.log", "a");
logfd = open("/tmp/install.log", O_WRONLY| O_APPEND);
}
} else {
logfile = fopen("debug.log", "w");
logfd = open("debug.log", O_WRONLY);
}
if (getenv("DEBUG")) logDebugMessages = 1;
}
void closeLog(void) {
if (logfile) {
fclose(logfile);
close(logfd);
}
}