From 1a51e46e4a87e1cd9528ac5e5656011636e4086b Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Fri, 12 Jan 2018 08:18:30 +0100 Subject: support: Preserve errno in write_message, TEST_VERIFY and other checks These facilities could clobber errno, which makes it difficult to write certain checks because a specific order has to be used. --- support/check.c | 3 +++ support/support_test_compare_failure.c | 3 +++ support/support_test_verify_impl.c | 3 +++ support/write_message.c | 3 +++ 4 files changed, 12 insertions(+) (limited to 'support') diff --git a/support/check.c b/support/check.c index 688ed56..78f2b3c 100644 --- a/support/check.c +++ b/support/check.c @@ -18,6 +18,7 @@ #include +#include #include #include #include @@ -26,9 +27,11 @@ static void print_failure (const char *file, int line, const char *format, va_list ap) { + int saved_errno = errno; printf ("error: %s:%d: ", file, line); vprintf (format, ap); puts (""); + errno = saved_errno; } int diff --git a/support/support_test_compare_failure.c b/support/support_test_compare_failure.c index e5596fd..8eb51c4 100644 --- a/support/support_test_compare_failure.c +++ b/support/support_test_compare_failure.c @@ -16,6 +16,7 @@ License along with the GNU C Library; if not, see . */ +#include #include #include @@ -44,6 +45,7 @@ support_test_compare_failure (const char *file, int line, int right_positive, int right_size) { + int saved_errno = errno; support_record_failure (); if (left_size != right_size) printf ("%s:%d: numeric comparison failure (widths %d and %d)\n", @@ -52,4 +54,5 @@ support_test_compare_failure (const char *file, int line, printf ("%s:%d: numeric comparison failure\n", file, line); report (" left", left_expr, left_value, left_positive, left_size); report ("right", right_expr, right_value, right_positive, right_size); + errno = saved_errno; } diff --git a/support/support_test_verify_impl.c b/support/support_test_verify_impl.c index 80311a8..5ff5555 100644 --- a/support/support_test_verify_impl.c +++ b/support/support_test_verify_impl.c @@ -18,14 +18,17 @@ #include +#include #include #include void support_test_verify_impl (const char *file, int line, const char *expr) { + int saved_errno = errno; support_record_failure (); printf ("error: %s:%d: not true: %s\n", file, line, expr); + errno = saved_errno; } void diff --git a/support/write_message.c b/support/write_message.c index 9d0f267..a3e2f90 100644 --- a/support/write_message.c +++ b/support/write_message.c @@ -18,12 +18,15 @@ #include +#include #include #include void write_message (const char *message) { + int saved_errno = errno; ssize_t unused __attribute__ ((unused)); unused = write (STDOUT_FILENO, message, strlen (message)); + errno = saved_errno; } -- cgit v1.1