Make sure debug() never alters errno, so that it can safely be called between an error and calling wperror()

darcs-hash:20061214100131-ac50b-b1c2e4819567fc35858233c265a26b934620fc6d.gz
This commit is contained in:
axel 2006-12-14 20:01:31 +10:00
parent b932a9a084
commit 52b74f9f34
2 changed files with 11 additions and 2 deletions

View File

@ -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 )

View File

@ -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.