Skip to content

Commit 1a51e46

Browse files
committed
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.
1 parent 63b5288 commit 1a51e46

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

ChangeLog

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2018-01-12 Florian Weimer <[email protected]>
2+
3+
* support/write_message.c (write_message): Preserve errno.
4+
* support/check.c (print_failure): Likewise.
5+
* support/support_test_verify_impl.c (support_test_verify_impl):
6+
Likewise.
7+
* support/support_test_compare_failure.c
8+
(support_test_compare_failure): Likewise.
9+
110
2018-01-12 Florian Weimer <[email protected]>
211

312
[BZ #22701]

support/check.c

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <support/check.h>
2020

21+
#include <errno.h>
2122
#include <stdarg.h>
2223
#include <stdio.h>
2324
#include <stdlib.h>
@@ -26,9 +27,11 @@
2627
static void
2728
print_failure (const char *file, int line, const char *format, va_list ap)
2829
{
30+
int saved_errno = errno;
2931
printf ("error: %s:%d: ", file, line);
3032
vprintf (format, ap);
3133
puts ("");
34+
errno = saved_errno;
3235
}
3336

3437
int

support/support_test_compare_failure.c

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
License along with the GNU C Library; if not, see
1717
<http://www.gnu.org/licenses/>. */
1818

19+
#include <errno.h>
1920
#include <stdio.h>
2021
#include <support/check.h>
2122

@@ -44,6 +45,7 @@ support_test_compare_failure (const char *file, int line,
4445
int right_positive,
4546
int right_size)
4647
{
48+
int saved_errno = errno;
4749
support_record_failure ();
4850
if (left_size != right_size)
4951
printf ("%s:%d: numeric comparison failure (widths %d and %d)\n",
@@ -52,4 +54,5 @@ support_test_compare_failure (const char *file, int line,
5254
printf ("%s:%d: numeric comparison failure\n", file, line);
5355
report (" left", left_expr, left_value, left_positive, left_size);
5456
report ("right", right_expr, right_value, right_positive, right_size);
57+
errno = saved_errno;
5558
}

support/support_test_verify_impl.c

+3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818

1919
#include <support/check.h>
2020

21+
#include <errno.h>
2122
#include <stdio.h>
2223
#include <stdlib.h>
2324

2425
void
2526
support_test_verify_impl (const char *file, int line, const char *expr)
2627
{
28+
int saved_errno = errno;
2729
support_record_failure ();
2830
printf ("error: %s:%d: not true: %s\n", file, line, expr);
31+
errno = saved_errno;
2932
}
3033

3134
void

support/write_message.c

+3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818

1919
#include <support/support.h>
2020

21+
#include <errno.h>
2122
#include <string.h>
2223
#include <unistd.h>
2324

2425
void
2526
write_message (const char *message)
2627
{
28+
int saved_errno = errno;
2729
ssize_t unused __attribute__ ((unused));
2830
unused = write (STDOUT_FILENO, message, strlen (message));
31+
errno = saved_errno;
2932
}

0 commit comments

Comments
 (0)