fix: filename expansion *

- If a program name has '/' in it, use the string as the program path.
- Else, search it in $PATH.
This commit is contained in:
mcolonna 2024-06-25 14:28:14 +02:00
parent f3a8866c56
commit e144a5aa65
2 changed files with 11 additions and 6 deletions

View file

@ -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:

View file

@ -6,7 +6,7 @@
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);