diff --git a/common.c b/common.c index a63cbce91..cef60d0de 100644 --- a/common.c +++ b/common.c @@ -548,14 +548,17 @@ int read_blocked(int fd, void *buf, size_t count) void debug( int level, const wchar_t *msg, ... ) { va_list va; + string_buffer_t sb; string_buffer_t sb2; + + int errno_old = errno; - CHECK( msg, ); - if( level > debug_level ) return; + CHECK( msg, ); + sb_init( &sb ); sb_init( &sb2 ); @@ -570,6 +573,8 @@ void debug( int level, const wchar_t *msg, ... ) sb_destroy( &sb ); sb_destroy( &sb2 ); + + errno = errno_old; } void write_screen( const wchar_t *msg, string_buffer_t *buff ) diff --git a/common.h b/common.h index 323dd1cae..d6559cd0a 100644 --- a/common.h +++ b/common.h @@ -305,6 +305,10 @@ int read_blocked(int fd, void *buf, size_t count); Issue a debug message with printf-style string formating and automatic line breaking. The string will begin with the string \c program_name, followed by a colon and a whitespace. + + Because debug is often called to tell the user about an error, + before using wperror to give a specific error message, debug will + never ever modify the value of errno. \param level the priority of the message. Lower number means higher priority. Messages with a priority_number higher than \c debug_level will be ignored.. \param msg the message format string.