(res_isourserver): Fix cast.
[glibc/pb-stable.git] / stdlib / tst-setcontext.c
blob6ee1b514a68d3a0b302ca5bee97320f5bbf5d900
1 /* Copyright (C) 2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #include <errno.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <ucontext.h>
24 static ucontext_t ctx[3];
26 static int was_in_f1;
27 static int was_in_f2;
29 static void
30 f1 (long a0, long a1, long a2, long a3)
32 printf ("start f1(a0=%lx,a1=%lx,a2=%lx,a3=%lx)\n", a0, a1, a2, a3);
34 if (a0 != 1 || a1 != 2 || a2 != 3 || a3 != -4)
36 puts ("arg mismatch");
37 exit (-1);
40 if (swapcontext (&ctx[1], &ctx[2]) != 0)
42 printf ("%s: swapcontext: %m\n", __FUNCTION__);
43 exit (1);
45 puts ("finish f1");
46 was_in_f1 = 1;
49 static void
50 f2 (void)
52 puts ("start f2");
53 if (swapcontext (&ctx[2], &ctx[1]) != 0)
55 printf ("%s: swapcontext: %m\n", __FUNCTION__);
56 exit (1);
58 puts ("finish f2");
59 was_in_f2 = 1;
62 int
63 main (void)
65 char st1[8192];
66 char st2[8192];
68 puts ("making contexts");
69 if (getcontext (&ctx[1]) != 0)
71 if (errno == ENOSYS)
72 exit (0);
74 printf ("%s: getcontext: %m\n", __FUNCTION__);
75 exit (1);
77 ctx[1].uc_stack.ss_sp = st1;
78 ctx[1].uc_stack.ss_size = sizeof st1;
79 ctx[1].uc_link = &ctx[0];
80 makecontext (&ctx[1], (void (*) (void)) f1, 4, 1, 2, 3, -4);
82 if (getcontext (&ctx[2]) != 0)
84 printf ("%s: second getcontext: %m\n", __FUNCTION__);
85 exit (1);
87 ctx[2].uc_stack.ss_sp = st2;
88 ctx[2].uc_stack.ss_size = sizeof st2;
89 ctx[2].uc_link = &ctx[1];
90 makecontext (&ctx[2], f2, 0);
92 puts ("swapping contexts");
93 if (swapcontext (&ctx[0], &ctx[2]) != 0)
95 printf ("%s: swapcontext: %m\n", __FUNCTION__);
96 exit (1);
98 puts ("back at main program");
100 if (was_in_f1 == 0)
102 puts ("didn't reach f1");
103 exit (1);
105 if (was_in_f2 == 0)
107 puts ("didn't reach f2");
108 exit (1);
111 puts ("test succeeded");
112 return 0;