diff --git a/dev/TODO b/dev/TODO index add83c7..d5619bb 100644 --- a/dev/TODO +++ b/dev/TODO @@ -1,6 +1,5 @@ - finding commands - built-in commands - - find with given path only if there is a '/' - variables - uses $PATH in env.variables instead of envp - builtins: diff --git a/src/path.c b/src/path.c index f1f41f4..a2922b8 100644 --- a/src/path.c +++ b/src/path.c @@ -6,7 +6,7 @@ /* By: jschaft +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/16 12:07:26 by jschaft #+# #+# */ -/* Updated: 2024/06/21 16:23:54 by mcolonna ### ########.fr */ +/* Updated: 2024/06/25 14:27:31 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,11 @@ static const char **get_path(const t_memclass mc, t_list *variables) return (re); } +static bool is_path(const char *str) +{ + return (char_isin('/', str)); +} + const char *search_path( const t_memclass mc, t_list *variables, const char *prog) { @@ -30,12 +35,13 @@ const char *search_path( int i; const char *r; - i = 0; - if (access(prog, X_OK) >= 0) + if (is_path(prog)) { - mem_free((void *)prog2); - return (ft_strdup(prog)); + if (access(prog, X_OK) >= 0) + return (ft_strdup(prog)); + return (NULL); } + i = 0; while (path[i] != NULL) { r = str_join(fatal_error, mc, path[i], prog2);