X-Git-Url: https://ruderich.org/simon/gitweb/?p=coloredstderr%2Fcoloredstderr.git;a=blobdiff_plain;f=src%2Fdebug.h;h=7425ce475f8c49f475f4dba01d48408ee65f547b;hp=aebd88c29342815c8f6773aa08f81068f2bb999b;hb=dfd317650f05542db49d7bc37649a232f28efa3f;hpb=fe3f7d4c635b265c58efd5bc420d32135ec7903e diff --git a/src/debug.h b/src/debug.h index aebd88c..7425ce4 100644 --- a/src/debug.h +++ b/src/debug.h @@ -44,10 +44,13 @@ static void debug_write(int fd, int first_call, char const *format, va_list ap) 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 +60,18 @@ static void debug(char const *format, ...) { va_start(ap, format); debug_write(fd, call_count == 1, format, ap); va_end(ap); + + errno = saved_errno; } static void warning(char const *format, ...) { va_list ap; + int saved_errno = errno; + char const *home = getenv("HOME"); if (!home) { + errno = saved_errno; return; } @@ -75,6 +83,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 +93,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