diff --git a/src/ft_errno.h b/src/ft_errno.h index f17cbaa..1c89f38 100644 --- a/src/ft_errno.h +++ b/src/ft_errno.h @@ -18,6 +18,7 @@ typedef enum e_errno FT_EERRNO = -2, FT_EGET = -1, FT_ESUCCESS = 0, + FT_ENOMEM, FT_EINVAL, FT_EBADID, FT_EUNEXPECTED_PIPE, diff --git a/src/subst/replace_substr.c b/src/subst/replace_substr.c index f2716f0..5353dff 100644 --- a/src/subst/replace_substr.c +++ b/src/subst/replace_substr.c @@ -6,7 +6,7 @@ /* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/25 13:02:59 by jguelen #+# #+# */ -/* Updated: 2025/03/08 14:52:42 by jguelen ### ########.fr */ +/* Updated: 2025/03/10 18:30:20 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/subst/simple_filename_exp.c b/src/subst/simple_filename_exp.c index 0af7b7e..25a0914 100644 --- a/src/subst/simple_filename_exp.c +++ b/src/subst/simple_filename_exp.c @@ -3,17 +3,22 @@ /* ::: :::::::: */ /* simple_filename_exp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/02 13:40:10 by jguelen #+# #+# */ -/* Updated: 2025/03/07 17:25:18 by jguelen ### ########.fr */ +/* Updated: 2025/03/11 14:46:17 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" #include "libft.h" -#include "ft_errno.h" +#include "../ft_errno.h" +#include +/* +** Returns a malloc-allocated string corresponding to +** "path_dir/name" +*/ char *alloc_path(char *path_dir, char *name) { char *path; @@ -44,10 +49,15 @@ static char **get_paths_array(t_env *env) return (path_array); } +/* +** TODO Check if filename refers to an actual file or a directory and what to +** do about that case. +*/ char *filepath_from_env(char *filename, t_minishell *app) { char *filepath; char **path; + size_t i; path = get_paths_array(app->env); if (path == NULL) @@ -63,3 +73,24 @@ char *filepath_from_env(char *filename, t_minishell *app) destroy_split_array(path); return (NULL); } + +/* +** Returns a malloc-allocated string representing the full path to +** the command or executable corresponding to name or NULL in case of +** failure or . +** NOTE: if name contains a '/' character then name is considered to +** be an absolute path. +*/ +char *get_filepath(const char *name, t_minishell *app) +{ + char *cmd_path; + + if (ft_strchr(name, '/')) + { + cmd_path = ft_strdup(name); + if (!cmd_path) + return (ft_errno(FT_ENOMEM), NULL); + return (cmd_path); + } + return (filepath_from_env(name, app)); +}