void listfiles(t_arg *arg, t_ls *ls) { DIR *dirfd; struct stat filestat; t_ent *file; int symlink; symlink = 0; if (lstat(arg->path, &filestat) == 0) { dirfd = opendir(arg->path); if ((dirfd == NULL && errno != EACCES) || (symlink = symlinkexce(ls, arg, &filestat))) { file = newent(arg->path, &filestat); ls->files = addent(&ls->files, file); if (symlink) arg->read = 1; } if (dirfd) closedir(dirfd); } else { ft_putstr_fd("ls: ", 2); perror(arg->path); } }
/* * dodefine - install definition in the table */ void dodefine(const char *name, const char *defn) { ndptr p; int n; if (!*name) errx(1, "%s at line %lu: null definition.", CURRENT_NAME, CURRENT_LINE); if ((p = lookup(name)) == nil) p = addent(name); else if (p->defn != null) free((char *) p->defn); if (strncmp(defn, BUILTIN_MARKER, sizeof(BUILTIN_MARKER)-1) == 0) { n = builtin_type(defn+sizeof(BUILTIN_MARKER)-1); if (n != -1) { p->type = n & TYPEMASK; if ((n & NOARGS) == 0) p->type |= NEEDARGS; p->defn = null; return; } } if (!*defn) p->defn = null; else p->defn = xstrdup(defn); p->type = MACRTYPE; if (STREQ(name, defn)) p->type |= RECDEF; }
/* * dopushdef - install a definition in the hash table * without removing a previous definition. Since * each new entry is entered in *front* of the * hash bucket, it hides a previous definition from * lookup. */ static void dopushdef(const char *name, const char *defn) { ndptr p; if (!*name) errx(1, "%s at line %lu: null definition", CURRENT_NAME, CURRENT_LINE); p = addent(name); if (!*defn) p->defn = null; else p->defn = xstrdup(defn); p->type = MACRTYPE; if (STREQ(name, defn)) p->type |= RECDEF; }
void listdiranalyse(t_ls *ls, t_arg *arg, struct dirent *ent) { struct stat filestat; t_ent *ment; char *lpath; char *lpath2; lpath = ft_strjoin("/", ent->d_name); lpath2 = ft_strjoin(arg->path, lpath); if (lstat(lpath2, &filestat) == 0) { ment = newent(ent->d_name, &filestat); arg->ent = addent(&(arg->ent), ment); if (!ft_strequ(ent->d_name, ".") && !ft_strequ(ent->d_name, "..")) { if ((ent->d_type == 4 || ent->d_type == 0) && ls->opts['R']) { arg->sub = addarg(&arg->sub, newarg(lpath2)); } } } ft_strdel(&lpath2); ft_strdel(&lpath); }