Rev 43 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 43 | Rev 53 | ||
---|---|---|---|
Line 27... | Line 27... | ||
27 | #include <dirent.h> |
27 | #include <dirent.h> |
28 | #include <unistd.h> |
28 | #include <unistd.h> |
29 | 29 | ||
30 | #include <errno.h> |
30 | #include <errno.h> |
31 | 31 | ||
32 | #define PATH_MAX 255 |
32 | #define PATH_MAX2 255 |
33 | 33 | ||
34 | // ============================================================================ |
34 | // ============================================================================ |
35 | // Functions |
35 | // Functions |
36 | // ============================================================================ |
36 | // ============================================================================ |
37 | 37 | ||
Line 43... | Line 43... | ||
43 | 43 | ||
44 | // http://www.ibm.com/developerworks/aix/library/au-unix-readdir.html |
44 | // http://www.ibm.com/developerworks/aix/library/au-unix-readdir.html |
45 | 45 | ||
46 | void traverse(char *directory) |
46 | void traverse(char *directory) |
47 | { |
47 | { |
48 | char curdir[PATH_MAX]; |
48 | char curdir[PATH_MAX2]; |
49 | char curdir2[PATH_MAX]; |
49 | char curdir2[PATH_MAX2]; |
50 | 50 | ||
51 | getcwd(curdir, PATH_MAX); |
51 | getcwd(curdir, PATH_MAX2); |
52 | chdir(directory); |
52 | chdir(directory); |
53 | getcwd(curdir2, PATH_MAX); |
53 | getcwd(curdir2, PATH_MAX2); |
54 | 54 | ||
55 | DIR *dir = NULL; |
55 | DIR *dir = NULL; |
56 | struct dirent entry; |
56 | struct dirent entry; |
57 | struct dirent *entryPtr = NULL; |
57 | struct dirent *entryPtr = NULL; |
58 | int retval = 0; |
58 | int retval = 0; |
59 | char pathName[PATH_MAX + 1]; |
59 | char pathName[PATH_MAX2 + 1]; |
60 | char pfile[PATH_MAX + 1]; |
60 | char pfile[PATH_MAX2 + 1]; |
61 | 61 | ||
62 | /* Open the given directory, if you can. */ |
62 | /* Open the given directory, if you can. */ |
63 | dir = opendir(curdir2); |
63 | dir = opendir(curdir2); |
64 | if (dir == NULL) |
64 | if (dir == NULL) |
65 | { |
65 | { |
Line 68... | Line 68... | ||
68 | retval = readdir_r( dir, &entry, &entryPtr ); |
68 | retval = readdir_r( dir, &entry, &entryPtr ); |
69 | while( entryPtr != NULL ) |
69 | while( entryPtr != NULL ) |
70 | { |
70 | { |
71 | struct stat entryInfo; |
71 | struct stat entryInfo; |
72 | 72 | ||
73 | if( ( ! strncmp( entry.d_name, ".", PATH_MAX ) == 0 ) && |
73 | if( ( ! strncmp( entry.d_name, ".", PATH_MAX2 ) == 0 ) && |
74 | ( ! strncmp( entry.d_name, "..", PATH_MAX ) == 0 ) ) |
74 | ( ! strncmp( entry.d_name, "..", PATH_MAX2 ) == 0 ) ) |
75 | { |
75 | { |
76 | sprintf(pfile,"%s/%s", curdir2, entry.d_name); |
76 | sprintf(pfile,"%s/%s", curdir2, entry.d_name); |
77 | if (isdir(entry.d_name) && ! issymlink(entry.d_name)) |
77 | if (isdir(entry.d_name) && ! issymlink(entry.d_name)) |
78 | { |
78 | { |
79 | printf("%s\n", pfile); |
79 | printf("%s\n", pfile); |