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); } }
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); }
void newent(const char *cl, const char *sd) { newent(cl, sd, saved_pos); }