fin mise a la norme exec (reste un fichier mais il faut que vous y regardiez)

This commit is contained in:
gwojda 2017-03-20 17:08:39 +01:00
parent b1eaa947a6
commit 03edcfc777
2 changed files with 22 additions and 18 deletions

View file

@ -1,22 +1,33 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* lib_path.c :+: :+: :+: */ /* ft_findexec.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 13:37:49 by jhalford #+# #+# */ /* Created: 2016/12/03 13:37:49 by jhalford #+# #+# */
/* Updated: 2017/01/10 13:18:56 by jhalford ### ########.fr */ /* Updated: 2017/03/20 16:52:10 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
char *ft_findexec(char *path, char *file) static char *create_path(char *path, char *name, char **spath)
{
char *execpath;
if (path[ft_strlen(path)] != '/')
execpath = ft_str3join(path, "/", name);
else
execpath = ft_strjoin(path, name);
ft_sstrfree(spath);
return (execpath);
}
char *ft_findexec(char *path, char *file)
{ {
int i; int i;
DIR *dir; DIR *dir;
char *execpath;
char **spath; char **spath;
struct dirent *dirent; struct dirent *dirent;
@ -30,13 +41,8 @@ char *ft_findexec(char *path, char *file)
{ {
if (ft_strcmp(dirent->d_name, file)) if (ft_strcmp(dirent->d_name, file))
continue ; continue ;
if (spath[i][ft_strlen(spath[i])] != '/')
execpath = ft_str3join(spath[i], "/", dirent->d_name);
else
execpath = ft_strjoin(spath[i], dirent->d_name);
ft_sstrfree(spath);
closedir(dir); closedir(dir);
return (execpath); return (create_path(spath[i], dirent->d_name, spath));
} }
closedir(dir); closedir(dir);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
/* Updated: 2017/03/20 16:02:08 by gwojda ### ########.fr */ /* Updated: 2017/03/20 17:07:01 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -53,16 +53,14 @@ int process_set(t_process *p, t_btree *ast)
exec = &data_singleton()->exec; exec = &data_singleton()->exec;
op = pop(&exec->op_stack); op = pop(&exec->op_stack);
if ((EXEC_IS_AND_IF(exec->attrs) if ((EXEC_IS_AND_IF(exec->attrs)
&& ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") != 0) && ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") != 0)
|| (EXEC_IS_OR_IF(exec->attrs) || (EXEC_IS_OR_IF(exec->attrs)
&& ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)) && ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0))
return (1); return (1);
fds[PIPE_WRITE] = STDOUT; fds[PIPE_WRITE] = STDOUT;
fds[PIPE_READ] = STDIN; fds[PIPE_READ] = STDIN;
if (op == TK_PIPE) (op == TK_PIPE) ? pipe(fds) : (0);
pipe(fds); exec->job.attrs |= (op == TK_AMP ? JOB_BG : 0);
else if (op == TK_AMP)
exec->job.attrs |= JOB_BG;
p->fdin = exec->fdin; p->fdin = exec->fdin;
p->to_close = fds[PIPE_READ]; p->to_close = fds[PIPE_READ];
p->fdout = fds[PIPE_WRITE]; p->fdout = fds[PIPE_WRITE];