Exemplo n.º 1
0
Arquivo: main.c Projeto: hikkary/ft_ls
int srm(s_dir *d, s_arg *a, char **argv)
{
	int c;
	while((d->rd = readdir(d->open)) != NULL)
	{
			if(d->rd->d_name[0] != '.')
			{
				stat(d->rd->d_name, d->info);
				ft_putstr(d->rd->d_name);
				ft_putchar('\n');
			}
	}
	closedir(d->open);	
//	d->open = opendir(argv[a->arc]);
	while((d->rd = readdir(d->open)) != NULL)
	{
			if(d->rd->d_name[0] != '.')
			{
				if(ft_is_dir(d->rd->d_name))
				{
					d->open = opendir(d->rd->d_name);
					srm(d, a, argv);
				}
			}
	}


	return (0);	
}
Exemplo n.º 2
0
int ft_dircheck(char *argv, int j, t_args *args)
{


	if (ft_is_dir(argv) == 0)
	{
		args->elem[j] = ft_strdup(argv);
		return (1);
	}
	return (0);
}
Exemplo n.º 3
0
void		ft_get(t_info *i)
{
	char			*path;
	struct stat		s;
	char			buff[513];
	int				fd;
	int				count;

	if (!i->argv[1])
		return ;
	if (i->argv[1] && i->argv[1][0] != '/')
		path = ft_trunc("%s/%s", i->pwd, i->argv[1]);
	else
		path = ft_strdup(i->argv[1]);
	if (ft_is_dir(path))
	{
		free(path);
		ft_putendl_fd("ERROR: can't get directory\4", i->sock);
		return ;
	}
	if ((fd = open(path, O_RDONLY)) == -1)
	{
		free(path);
		ft_putendl_fd("ERROR: no such file or permission denied\4", i->sock);
		return ;
	}
	free(path);
	ft_bzero(buff, 512);
	send(i->sock, "ERROR: NULL\n", 12, 0);
	fstat(fd, &s);
	count = 0;
	if (s.st_blocks <= 0)
	{
		close(fd);
		return ;
	}
	path = ft_trunc("SIZE: %d", s.st_blocks * 512);
	ft_putendl_fd(path, i->sock);
	ft_putendl_fd(path, 1);
	free(path);
	while (count < s.st_blocks)
	{
		read(fd, buff, 512);
		send(i->sock, buff, 512, 0);
		ft_bzero(buff, 512);
		count++;
	}
	close(fd);
}
Exemplo n.º 4
0
static void		norme_big_r_1(DIR **d, char *path, char *options, char ***tmp)
{
	struct dirent	*drnt;
	char			*tmp_suffix;

	while ((drnt = readdir(*d)) != NULL)
	{
		tmp_suffix = create_str_suffix(path, drnt->d_name);
		if (ft_is_dir(tmp_suffix) == 1 && ft_strcmp(drnt->d_name, ".")
			&& ft_strcmp(drnt->d_name, ".."))
		{
			if ((!ft_strchr(options, 'a') && (drnt->d_name)[0] != '.')
				|| ft_strchr(options, 'a'))
				*tmp = extend_tab_str(*tmp, tmp_suffix);
		}
	}
	return ;
}
Exemplo n.º 5
0
t_list			*ft_del_files(t_core *core)
{
	t_list		*cursor;
	t_list		*tmp;

	cursor = OUTPUT;
	while (cursor)
	{
		tmp = cursor->next;
		if (!(ft_strchr(OPT, 'R'))
			|| !(ft_strcmp(ft_strrchr(cursor->content, '/'), "/."))
			|| !(ft_strcmp(ft_strrchr(cursor->content, '/'), "/.."))
			|| (ft_is_file_foo(cursor->content, "link"))
			|| (ft_is_dir(cursor->content)) != 1)
			ft_lstfreeone(&OUTPUT, &cursor);
		cursor = tmp;
	}
	return (OUTPUT);
}
Exemplo n.º 6
0
t_options		*ft_parse(t_options *opt, int i, char **argv)
{
	int				j;
	struct stat		bufstat;

	j = 0;
	if (argv[i][0] == '-' && opt->nbfile == 0 && !ft_is_dir(argv[i]))
	{
		(!argv[i][1]) ? ft_error(argv[i], 2) : 0;
		while (argv[i][++j])
			opt = ft_add_option(argv[i][j], opt);
	}
	else
	{
		if (lstat(argv[i], &bufstat) != -1)
			opt->files[opt->nbfile++] = ft_strdup(argv[i]);
		else
			ft_error_noend(argv[i], errno);
		opt->errors++;
	}
	return (opt);
}