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.
This commit is contained in:
parent
63b52889c3
commit
1a51e46e4a
|
@ -1,3 +1,12 @@
|
||||||
|
2018-01-12 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
|
* support/write_message.c (write_message): Preserve errno.
|
||||||
|
* support/check.c (print_failure): Likewise.
|
||||||
|
* support/support_test_verify_impl.c (support_test_verify_impl):
|
||||||
|
Likewise.
|
||||||
|
* support/support_test_compare_failure.c
|
||||||
|
(support_test_compare_failure): Likewise.
|
||||||
|
|
||||||
2018-01-12 Florian Weimer <fweimer@redhat.com>
|
2018-01-12 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
[BZ #22701]
|
[BZ #22701]
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include <support/check.h>
|
#include <support/check.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -26,9 +27,11 @@
|
||||||
static void
|
static void
|
||||||
print_failure (const char *file, int line, const char *format, va_list ap)
|
print_failure (const char *file, int line, const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
|
int saved_errno = errno;
|
||||||
printf ("error: %s:%d: ", file, line);
|
printf ("error: %s:%d: ", file, line);
|
||||||
vprintf (format, ap);
|
vprintf (format, ap);
|
||||||
puts ("");
|
puts ("");
|
||||||
|
errno = saved_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
License along with the GNU C Library; if not, see
|
License along with the GNU C Library; if not, see
|
||||||
<http://www.gnu.org/licenses/>. */
|
<http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <support/check.h>
|
#include <support/check.h>
|
||||||
|
|
||||||
|
@ -44,6 +45,7 @@ support_test_compare_failure (const char *file, int line,
|
||||||
int right_positive,
|
int right_positive,
|
||||||
int right_size)
|
int right_size)
|
||||||
{
|
{
|
||||||
|
int saved_errno = errno;
|
||||||
support_record_failure ();
|
support_record_failure ();
|
||||||
if (left_size != right_size)
|
if (left_size != right_size)
|
||||||
printf ("%s:%d: numeric comparison failure (widths %d and %d)\n",
|
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);
|
printf ("%s:%d: numeric comparison failure\n", file, line);
|
||||||
report (" left", left_expr, left_value, left_positive, left_size);
|
report (" left", left_expr, left_value, left_positive, left_size);
|
||||||
report ("right", right_expr, right_value, right_positive, right_size);
|
report ("right", right_expr, right_value, right_positive, right_size);
|
||||||
|
errno = saved_errno;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,17 @@
|
||||||
|
|
||||||
#include <support/check.h>
|
#include <support/check.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
support_test_verify_impl (const char *file, int line, const char *expr)
|
support_test_verify_impl (const char *file, int line, const char *expr)
|
||||||
{
|
{
|
||||||
|
int saved_errno = errno;
|
||||||
support_record_failure ();
|
support_record_failure ();
|
||||||
printf ("error: %s:%d: not true: %s\n", file, line, expr);
|
printf ("error: %s:%d: not true: %s\n", file, line, expr);
|
||||||
|
errno = saved_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -18,12 +18,15 @@
|
||||||
|
|
||||||
#include <support/support.h>
|
#include <support/support.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
write_message (const char *message)
|
write_message (const char *message)
|
||||||
{
|
{
|
||||||
|
int saved_errno = errno;
|
||||||
ssize_t unused __attribute__ ((unused));
|
ssize_t unused __attribute__ ((unused));
|
||||||
unused = write (STDOUT_FILENO, message, strlen (message));
|
unused = write (STDOUT_FILENO, message, strlen (message));
|
||||||
|
errno = saved_errno;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue