about summary refs log tree commit diff
path: root/REORG.TODO/assert/test-assert-perr.c
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2017-06-08 15:39:03 -0400
committerZack Weinberg <zackw@panix.com>2017-06-08 15:39:03 -0400
commit5046dbb4a7eba5eccfd258f92f4735c9ffc8d069 (patch)
tree4470480d904b65cf14ca524f96f79eca818c3eaf /REORG.TODO/assert/test-assert-perr.c
parent199fc19d3aaaf57944ef036e15904febe877fc93 (diff)
downloadglibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.tar.gz
glibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.tar.xz
glibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.zip
Prepare for radical source tree reorganization. zack/build-layout-experiment
All top-level files and directories are moved into a temporary storage
directory, REORG.TODO, except for files that will certainly still
exist in their current form at top level when we're done (COPYING,
COPYING.LIB, LICENSES, NEWS, README), all old ChangeLog files (which
are moved to the new directory OldChangeLogs, instead), and the
generated file INSTALL (which is just deleted; in the new order, there
will be no generated files checked into version control).
Diffstat (limited to 'REORG.TODO/assert/test-assert-perr.c')
-rw-r--r--REORG.TODO/assert/test-assert-perr.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/REORG.TODO/assert/test-assert-perr.c b/REORG.TODO/assert/test-assert-perr.c
new file mode 100644
index 0000000000..8496db6ffd
--- /dev/null
+++ b/REORG.TODO/assert/test-assert-perr.c
@@ -0,0 +1,86 @@
+/* Test assert_perror().
+ *
+ * This is hairier than you'd think, involving games with
+ * stdio and signals.
+ *
+ */
+
+#include <signal.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <setjmp.h>
+
+jmp_buf rec;
+char buf[160];
+
+static void
+sigabrt (int unused)
+{
+  longjmp (rec, 1);  /* recover control */
+}
+
+#undef NDEBUG
+#include <assert.h>
+static void
+assert1 (void)
+{
+  assert_perror (1);
+}
+
+static void
+assert2 (void)
+{
+  assert_perror (0);
+}
+
+#define NDEBUG
+#include <assert.h>
+static void
+assert3 (void)
+{
+  assert_perror (2);
+}
+
+int
+main(void)
+{
+  volatile int failed = 1;  /* safety in presence of longjmp() */
+
+  fclose (stderr);
+  stderr = tmpfile ();
+  if (!stderr)
+    abort ();
+
+  signal (SIGABRT, sigabrt);
+
+  if (!setjmp (rec))
+    assert1 ();
+  else
+    failed = 0;  /* should happen */
+
+  if (!setjmp (rec))
+    assert2 ();
+  else
+    failed = 1; /* should not happen */
+
+  if (!setjmp (rec))
+    assert3 ();
+  else
+    failed = 1; /* should not happen */
+
+  rewind (stderr);
+  fgets (buf, 160, stderr);
+  if (!strstr(buf, strerror (1)))
+    failed = 1;
+
+  fgets (buf, 160, stderr);
+  if (strstr (buf, strerror (0)))
+    failed = 1;
+
+  fgets (buf, 160, stderr);
+  if (strstr (buf, strerror (2)))
+    failed = 1;
+
+  return failed;
+}