diff options
Diffstat (limited to 'lib/lib.c')
-rw-r--r-- | lib/lib.c | 62 |
1 files changed, 0 insertions, 62 deletions
@@ -549,65 +549,3 @@ void xpidfile(char *name) xwrite(fd, spid, sprintf(spid, "%ld\n", (long)getpid())); close(fd); } - -// Create a dirtree node from a path. - -struct dirtree *read_dirtree_node(char *path) -{ - struct dirtree *dt; - char *name; - - // Find last chunk of name. - - for (;;) { - name = strrchr(path, '/'); - - if (!name) name = path; - else { - if (*(name+1)) name++; - else { - *name=0; - continue; - } - } - break; - } - - dt = xzalloc(sizeof(struct dirtree)+strlen(name)+1); - xstat(path, &(dt->st)); - strcpy(dt->name, name); - - return dt; -} - -// Given a directory (in a writeable PATH_MAX buffer), recursively read in a -// directory tree. - -struct dirtree *read_dirtree(char *path, struct dirtree *parent) -{ - struct dirtree *dt = NULL, **ddt = &dt; - DIR *dir; - int len = strlen(path); - - if (!(dir = opendir(path))) perror_msg("No %s", path); - - for (;;) { - struct dirent *entry = readdir(dir); - if (!entry) break; - - // Skip "." and ".." - if (entry->d_name[0]=='.') { - if (!entry->d_name[1]) continue; - if (entry->d_name[1]=='.' && !entry->d_name[2]) continue; - } - - snprintf(path+len, sizeof(toybuf)-len, "/%s", entry->d_name); - *ddt = read_dirtree_node(path); - (*ddt)->parent = parent; - if (entry->d_type == DT_DIR) (*ddt)->child = read_dirtree(path, *ddt); - ddt = &((*ddt)->next); - path[len]=0; - } - - return dt; -} |