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:
parent
f3a8866c56
commit
e144a5aa65
2 changed files with 11 additions and 6 deletions
1
dev/TODO
1
dev/TODO
|
@ -1,6 +1,5 @@
|
||||||
- finding commands
|
- finding commands
|
||||||
- built-in commands
|
- built-in commands
|
||||||
- find with given path only if there is a '/'
|
|
||||||
- variables
|
- variables
|
||||||
- uses $PATH in env.variables instead of envp
|
- uses $PATH in env.variables instead of envp
|
||||||
- builtins:
|
- builtins:
|
||||||
|
|
16
src/path.c
16
src/path.c
|
@ -6,7 +6,7 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/11/16 12:07:26 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);
|
return (re);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool is_path(const char *str)
|
||||||
|
{
|
||||||
|
return (char_isin('/', str));
|
||||||
|
}
|
||||||
|
|
||||||
const char *search_path(
|
const char *search_path(
|
||||||
const t_memclass mc, t_list *variables, const char *prog)
|
const t_memclass mc, t_list *variables, const char *prog)
|
||||||
{
|
{
|
||||||
|
@ -30,12 +35,13 @@ const char *search_path(
|
||||||
int i;
|
int i;
|
||||||
const char *r;
|
const char *r;
|
||||||
|
|
||||||
i = 0;
|
if (is_path(prog))
|
||||||
if (access(prog, X_OK) >= 0)
|
|
||||||
{
|
{
|
||||||
mem_free((void *)prog2);
|
if (access(prog, X_OK) >= 0)
|
||||||
return (ft_strdup(prog));
|
return (ft_strdup(prog));
|
||||||
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
i = 0;
|
||||||
while (path[i] != NULL)
|
while (path[i] != NULL)
|
||||||
{
|
{
|
||||||
r = str_join(fatal_error, mc, path[i], prog2);
|
r = str_join(fatal_error, mc, path[i], prog2);
|
||||||
|
|
Loading…
Add table
Reference in a new issue