From 3ab8361d696559cd20495b4af1186a679f1460f2 Mon Sep 17 00:00:00 2001 From: yosyo Date: Sun, 19 May 2024 05:49:22 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=8F=97=EF=B8=8F=E3=80=8D=20wip(e?= =?UTF-8?q?xec/get=5Fpath):=20can=20get=20all=20files=20in=20path,=20only?= =?UTF-8?q?=20printing=20for=20now.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/execution.h | 4 ++- include/minishell.h | 4 +++ src/env/env_cmd.c | 2 -- src/exec/get_path.c | 66 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 src/exec/get_path.c diff --git a/include/execution.h b/include/execution.h index 77fef6b..be6273e 100644 --- a/include/execution.h +++ b/include/execution.h @@ -6,13 +6,15 @@ /* By: mmoussou # include # include +# include +# include +# include +# include # include "libft.h" # include "parsing.h" diff --git a/src/env/env_cmd.c b/src/env/env_cmd.c index 04a5666..1620181 100644 --- a/src/env/env_cmd.c +++ b/src/env/env_cmd.c @@ -44,7 +44,6 @@ char **env_get(t_env *env) int env_create_first_el(char *env_line, t_env *env) { -// t_env *new; char *name; char *content; @@ -139,7 +138,6 @@ int env_edit(char *name, char *content, t_env *env) int env_delete(char *name, t_env *env) { -// char *new_content; t_env *tmp; while (env && env->next && ft_strcmp(env->next->name, name)) diff --git a/src/exec/get_path.c b/src/exec/get_path.c new file mode 100644 index 0000000..ea4ed13 --- /dev/null +++ b/src/exec/get_path.c @@ -0,0 +1,66 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_path.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmoussou d_name, ".", ft_strlen(dir_entry->d_name)) + || !ft_strncmp(dir_entry->d_name, "..", ft_strlen(dir_entry->d_name))) + { + dir_entry = readdir(path_dir); + continue ; + } + abs_path = ft_calloc(sizeof(char), strlen(path) + strlen(dir_entry->d_name) + 1); + if (!abs_path) + return (-1); + strcat(abs_path, path); + strcat(abs_path, dir_entry->d_name); + stat(abs_path, &entry); + if (S_ISREG(entry.st_mode) + && (entry.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) + printf("%s\n", dir_entry->d_name); + free(abs_path); + dir_entry = readdir(path_dir); + } + closedir(path_dir); + return (0); +} + +int get_path(char *path) +{ + char **path_dir; + int i; + + path_dir = ft_split(path, ':'); + if (!path_dir) + return (-1); + i = 0; + while (path_dir[i]) + { + get_path_list(path_dir[i]); + i++; + } + ft_free("a", &path_dir); + return (0); +}