equal
deleted
inserted
replaced
|
1 /** |
|
2 * fts.c file hierarchy browser |
|
3 */ |
|
4 |
|
5 #include <stdio.h> |
|
6 #include <stdlib.h> |
|
7 |
|
8 #include <sys/types.h> |
|
9 #include <sys/stat.h> |
|
10 |
|
11 #include <fts.h> |
|
12 |
|
13 int compare (const FTSENT ** a, const FTSENT ** b) |
|
14 { |
|
15 return 0; |
|
16 } |
|
17 |
|
18 int main (int argc, char **argv) |
|
19 { |
|
20 FTS *fts; |
|
21 FTSENT *current = NULL; |
|
22 |
|
23 char **paths; |
|
24 |
|
25 int i; |
|
26 |
|
27 if (argc < 2) { |
|
28 printf ("Usage: %s [dir]...\n", argv[0]); |
|
29 return EXIT_FAILURE; |
|
30 } |
|
31 |
|
32 if ((paths = calloc (argc + 1, sizeof (char *))) == NULL) { |
|
33 perror ("CALLOC"); |
|
34 return EXIT_FAILURE; |
|
35 } |
|
36 |
|
37 for (i = 1; i < argc; i++) { |
|
38 paths[i - 1] = argv[i]; |
|
39 } |
|
40 |
|
41 paths[i] = NULL; |
|
42 |
|
43 if ((fts = fts_open (paths, FTS_NOSTAT, &compare)) == NULL) { |
|
44 perror ("fts_open"); |
|
45 return EXIT_FAILURE; |
|
46 } |
|
47 |
|
48 while ((current = fts_read (fts)) != NULL) { |
|
49 printf ("%s/%s\n", current->fts_path, current->fts_name); |
|
50 } |
|
51 |
|
52 if (fts_close (fts) < 0) |
|
53 perror ("fts_close"); |
|
54 |
|
55 if (paths != NULL) |
|
56 free (paths); |
|
57 |
|
58 return EXIT_SUCCESS; |
|
59 } |