xref: /freebsd/contrib/mandoc/test-fts.c (revision e0c4386e)
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <fts.h>
4 #include <stdio.h>
5 #include <string.h>
6 
7 #ifdef FTS_COMPARE_CONST
8 int fts_compare(const FTSENT *const *, const FTSENT *const *);
9 #else
10 int fts_compare(const FTSENT **, const FTSENT **);
11 #endif
12 
13 int
14 main(void)
15 {
16 	const char	*argv[2];
17 	FTS		*ftsp;
18 	FTSENT		*entry;
19 
20 	argv[0] = ".";
21 	argv[1] = (char *)NULL;
22 
23 	ftsp = fts_open((char * const *)argv,
24 	    FTS_PHYSICAL | FTS_NOCHDIR, fts_compare);
25 
26 	if (ftsp == NULL) {
27 		perror("fts_open");
28 		return 1;
29 	}
30 
31 	entry = fts_read(ftsp);
32 
33 	if (entry == NULL) {
34 		perror("fts_read");
35 		return 1;
36 	}
37 
38 	if (fts_set(ftsp, entry, FTS_SKIP) != 0) {
39 		perror("fts_set");
40 		return 1;
41 	}
42 
43 	if (fts_close(ftsp) != 0) {
44 		perror("fts_close");
45 		return 1;
46 	}
47 
48 	return 0;
49 }
50 
51 int
52 #ifdef FTS_COMPARE_CONST
53 fts_compare(const FTSENT *const *a, const FTSENT *const *b)
54 #else
55 fts_compare(const FTSENT **a, const FTSENT **b)
56 #endif
57 {
58 	return strcmp((*a)->fts_name, (*b)->fts_name);
59 }
60