functional: add mntent test
[libc-test.git] / src / functional / search_insque.c
blob0f4c3706eeedd5ab4739a41f3155f8340f1114a5
1 #ifndef _XOPEN_SOURCE
2 #define _XOPEN_SOURCE 700
3 #endif
4 #include <stdlib.h>
5 #include <search.h>
6 #include "test.h"
8 struct q {
9 struct q *n;
10 struct q *p;
11 int i;
14 static struct q *new(int i)
16 struct q *q = malloc(sizeof *q);
17 q->i = i;
18 return q;
21 int main()
23 struct q *q = new(0);
24 struct q *p;
25 int i;
27 insque(q, 0);
28 for (i = 1; i < 10; i++) {
29 insque(new(i), q);
30 q = q->n;
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;
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;