mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-05 23:18:08 +01:00
fix: get_cmdpath returns NULL if executable is absent in first directory searched
This commit is contained in:
parent
a5a93be3d0
commit
bd01c79838
1 changed files with 7 additions and 6 deletions
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* simple_filename_exp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/02 13:40:10 by jguelen #+# #+# */
|
||||
/* Updated: 2025/03/21 17:33:50 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/03/27 18:39:23 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -55,16 +55,18 @@ static char **get_paths_array(t_env *env)
|
|||
** is the value stored in oldpath that will be used resulting in a Permission
|
||||
** denied error. oldpath is to store the first occurrence of a regular file
|
||||
** corresponding to the filepath but not executable.
|
||||
**
|
||||
** We disregard all stat(2) failures, since bash does the same and treats them
|
||||
** all to mean that the file does not exist.
|
||||
*/
|
||||
static char *select_path(char *filepath, char **oldpath, char **path,
|
||||
struct stat *fstat)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ft_errno(FT_ESUCCESS);
|
||||
ret = stat(filepath, fstat);
|
||||
if (ret == -1)
|
||||
return (path_split_destroy(path), ft_errno(FT_STATFAIL), NULL);
|
||||
return (NULL);
|
||||
if (access(filepath, F_OK) == 0 && ret == 0 && S_ISREG(fstat->st_mode))
|
||||
{
|
||||
if (access(filepath, X_OK) != 0)
|
||||
|
|
@ -114,8 +116,7 @@ static char *deal_with_filled_path(char *filename, char **path,
|
|||
tmp = select_path(filepath, &oldpath, path, fstat);
|
||||
if (tmp)
|
||||
return (filepath);
|
||||
else if (!tmp && ft_errno_get() == FT_STATFAIL)
|
||||
return (free(filepath), NULL);
|
||||
free(filepath);
|
||||
i++;
|
||||
}
|
||||
path_split_destroy(path);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue