Sync usage with man page.
[netbsd-mini2440.git] / regress / lib / libc / nsdispatch / recurse / recurse.c
blob1bf6f6dedd5aaa6e23937b4b2c38f5c9b3bee763
1 /* $NetBSD: recurse.c,v 1.2 2004/08/02 00:17:21 thorpej Exp $ */
3 /*
4 * Written by Jason R. Thorpe, August 1, 2004.
5 * Public domain.
6 */
8 #define _REENTRANT
10 #include <assert.h>
11 #include <nsswitch.h>
12 #include <stdarg.h>
13 #include <stdlib.h>
14 #include <pthread.h>
15 #include <stdio.h>
17 static const ns_src testsrc[] = {
18 { "test", NS_SUCCESS },
19 { 0 }
22 static int
23 func3(void *rv, void *cb_data, va_list ap)
26 printf("func3: enter\n");
27 printf("func3: exit\n");
28 return (NS_SUCCESS);
31 static int
32 func2(void *rv, void *cb_data, va_list ap)
34 static const ns_dtab dtab[] = {
35 { "test", func3, NULL },
36 { 0 }
38 int r;
40 printf("func2: enter\n");
41 r = nsdispatch(NULL, dtab, "test", "test", testsrc);
42 printf("func2: exit\n");
43 return (r);
46 static int
47 func1(void)
49 static const ns_dtab dtab[] = {
50 { "test", func2, NULL },
51 { 0 }
53 int r;
55 printf("func1: enter\n");
56 r = nsdispatch(NULL, dtab, "test", "test", testsrc);
57 printf("func1: exit\n");
58 return (r);
61 static void *
62 thrfunc(void *arg)
65 pthread_exit(NULL);
68 int
69 main(int argc, char *argv[])
71 pthread_t thr;
72 void *threval;
74 assert(pthread_create(&thr, NULL, thrfunc, NULL) == 0);
75 assert(func1() == NS_SUCCESS);
76 assert(pthread_join(thr, &threval) == 0);
77 exit(0);