aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDominik Kaiser2025-01-15 16:34:01 +0100
committerDominik Kaiser2025-01-15 16:34:01 +0100
commit48912782078b2b3f59413db2539bf6fa6e56b2f8 (patch)
tree836d10752c0a9a2914a2ea174dce4e00401bb658 /src
parent6f3d737e20b95573497c29271d2f947e39685de2 (diff)
downloadminishell-48912782078b2b3f59413db2539bf6fa6e56b2f8.tar.gz
minishell-48912782078b2b3f59413db2539bf6fa6e56b2f8.zip
Fix some errors
Diffstat (limited to 'src')
-rw-r--r--src/get_cmd_path.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/get_cmd_path.c b/src/get_cmd_path.c
index 605adf6..fb45730 100644
--- a/src/get_cmd_path.c
+++ b/src/get_cmd_path.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/17 19:19:59 by chuhlig #+# #+# */
-/* Updated: 2025/01/15 16:15:32 by dkaiser ### ########.fr */
+/* Updated: 2025/01/15 16:32:30 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,12 +16,14 @@
#include <sys/errno.h>
#include <sys/unistd.h>
#include <unistd.h>
+#include <sys/stat.h>
static char *get_simple_cmd_path(char *cmd, int *return_code);
static char *get_absolute_cmd_path(char *cmd, t_env *env, int *return_code);
static char *find_in_path(char *cmd, t_env *env, int *return_code);
static char *error(int err_code, char *err_text, int exit_code, int *ret_code);
char **get_split_path(t_env *env);
+static int is_directory(char *path);
char *get_cmd_path(char *cmd, t_env *env, int *return_code)
{
@@ -55,6 +57,8 @@ static char *get_absolute_cmd_path(char *cmd, t_env *env, int *return_code)
free(result);
return (error(EACCES, cmd, 126, return_code));
}
+ if (is_directory(cmd))
+ return (error(EISDIR, cmd, 126, return_code));
return (result);
}
@@ -102,6 +106,8 @@ static char *get_simple_cmd_path(char *cmd, int *return_code)
free(result);
return (error(EACCES, cmd, 126, return_code));
}
+ if (is_directory(cmd))
+ return (error(EISDIR, cmd, 126, return_code));
return (result);
}
@@ -113,3 +119,14 @@ static char *error(int err_code, char *err_text, int exit_code, int *ret_code)
*ret_code = exit_code;
return (NULL);
}
+
+static int is_directory(char *path)
+{
+ struct stat path_stat;
+
+ stat(path, &path_stat);
+ if ((path_stat.st_mode & S_IFMT) == S_IFDIR)
+ return (1);
+ else
+ return (0);
+}