X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=src%2Fdebug.h;h=4a7c00bc107949f2a9ab5b7aaea3c3c1452a429e;hb=8a58e07a5bc69ef7170faee373d070684d2f159d;hp=adc0792f1ce8b1e9e938b7503faf45edc724fdb9;hpb=31a1fdf921bf767154470e94f0f28c299d56cd5a;p=coloredstderr%2Fcoloredstderr.git diff --git a/src/debug.h b/src/debug.h index adc0792..4a7c00b 100644 --- a/src/debug.h +++ b/src/debug.h @@ -41,13 +41,17 @@ static void debug_write(int fd, int first_call, char const *format, va_list ap) real_close(fd); } +#ifdef DEBUG static void debug(char const *format, ...) { va_list ap; + int saved_errno = errno; + /* If the file doesn't exist, do nothing. Prevents writing log files in * unexpected places. The user must create the file manually. */ int fd = open(DEBUG_FILE, O_WRONLY | O_APPEND); if (fd == -1) { + errno = saved_errno; return; } @@ -57,13 +61,19 @@ static void debug(char const *format, ...) { va_start(ap, format); debug_write(fd, call_count == 1, format, ap); va_end(ap); + + errno = saved_errno; } +#endif static void warning(char const *format, ...) { va_list ap; - char *home = getenv("HOME"); + int saved_errno = errno; + + char const *home = getenv("HOME"); if (!home) { + errno = saved_errno; return; } @@ -75,6 +85,7 @@ static void warning(char const *format, ...) { /* Create the warning file if it doesn't exist yet. */ int fd = open(path, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR); if (fd == -1) { + errno = saved_errno; return; } @@ -84,6 +95,8 @@ static void warning(char const *format, ...) { va_start(ap, format); debug_write(fd, call_count == 1, format, ap); va_end(ap); + + errno = saved_errno; } #endif