예제 #1
0
파일: list.c 프로젝트: Denis2222/ft_ls
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);
    }
}
예제 #2
0
파일: eval.c 프로젝트: edgar-pek/PerspicuOS
/*
 * 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;
}
예제 #3
0
파일: eval.c 프로젝트: edgar-pek/PerspicuOS
/*
 * 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;
}
예제 #4
0
파일: list.c 프로젝트: Denis2222/ft_ls
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);
}