- char *base, *n, name[PATH_MAX];
- int nlinks;
- DIR *dir;
- struct dirent *dp;
- struct stat st;
-
- /*
- * Keep track of number of directories we've seen so we can
- * stop stat'ing entries in this directory once we've seen
- * them all. This optimization will fail if you have extra
- * directories beginning with ".", since we don't bother to
- * stat them. But that shouldn't generally be a problem.
- */
- nlinks = s->st_nlink;
-
- if (!(dir = opendir(dirName)))
- adios(dirName, "can't open directory");
-
- /*
- * A hack so that we don't see a
- * leading "./" in folder names.
- */
- base = strcmp (dirName, ".") ? dirName : dirName + 1;
-
- while (nlinks && (dp = readdir(dir))) {
- if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) {
- nlinks--;
- continue;
- }
- if (dp->d_name[0] == '.')
- continue;
- /* Check to see if the name of the file is a number
- * if it is, we assume it's a mail file and skip it
- */
- for (n = dp->d_name; *n && isdigit(*n); n++);
- if (!*n)
- continue;
- strncpy (name, base, sizeof(name) - 2);
- if (*base)
- strcat(name, "/");
- strncat(name, dp->d_name, sizeof(name) - strlen(name) - 1);
- if ((stat(name, &st) != -1) && S_ISDIR(st.st_mode)) {
- /*
- * Check if this was really a symbolic link pointing
- * to a directory. If not, then decrement link count.
- */
- if (lstat (name, &st) == -1)
- nlinks--;
- /* Add this folder to the list */
- if (AddFolder(name, showzero) &&
- (recurse || searchdepth) && st.st_nlink > 2)
- BuildFolderListRecurse(name, &st, searchdepth - 1);
+ char *base, name[PATH_MAX];
+ unsigned char *n;
+ int nlinks;
+ DIR *dir;
+ struct dirent *dp;
+ struct stat st;
+
+ /*
+ ** Keep track of number of directories we've seen so we can
+ ** stop stat'ing entries in this directory once we've seen
+ ** them all. This optimization will fail if you have extra
+ ** directories beginning with ".", since we don't bother to
+ ** stat them. But that shouldn't generally be a problem.
+ */
+ nlinks = s->st_nlink;
+
+ if (!(dir = opendir(dirName)))
+ adios(dirName, "can't open directory");
+
+ /*
+ ** A hack so that we don't see a
+ ** leading "./" in folder names.
+ */
+ base = (strcmp(dirName, ".")==0) ? dirName + 1 : dirName;
+
+ while (nlinks && (dp = readdir(dir))) {
+ if (strcmp(dp->d_name, ".")==0 ||
+ strcmp(dp->d_name, "..")==0) {
+ nlinks--;
+ continue;
+ }
+ if (dp->d_name[0] == '.')
+ continue;
+ /* Check to see if the name of the file is a number
+ ** if it is, we assume it's a mail file and skip it
+ */
+ for (n = dp->d_name; *n && isdigit(*n); n++);
+ if (!*n)
+ continue;
+ strncpy(name, base, sizeof(name) - 2);
+ if (*base)
+ strcat(name, "/");
+ strncat(name, dp->d_name, sizeof(name) - strlen(name) - 1);
+ if ((stat(name, &st) != -1) && S_ISDIR(st.st_mode)) {
+ /*
+ ** Check if this was really a symbolic link pointing
+ ** to a directory. If not, then decrement link count.
+ */
+ if (lstat(name, &st) == -1)
+ nlinks--;
+ /* Add this folder to the list */
+ if (AddFolder(name, showzero) &&
+ (recurse || searchdepth) &&
+ st.st_nlink > 2)
+ BuildFolderListRecurse(name, &st,
+ searchdepth - 1);
+ }