support: Add xstrndup, xunlink, xreadlink, support_create_temp_directory
[glibc.git] / stdlib / bug-getcontext.c
blob163400acba4ac0f4ab735afa797633d93b764bcc
1 /* BZ 12420 */
3 #include <errno.h>
4 #include <fenv.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <ucontext.h>
8 #include <libc-diag.h>
10 static int
11 do_test (void)
13 if (FE_ALL_EXCEPT == 0)
15 printf("Skipping test; no support for FP exceptions.\n");
16 return 0;
19 int except_mask = 0;
20 #ifdef FE_DIVBYZERO
21 except_mask |= FE_DIVBYZERO;
22 #endif
23 #ifdef FE_INVALID
24 except_mask |= FE_INVALID;
25 #endif
26 #ifdef FE_OVERFLOW
27 except_mask |= FE_OVERFLOW;
28 #endif
29 #ifdef FE_UNDERFLOW
30 except_mask |= FE_UNDERFLOW;
31 #endif
32 int status = feenableexcept (except_mask);
34 except_mask = fegetexcept ();
35 if (except_mask == -1)
37 printf("\nBefore getcontext(): fegetexcept returned: %d\n",
38 except_mask);
39 return 1;
42 ucontext_t ctx;
43 status = getcontext(&ctx);
44 if (status)
46 printf("\ngetcontext failed, errno: %d.\n", errno);
47 return 1;
50 printf ("\nDone with getcontext()!\n");
51 fflush (NULL);
53 /* On nios2 and tilepro, GCC 5 warns that except_mask may be used
54 uninitialized. Because it is always initialized and nothing in
55 this test ever calls setcontext (a setcontext call could result
56 in local variables being clobbered on the second return from
57 getcontext), in fact an uninitialized use is not possible. */
58 DIAG_PUSH_NEEDS_COMMENT;
59 DIAG_IGNORE_NEEDS_COMMENT (5, "-Wmaybe-uninitialized");
60 int mask = fegetexcept ();
61 if (mask != except_mask)
63 printf("\nAfter getcontext(): fegetexcept returned: %d, expected: %d.\n",
64 mask, except_mask);
65 return 1;
68 printf("\nAt end fegetexcept() returned %d, expected: %d.\n",
69 mask, except_mask);
70 DIAG_POP_NEEDS_COMMENT;
72 return 0;
75 #define TEST_FUNCTION do_test ()
76 #include "../test-skeleton.c"