add _DEFAULT_SOURCE wherever _BSD_SOURCE was used
[libc-test] / src / functional / search_insque.c
1 #ifndef _XOPEN_SOURCE
2 #define _XOPEN_SOURCE 700
3 #endif
4 #include <stdlib.h>
5 #include <search.h>
6 #include "test.h"
7
8 struct q {
9         struct q *n;
10         struct q *p;
11         int i;
12 };
13
14 static struct q *new(int i)
15 {
16         struct q *q = malloc(sizeof *q);
17         q->i = i;
18         return q;
19 }
20
21 int main()
22 {
23         struct q *q = new(0);
24         struct q *p;
25         int i;
26
27         insque(q, 0);
28         for (i = 1; i < 10; i++) {
29                 insque(new(i), q);
30                 q = q->n;
31         }
32         p = q;
33         while (q) {
34                 if (q->i != --i)
35                         t_error("walking queue: got %d, wanted %d\n", q->i, i);
36                 q = q->p;
37         }
38         remque(p->p);
39         if (p->p->i != p->i-2)
40                 t_error("remque: got %d, wanted %d\n", p->p->i, p->i-2);
41         if (p->p->n->i != p->i)
42                 t_error("remque: got %d, wanted %d\n", p->p->n->i, p->i);
43         return t_status;
44 }