preserve errno when logging
Costa Tsaousis (ktsaou) committed
Apr 2, 2017 at 14:50 UTC
361aad695d09ba47a8929769a8477cb44cd3e119
1 file changed
+5
-2
src/log.c
+5
-2
@@ -298,6 +298,9 @@ static const char *strerror_result_string(const char *a, const char *b) { (void)
298
299
void error_int( const char *prefix, const char *file, const char *function, const unsigned long line, const char *fmt, ... )
300
{
301
+ // save a copy of errno - just in case this function generates a new error
302
+ int __errno = errno;
303
+
304
va_list args;
305
306
// prevent logging too much
@@ -311,9 +314,9 @@ void error_int( const char *prefix, const char *file, const char *function, cons
314
vfprintf( stderr, fmt, args );
315
va_end( args );
316
314
- if(errno) {
317
+ if(__errno) {
318
char buf[1024];
316
- fprintf(stderr, " (errno %d, %s)\n", errno, strerror_result(strerror_r(errno, buf, 1023), buf));
319
+ fprintf(stderr, " (errno %d, %s)\n", __errno, strerror_result(strerror_r(__errno, buf, 1023), buf));
320
errno = 0;
321
}
322
else