Example #1
0
int send_file(struct asfd *asfd, FF_PKT *ff, bool top_level, struct conf *conf)
{
	static struct sbuf *sb=NULL;

	if(!sb && !(sb=sbuf_alloc(conf))) return -1;

	if(!file_is_included(conf, ff->fname, top_level)) return 0;

#ifdef HAVE_WIN32
	if(ff->winattr & FILE_ATTRIBUTE_ENCRYPTED)
	{
		if(ff->type==FT_REG
		  || ff->type==FT_DIR)
			return to_server(asfd, conf, ff, sb, CMD_EFS_FILE);
		return logw(asfd, conf, "EFS type %d not yet supported: %s",
			ff->type, ff->fname);
	}
#endif

	switch(ff->type)
	{
		case FT_REG:
		case FT_RAW:
		case FT_FIFO:
			return do_to_server(asfd, conf, ff, sb, filesymbol,
				in_exclude_comp(conf->excom,
					ff->fname, conf->compression));
		case FT_DIR:
		case FT_REPARSE:
		case FT_JUNCTION:
			return to_server(asfd, conf, ff, sb, dirsymbol);
		case FT_LNK_S:
			return to_server(asfd, conf, ff, sb, CMD_SOFT_LINK);
		case FT_LNK_H:
			return to_server(asfd, conf, ff, sb, CMD_HARD_LINK);
		case FT_SPEC:
			return to_server(asfd, conf, ff, sb, CMD_SPECIAL);
		case FT_NOFSCHG:
			return logw(asfd, conf, "Dir: %s [will not descend: "
				"file system change not allowed]\n", ff->fname);
		case FT_NOFOLLOW:
			return ft_err(asfd, conf, ff, "Could not follow link");
		case FT_NOSTAT:
			return ft_err(asfd, conf, ff, "Could not stat");
		case FT_NOOPEN:
			return ft_err(asfd, conf, ff, "Could not open directory");
		default:
			return logw(asfd, conf,
				_("Err: Unknown file type %d: %s"),
				ff->type, ff->fname);
	}
}
Example #2
0
static int my_send_file(struct asfd *asfd, struct FF_PKT *ff, struct conf **confs)
{
	static struct sbuf *sb=NULL;
	struct cntr *cntr=get_cntr(confs);

	if(!sb && !(sb=sbuf_alloc(get_protocol(confs)))) return -1;

#ifdef HAVE_WIN32
	if(ff->winattr & FILE_ATTRIBUTE_ENCRYPTED)
	{
		if(ff->type==FT_REG
		  || ff->type==FT_DIR)
			return to_server(asfd, confs, ff, sb, CMD_EFS_FILE);
		return logw(asfd, cntr,
			"EFS type %d not yet supported: %s\n",
			ff->type, ff->fname);
	}
#endif

	switch(ff->type)
	{
		case FT_REG:
		case FT_RAW:
		case FT_FIFO:
			return do_to_server(asfd, confs, ff, sb, filesymbol,
				in_exclude_comp(get_strlist(confs[OPT_EXCOM]),
				  ff->fname, get_int(confs[OPT_COMPRESSION])));
		case FT_DIR:
		case FT_REPARSE:
		case FT_JUNCTION:
			return to_server(asfd, confs, ff, sb, dirsymbol);
		case FT_LNK_S:
			return to_server(asfd, confs, ff, sb, CMD_SOFT_LINK);
		case FT_LNK_H:
			return to_server(asfd, confs, ff, sb, CMD_HARD_LINK);
		case FT_SPEC:
			return to_server(asfd, confs, ff, sb, CMD_SPECIAL);
		case FT_NOFSCHG:
			return ft_err(asfd, confs, ff, "Will not descend: "
				"file system change not allowed");
		case FT_NOFOLLOW:
			return ft_err(asfd, confs, ff, "Could not follow link");
		case FT_NOSTAT:
			return ft_err(asfd, confs, ff, "Could not stat");
		case FT_NOOPEN:
			return ft_err(asfd, confs, ff, "Could not open directory");
		default:
			return logw(asfd, cntr,
				"Err: Unknown file type %d: %s\n",
				ff->type, ff->fname);
	}
}
Example #3
0
File: dir.c Project: sbenning42/42
void				ls_dir(void *p, size_t size)
{
    t_ls_entry		*e;
    t_node			*root;
    DIR				*dir;

    e = (t_ls_entry *)p;
    if (e->type != T_DIR || !e->handle || \
            (e->stat.st_mode & S_IFSOCK) == S_IFSOCK || \
            (e->stat.st_mode & S_IFLNK) == S_IFLNK)
        return ;
    handle_path(e->name);
    dir = opendir(env()->path);
    ft_err(env()->av, ft_name(env()->path));
    if (!dir)
        handle_path(NULL);
    else if (!(root = dir_tree(dir)))
        handle_path(NULL);
    else
    {
        tree_doinf(root, g_ls_select_print(env()->o));
        if ((env()->o & O_RECU) == O_RECU)
            tree_doinf(root, ls_dir);
        handle_path(NULL);
        tree_del(&root, NULL);
    }
    (void)size;
}
Example #4
0
int				fdf_map_attr(t_env *e, t_list *lst)
{
	t_lex_tk	*t;
	int			x;
	int			max;

	if (!lst)
		return (ft_verbose(e->av, e->id, "File seems to be empty..."));
	x = 0;
	while (lst)
	{
		t = (t_lex_tk *)lst->content;
		if (t->type == Unknow)
			return (fdf_synerror(e, t, e->map->y + 1));
		else if (t->type == Eol)
			fdf_maj_xy(e->map, &x);
		lst = lst->next;
		x++;
	}
	max = (e->map->x > e->map->y ? e->map->x : e->map->y);
	e->map->gap = (FDF_SCREEN / 3.0) / max;
	if (!(e->map->m = fdf_newpxmat(e->map->x * e->map->y)))
		return (ft_err(e->av, e->id, "Memory allocation failed"));
	return (1);
}
Example #5
0
File: dir.c Project: sbenning42/42
t_node				*dir_tree(DIR *dir)
{
    t_node			*root;
    struct dirent	*entry;
    long long int	block;
    int				i;

    env()->nlinkpad = 0;
    env()->sizepad = 0;
    env()->ownerlen = 0;
    env()->grplen = 0;
    block = 0;
    i = 0;
    root = NULL;
    while ((entry = readdir(dir)))
    {
        if (!entry_tree(&root, entry, &block, &i))
        {
            tree_del(&root, NULL);
            return (NULL);
        }
    }
    ft_err(env()->av, env()->path);
    closedir(dir);
    if (((env()->o & O_LONG) == O_LONG) && (i > 0))
        ft_printf("total %lld\n", block);
    return (root);
}
Example #6
0
int				cmd_cd(char **tab)
{
	int		size;
	char	*pwd;

	pwd = ft_strnew(200);
	if ((size = ft_size_tab(tab)) > 3)
		return (ft_err(ERCDMULT, tab[1]));
	else if (size == 2)
		pwd = ft_strcpy(pwd, ft_getenv("HOME", g_env));
	else
	{
		if (tab[1][0] == '~')
			pwd = ft_strcpy(pwd, ft_getenv("HOME", g_env));
		else if (tab[1][0] == '-')
			pwd = ft_strcpy(pwd, ft_getenv("OLDPWD", g_env));
		else if (tab[1][0] != '/')
			pwd = ft_strcpy(pwd, ft_getenv("PWD", g_env));
		if (!ft_strlen((pwd = build_pwd(tab[1], pwd))))
			pwd[0] = '/';
	}
	if (check_cd(pwd) == 0)
		return (1);
	if (chdir(pwd) != -1)
		refresh_pwd(pwd);
	free(pwd);
	return (1);
}
Example #7
0
static int		check_cd(char *pwd)
{
	struct stat	buf;
	char		*tmp;
	int			err;

	err = 0;
	if (ft_strchr((pwd + 1), '/'))
	{
		tmp = ft_strdup(pwd);
		tmp = ft_path_back(tmp, '/');
		if (check_cd(tmp) == 0)
		{
			free(tmp);
			return (0);
		}
		free(tmp);
	}
	lstat(pwd, &buf);
	if (access(pwd, F_OK) == -1)
		err = ERCDNOTFOUND;
	else if (!(buf.st_mode & S_IFDIR))
		err = ERCDNOTDIR;
	else if (access(pwd, R_OK) == -1)
		err = ERCDACCESS;
	return ((!err) ? 1 : ft_err(err, pwd));
}
Example #8
0
File: argv.c Project: sbenning42/42
static t_node		*argv_wa_tree(int ac, int i, char **av)
{
	int				(*s)(void *, void *);
	t_node			*root;
	t_node			*no;
	t_ls_entry		e;

	root = NULL;
	s = g_ls_select_argvsort(env()->o);
	while (i < ac)
	{
		e = ls_newentry(av[i], av[i]);
		errno = 0;
		if (!(no = tree_newnode((void *)&e, sizeof(t_ls_entry))))
		{
			ft_err(env()->av, av[i]);
			errno = 0;
			tree_del(&root, NULL);
			return (NULL);
		}
		maj_env(e);
		tree_add(&root, no, s);
		i++;
	}
	return (root);
}
Example #9
0
File: dir.c Project: sbenning42/42
int					entry_tree(t_node **ar, struct dirent *entry, \
                               quad_t *blocks, int *i)
{
    char			absname[PATHSIZE_LS];
    t_ls_entry		e;
    t_node			*no;

    ft_strcpy(absname, env()->path);
    ft_strcat(absname, "/");
    ft_strcat(absname, entry->d_name);
    e = ls_newentry(entry->d_name, absname);
    if (entry->d_name[0] == '.' && !((env()->o & O_HIDE) == O_HIDE))
        e.handle = 0;
    if (e.handle)
    {
        *i += 1;
        *blocks += e.stat.st_blocks;
    }
    if (!ft_strcmp(entry->d_name, ".") || !ft_strcmp(entry->d_name, ".."))
        e.handle = 0;
    if (!(no = tree_newnode((void *)&e, sizeof(t_ls_entry))))
        return (ft_err(env()->av, absname));
    tree_add(ar, no, g_ls_select_sort(env()->o));
    maj_env(e);
    return (1);
}
Example #10
0
int					get_next_line(int fd, char **line)
{
	static char		*save = NULL;
	char			buff[BUFF_SIZE + 1];
	char			*tmp;
	int				ret;

	ret = 0;
	if (fd == -1 || BUFF_SIZE <= 0)
		return (ft_err(&save));
	if (save == NULL)
		save = ft_strnew(BUFF_SIZE + 1);
	while (save != NULL
			&& ft_strchr(save, '\n') == NULL
			&& ((ret = read(fd, buff, BUFF_SIZE)) > 0))
	{
		buff[ret] = '\0';
		tmp = save;
		save = ft_strjoin(tmp, buff);
		free(tmp);
	}
	if (ret == -1)
		return (-1);
	if (ret == 0 && ft_strchr(save, '\n') == NULL)
		return ((ft_end(line, &save)));
	ft_ret(line, &(save));
	return (1);
}
Example #11
0
int			main(int argc, char **argv)
{
	int		fd;
	t_mlx	*mlx;

	if (argc != 2)
		return (ft_err(001, NULL));
	fd = 0;
	mlx = NULL;
	fd = open(argv[1], O_RDONLY);
	if (fd < 0)
		return (ft_err(002, argv[1]));
	mlx = ft_init(mlx, fd);
	mlx = ft_loop(mlx);
	close(fd);
	ft_free_bundle(mlx);
	return (0);
}
Example #12
0
File: ex4.c Project: magouin/lem_in
void	check(t_salle *sl)
{
	t_salle	*p;
	int		start;
	int		end;

	start = 0;
	end = 0;
	while (sl->prev)
		sl = sl->prev;
	while (sl)
	{
		p = sl->next;
		while (p)
			(p->name == sl->name) ? ft_err(NULL, NULL, 5) : (p = p->next);
		sl->start ? start++ : 0;
		sl->end ? end++ : 0;
		sl = sl->next;
	}
	start != 1 || end != 1 ? ft_err(NULL, NULL, 6) : 0;
}
Example #13
0
char		*fmt_link(t_ls_entry *e, char *buf)
{
	char	absname[PATHSIZE_LS + 1];

	ft_bzero((void *)buf, LINKSIZE_LS + 1);
	ft_bzero((void *)absname, PATHSIZE_LS + 1);
	ft_strcpy(absname, env()->path);
	ft_strcat(absname, "/");
	ft_strcat(absname, e->name);
	if (readlink(absname, buf, (size_t)LINKSIZE_LS) > 0)
		ft_err(env()->av, e->name);
	return (buf);
}
Example #14
0
File: ex4.c Project: magouin/lem_in
void	tubes2(t_env *e, char **split, int *dim)
{
	while ((e->salle)->prev != NULL)
		e->salle = (e->salle)->prev;
	while (e->salle != NULL && ft_strcmp((e->salle)->name, split[1]))
		e->salle = (e->salle)->next;
	e->salle != NULL ? (e->tube)->s2 = e->salle : ft_err(NULL, NULL, 7);
	(e->tube)->x = dim[0] - (e->salle)->x;
	(e->tube)->y = dim[1] - (e->salle)->y;
	free(split[0]);
	free(split[1]);
	free(split);
}
Example #15
0
File: ex4.c Project: magouin/lem_in
void	comment2(char **split, t_env *e)
{
	split[0][0] == 'L' || !((e->salle)->name =
	(char*)malloc(sizeof(char) * (ft_strlen(split[0]) + 1)))
		? ft_err(NULL, NULL, 3) : 0;
	ft_strcpy((e->salle)->name, split[0]);
	integer(split[1]);
	integer(split[2]);
	(e->salle)->x = ft_atoi(split[1]);
	(e->salle)->y = ft_atoi(split[2]);
	free(split[0]);
	free(split[1]);
	free(split[2]);
	free(split);
}
Example #16
0
int			ft_parser_print_err(char c)
{
	char	*tmp;
	char	*tmp2;
	char	ch[2];

	ch[0] = c;
	ch[1] = '\0';
	tmp = ft_strjoin("Parse error near '", ch);
	tmp2 = ft_strjoin(tmp, "'");
	ft_memdel((void **)&tmp);
	ft_err(tmp2);
	ft_memdel((void **)&tmp2);
	return (ERR);
}
Example #17
0
File: ex4.c Project: magouin/lem_in
int		comment(t_env *e, char **line)
{
	char		**split;

	get_next_line(0, line);
	e->salle = edit_sl(e->salle);
	while ((*line)[0] == '#')
	{
		!(ft_strcmp(*line, "##start")) ? (e->salle)->start = 1 : 0;
		!(ft_strcmp(*line, "##end")) ? (e->salle)->end = 1 : 0;
		get_next_line(0, line);
	}
	split = ft_strsplit(*line, ' ');
	split[0] == NULL ? ft_err(NULL, NULL, 4) : 0;
	if (split[1] == NULL || split[2] == NULL || split[3] != NULL)
	{
		free(split[0]);
		free(split);
		return (0);
	}
	comment2(split, e);
	return (1);
}
Example #18
0
File: error.c Project: Apercu/42sh
void		ft_error(char *msg)
{
	ft_err(msg);
	ft_exit(1);
}