|
|
1.1 ! root 1: #include "decl.h" ! 2: #include <dir.h> ! 3: ! 4: int ! 5: isdir (Path& p) ! 6: { ! 7: struct stat sb; ! 8: ! 9: if (stat (p, &sb) < 0) ! 10: return 0; ! 11: return (sb.st_mode & S_IFMT) == S_IFDIR; ! 12: } ! 13: ! 14: static char* ! 15: charconv (String& s) ! 16: { ! 17: char *p = new char[s.length() + 1]; ! 18: s.dump (p); ! 19: return p; ! 20: } ! 21: ! 22: Path_list ! 23: dircontents (Path& p) ! 24: { ! 25: Path_list r; ! 26: char *cp = charconv (String(p)); ! 27: DIR *df = opendir (cp); ! 28: ! 29: if (df) { ! 30: direct *dp; ! 31: while (dp = readdir (df)) { ! 32: Path ds = dp->d_name; ! 33: if (ds != "." && ds != "..") { ! 34: Path_list_iterator i (r); ! 35: Path x; ! 36: ! 37: while (i.peekX (x) && x < ds) ! 38: i.next(); ! 39: ! 40: i.insert (ds); ! 41: } ! 42: } ! 43: ! 44: closedir (df); ! 45: } ! 46: ! 47: delete cp; ! 48: ! 49: return r; ! 50: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.