functional: add mntent test
[libc-test.git] / src / functional / search_lsearch.c
blob711a7a085d86e5baca49d61e7907c6fd37d4426d
1 #ifndef _XOPEN_SOURCE
2 #define _XOPEN_SOURCE 700
3 #endif
4 #include <string.h>
5 #include <search.h>
6 #include "test.h"
8 #define W 80
9 static char tab[100][W];
10 static size_t nel;
12 #define set(k) do{ \
13 char *r = lsearch(k, tab, &nel, W, (int(*)(const void*,const void*))strcmp); \
14 if (strcmp(r, k) != 0) \
15 t_error("lsearch %s failed\n", #k); \
16 }while(0)
18 #define get(k) lfind(k, tab, &nel, W, (int(*)(const void*,const void*))strcmp)
20 int main()
22 size_t n;
24 set("");
25 set("a");
26 set("b");
27 set("abc");
28 set("cd");
29 set("e");
30 set("ef");
31 set("g");
32 set("h");
33 set("iiiiiiiiii");
34 if (!get("a"))
35 t_error("lfind a failed\n");
36 if (get("c"))
37 t_error("lfind c should fail\n");
38 n = nel;
39 set("g");
40 if (nel != n)
41 t_error("lsearch g should not modify the table size (%d, was %d)\n", nel, n);
42 n = nel;
43 set("j");
44 if (nel != n+1)
45 t_error("lsearch j should increase the table size (%d, was %d)\n", nel, n);
46 return t_status;