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 #+# #+# */
/* Updated: 2017/01/10 13:18:56 by jhalford ### ########.fr */
/* Updated: 2017/03/20 16:52:10 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
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;
DIR *dir;
char *execpath;
char **spath;
struct dirent *dirent;
@ -30,13 +41,8 @@ char *ft_findexec(char *path, char *file)
{
if (ft_strcmp(dirent->d_name, file))
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);
return (execpath);
return (create_path(spath[i], dirent->d_name, spath));
}
closedir(dir);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */
@ -59,10 +59,8 @@ int process_set(t_process *p, t_btree *ast)
return (1);
fds[PIPE_WRITE] = STDOUT;
fds[PIPE_READ] = STDIN;
if (op == TK_PIPE)
pipe(fds);
else if (op == TK_AMP)
exec->job.attrs |= JOB_BG;
(op == TK_PIPE) ? pipe(fds) : (0);
exec->job.attrs |= (op == TK_AMP ? JOB_BG : 0);
p->fdin = exec->fdin;
p->to_close = fds[PIPE_READ];
p->fdout = fds[PIPE_WRITE];