diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-07-20 18:29:03 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-07-20 18:29:03 +0200 |
| commit | e77b1667e23a05f2874f80f5e47e634c58180c37 (patch) | |
| tree | e76c06188cf2081f92c37621f619bbb624f761d6 | |
| parent | 52bb7cc0f234776cd19c7a608b06578150d4695a (diff) | |
| download | minishell-e77b1667e23a05f2874f80f5e47e634c58180c37.tar.gz minishell-e77b1667e23a05f2874f80f5e47e634c58180c37.tar.bz2 minishell-e77b1667e23a05f2874f80f5e47e634c58180c37.zip | |
Fixing glob by removing chdir, Changed cmd variables
| m--------- | libft | 0 | ||||
| -rw-r--r-- | split_token | 301 | ||||
| -rw-r--r-- | src/eval/cmd.c | 43 | ||||
| -rw-r--r-- | src/eval/utils_eval.c | 34 | ||||
| -rw-r--r-- | src/main.c | 6 | ||||
| -rw-r--r-- | src/ms_glob.c | 77 | ||||
| -rw-r--r-- | src/preprocess.c | 2 | ||||
| -rw-r--r-- | src/utils.c | 7 |
8 files changed, 99 insertions, 371 deletions
diff --git a/libft b/libft -Subproject 0fc1e473e3bae0e1df32228ff72b9ab654fd2ac +Subproject 450e36f8ddf974e503731288c8d8bb8c62e67e4 diff --git a/split_token b/split_token deleted file mode 100644 index 7aa5020..0000000 --- a/split_token +++ /dev/null @@ -1,301 +0,0 @@ -diff --git a/include/eval.h b/include/eval.h -index 88142cd..88b6578 100644 ---- a/include/eval.h -+++ b/include/eval.h -@@ -6,7 +6,7 @@ - /* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ - /* +#+#+#+#+#+ +#+ */ - /* Created: 2020/04/01 17:05:30 by charles #+# #+# */ --/* Updated: 2020/07/15 17:03:05 by charles ### ########.fr */ -+/* Updated: 2020/07/20 13:22:26 by nahaddac ### ########.fr */ - /* */ - /* ************************************************************************** */ - -@@ -58,6 +58,7 @@ int eval(int fds[2], t_env env, t_path path, t_ast *ast); - - int fork_wrap(int fds[2], void *passed, int (*wrapped)(void *param)); - int eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast); -+t_ftlst *split_token(t_ftlst **lst, enum e_token_tag); - - /* - ** redir.c -diff --git a/include/lexer.h b/include/lexer.h -index ab2a448..f40db56 100644 ---- a/include/lexer.h -+++ b/include/lexer.h -@@ -6,7 +6,7 @@ - /* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */ - /* +#+#+#+#+#+ +#+ */ - /* Created: 2020/06/19 10:51:26 by nahaddac #+# #+# */ --/* Updated: 2020/07/16 07:10:58 by nahaddac ### ########.fr */ -+/* Updated: 2020/07/20 11:07:13 by nahaddac ### ########.fr */ - /* */ - /* ************************************************************************** */ - -diff --git a/libft b/libft -index 450e36f..0fc1e47 160000 ---- a/libft -+++ b/libft -@@ -1 +1 @@ --Subproject commit 450e36f8ddf974e503731288c8d8bb8c62e67e47 -+Subproject commit 0fc1e473e3bae0e1df32228ff72b9ab654fd2ac3 -diff --git a/minishell_test b/minishell_test -index 520742c..a90b8ed 160000 ---- a/minishell_test -+++ b/minishell_test -@@ -1 +1 @@ --Subproject commit 520742c77fc3d52301c54b7d678948f9c7c69ac6 -+Subproject commit a90b8ed1561e1edd05e2689e566727acedf4ff68 -diff --git a/src/eval/cmd.c b/src/eval/cmd.c -index 87c9bbf..adb4d1c 100644 ---- a/src/eval/cmd.c -+++ b/src/eval/cmd.c -@@ -3,10 +3,10 @@ - /* ::: :::::::: */ - /* cmd.c :+: :+: :+: */ - /* +:+ +:+ +:+ */ --/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ -+/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ - /* +#+#+#+#+#+ +#+ */ - /* Created: 2020/06/14 10:41:31 by charles #+# #+# */ --/* Updated: 2020/07/19 19:00:54 by charles ### ########.fr */ -+/* Updated: 2020/07/20 14:17:32 by nahaddac ### ########.fr */ - /* */ - /* ************************************************************************** */ - -@@ -14,6 +14,7 @@ - - pid_t g_child_pid = -1; - int g_last_status_code = 0; -+void token_debug(void *v); - - /* - ** \brief Wrap a function in a fork -@@ -91,6 +92,8 @@ int eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast) - { - t_fork_param_cmd param; - char **argv; -+ char *id; -+ t_ftlst *tmp; - - if (!redir_extract(ast->redirs, env, fds)) - { -@@ -105,7 +108,14 @@ int eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast) - && ((t_token*)ast->cmd_argv->data)->tag & TAG_IS_STR - && utils_start_with_valid_identifier(((t_token*)ast->cmd_argv->data)->content)) - { -- if (env_export_full(param.env_local, ((t_token*)ast->cmd_argv->data)->content) == NULL) -+ id = ((t_token*)ast->cmd_argv->data)->content; -+ *ft_strchr(id, '=') = '\0'; -+ ((t_token*)ast->cmd_argv->data)->content = ft_strchr(id, '\0') + 1; -+ tmp = split_token(&ast->cmd_argv, TAG_STICK); -+ ft_lstiter(tmp, token_debug); -+ printf("%s\n", ((t_token *)ast->cmd_argv->data)->content); -+ -+ if (env_export(param.env_local,id, ((t_token*)ast->cmd_argv->data)->content) == NULL) - return (-1); - ft_lstpop_front(&ast->cmd_argv, (void (*)(void*))token_destroy); - } -diff --git a/src/main.c b/src/main.c -index 85df51f..e1b956a 100644 ---- a/src/main.c -+++ b/src/main.c -@@ -6,7 +6,7 @@ - /* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */ - /* +#+#+#+#+#+ +#+ */ - /* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */ --/* Updated: 2020/07/19 20:22:37 by charles ### ########.fr */ -+/* Updated: 2020/07/20 11:21:23 by nahaddac ### ########.fr */ - /* */ - /* ************************************************************************** */ - -@@ -32,10 +32,10 @@ void ast_print(int level, t_ast *ast); - ** pipeline - ** cmd variable preprocess - ** PATH with no permission, link and other file system fun stuff --** escape lexer -+** escape lexer ------- ok - ** escape split preprocessing (escaped spaces) - ** signal on whole line instead of single command --** parsing error -+** parsing error ------ ok - ** env local to current minishell process - ** BETTER ERROR HANDLING IS BECOMING URGENT (spagetti code everywhere) - */ -@@ -67,12 +67,12 @@ int main(int argc, char **argv, char **envp) - path = path_update(NULL, env_search(env, "PATH")); - - char *env_exec_path; -- if ((env_exec_path = ft_htget(path, "env")) == NULL) -- { -- errorf("env: command not found\n"); -- return (127); -- } -- env_export(env, "_", env_exec_path); -+ // if ((env_exec_path = ft_htget(path, "env")) == NULL) -+ // { -+ // errorf("env: command not found\n"); -+ // return (127); -+ // } -+ // env_export(env, "_", env_exec_path); - - g_last_status_code = 0; - signal(SIGINT, signal_sigint); -@@ -104,7 +104,7 @@ int main(int argc, char **argv, char **envp) - if (parser_out == NULL || parser_out->syntax_error) - return (1); - -- //ast_print(0, parser_out->ast); -+ ast_print(0, parser_out->ast); - - /* printf("===cmd_argv===\n"); */ - /* ft_lstiter(parser_out->ast->cmd_argv, token_debug); */ -diff --git a/src/parse/parse.c b/src/parse/parse.c -index 89102bc..29b3ccb 100644 ---- a/src/parse/parse.c -+++ b/src/parse/parse.c -@@ -6,7 +6,7 @@ - /* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */ - /* +#+#+#+#+#+ +#+ */ - /* Created: 2020/06/17 18:09:04 by nahaddac #+# #+# */ --/* Updated: 2020/07/19 19:25:29 by charles ### ########.fr */ -+/* Updated: 2020/07/20 10:26:14 by nahaddac ### ########.fr */ - /* */ - /* ************************************************************************** */ - -@@ -47,6 +47,13 @@ t_ret *parse_redir(t_ftlst *input, t_ftlst **redirs) - - push_token(redirs, input->data); - input = input->next; -+ if (input == NULL) -+ { -+ errorf("syntax error near unexpected token `newline'\n", NULL); -+ tmp = ret_wrap_ast(NULL, NULL); -+ tmp->syntax_error = true; -+ return tmp; -+ } - tag = ((t_token *)input->data)->tag; - while(input != NULL - && input->next != NULL -@@ -91,7 +98,7 @@ t_ret *parse_cmd(t_ftlst *input) - else if (tag & TAG_IS_REDIR) - { - tmp = parse_redir(input, &ast->redirs); -- if (tmp->syntax_error || tmp == NULL) -+ if (tmp == NULL || tmp->syntax_error) - return tmp; - input = tmp->rest; - } -diff --git a/src/parse/parse_error.c b/src/parse/parse_error.c -index 42d46ea..84b06b2 100644 ---- a/src/parse/parse_error.c -+++ b/src/parse/parse_error.c -@@ -6,90 +6,8 @@ - /* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */ - /* +#+#+#+#+#+ +#+ */ - /* Created: 2020/06/18 15:09:48 by nahaddac #+# #+# */ --/* Updated: 2020/07/17 11:24:23 by nahaddac ### ########.fr */ -+/* Updated: 2020/07/20 10:46:26 by nahaddac ### ########.fr */ - /* */ - /* ************************************************************************** */ - - #include "parser.h" -- --// t_token *error_syntax_parent(t_ftlst *in) --// { --// t_token *tk; --// t_ftlst *first; --// --// first = in; --// while(in != NULL) --// { --// tk = in->data; --// if (tk->tag & TAG_PARENT_OPEN || tk->tag & TAG_PARENT_CLOSE) --// printf("%s\n", "coucouc"); --// in = in->next; --// } --// return first; --// } -- --// int out_error_first(t_token *tk) --// { --// int i; --// --// i = 0; --// if(tk->tag & TAG_IS_SEP) --// return(1); --// if (tk->tag & TAG_IS_REDIR) --// { --// while(tk->content[i]) --// i++; --// if (tk->tag & TAG_REDIR_APPEND && i <= 2) --// return (0); --// else --// return(1); --// } --// return(0); --// } --// --// t_token *error_syntax_simple(t_ftlst *in) --// { --// t_token *tk; --// size_t i; --// /* t_ftlst *first; */ --// --// tk = in->data; --// /* first = in; */ --// if(tk->tag & TAG_IS_SEP || (tk->tag & TAG_IS_REDIR)) --// { --// if (out_error_first(tk)) --// { --// i = ft_strlen(tk->content); --// if (i >= 2) --// tk->content[2] = '\0'; --// tk->content = --// ft_strjoin3("minishell: syntax error near unexpected token `", --// tk->content, "'"); --// return(tk); --// } --// } --// while(in != NULL) --// { --// i = 0; --// tk = in->data; --// if(tk->tag & TAG_IS_SEP || (tk->tag & TAG_IS_REDIR)) --// { --// if (((t_token *)in->next->data)->tag & --// ((t_token*)in->next->data)->tag & TAG_IS_SEP || --// (((t_token*)in->next->data)->tag & TAG_IS_REDIR)) --// { --// tk = in->next->data; --// i = ft_strlen(tk->content); --// if (i >= 3) --// tk->content[2] = '\0'; --// tk->content = --// ft_strjoin3("minishell: syntax error near unexpected token `", --// tk->content, "'"); --// printf("%s\n",tk->content ); --// return(tk); --// } --// } --// in = in->next; --// } --// return 0; --// } -diff --git a/src/preprocess.c b/src/preprocess.c -index 2a884df..a834624 100644 ---- a/src/preprocess.c -+++ b/src/preprocess.c -@@ -3,10 +3,10 @@ - /* ::: :::::::: */ - /* preprocess.c :+: :+: :+: */ - /* +:+ +:+ +:+ */ --/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ -+/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ - /* +#+#+#+#+#+ +#+ */ - /* Created: 2020/04/03 08:58:49 by charles #+# #+# */ --/* Updated: 2020/07/19 19:01:53 by charles ### ########.fr */ -+/* Updated: 2020/07/20 14:12:41 by nahaddac ### ########.fr */ - /* */ - /* ************************************************************************** */ - diff --git a/src/eval/cmd.c b/src/eval/cmd.c index c81c349..951b845 100644 --- a/src/eval/cmd.c +++ b/src/eval/cmd.c @@ -6,7 +6,7 @@ /* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/14 10:41:31 by charles #+# #+# */ -/* Updated: 2020/07/20 14:53:40 by nahaddac ### ########.fr */ +/* Updated: 2020/07/20 18:22:14 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -93,7 +93,7 @@ int eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast) t_fork_param_cmd param; char **argv; char *id; - t_ftlst *tmp; + /* t_ftlst *tmp; */ if (!redir_extract(ast->redirs, env, fds)) { @@ -103,21 +103,48 @@ int eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast) ast->redirs = NULL; if ((param.env_local = env_from_array((char*[]){NULL})) == NULL) return (-1); - // TODO generate token list after `=` for variable value preprocessing + while (ast->cmd_argv != NULL && ((t_token*)ast->cmd_argv->data)->tag & TAG_IS_STR && utils_start_with_valid_identifier(((t_token*)ast->cmd_argv->data)->content)) { + t_ftlst *start; + id = ((t_token*)ast->cmd_argv->data)->content; *ft_strchr(id, '=') = '\0'; ((t_token*)ast->cmd_argv->data)->content = ft_strchr(id, '\0') + 1; - tmp = split_token(&ast->cmd_argv, TAG_STICK); - preprocess(tmp, env); - ft_lstiter(tmp, token_debug); + if (*((t_token*)ast->cmd_argv->data)->content == '\0') + ft_lstpop_front(&ast->cmd_argv, NULL); + else + { + t_ftlst *curr = ast->cmd_argv; + t_ftlst *prev = curr; + + while (curr != NULL + && ((t_token*)curr->data)->tag & TAG_STICK && ((t_token*)curr->data)->tag & TAG_IS_STR) + { + prev = curr; + curr = curr->next; + } + if (curr != NULL && ((t_token*)curr->data)->tag & TAG_IS_STR) + { + prev = curr; + curr = curr->next; + } + + start = ast->cmd_argv; + ast->cmd_argv = prev->next; + prev->next = NULL; + } + + /* ft_lstiter(start, token_debug); */ + /* puts(""); */ + /* ft_lstiter(ast->cmd_argv, token_debug); */ + + char **strs = preprocess(&start, env); - if (env_export(param.env_local,id, ((t_token*)ast->cmd_argv->data)->content) == NULL) + if (env_export(param.env_local, id, strs[0]) == NULL) return (-1); - ft_lstpop_front(&ast->cmd_argv, (void (*)(void*))token_destroy); } if (ast->cmd_argv == NULL) // FIXME special env not passed to child processes { diff --git a/src/eval/utils_eval.c b/src/eval/utils_eval.c index 374411e..5fefe70 100644 --- a/src/eval/utils_eval.c +++ b/src/eval/utils_eval.c @@ -6,7 +6,7 @@ /* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/07/20 13:07:25 by nahaddac #+# #+# */ -/* Updated: 2020/07/20 14:51:40 by nahaddac ### ########.fr */ +/* Updated: 2020/07/20 17:53:18 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,18 +17,38 @@ t_ftlst *split_token(t_ftlst **lst, enum e_token_tag tag) { t_ftlst *curr; t_ftlst *start; + enum e_token_tag curr_tag; start = *lst; curr = *lst; - while (curr != NULL || ((t_token *)curr->data)->tag & tag) + t_ftlst *prev = curr; + while (curr != NULL) { - if (curr->next == NULL || (!(((t_token *)curr->next->data)->tag & tag))) + curr_tag = ((t_token *)curr->data)->tag; + if (!(curr_tag & TAG_STICK) || !(curr_tag & TAG_IS_STR)) { - *lst = curr->next; - curr->next = NULL; - return start; + *lst = prev->next; + prev->next = NULL; + return start; } + prev = curr; curr = curr->next; } - return start; + return start; + + + + /* if (curr != NULL) */ + /* curr_tag = ((t_token *)curr->data)->tag; */ + /* while (curr != NULL && curr_tag & TAG_STICK && curr_tag & TAG_IS_STR) */ + /* { */ + /* curr = curr->next; */ + /* curr_tag = ((t_token *)curr->data)->tag; */ + /* if (curr == NULL || !(curr_tag & TAG_STICK) || !(curr_tag & TAG_IS_STR)) */ + /* { */ + /* *lst = curr->next; */ + /* curr->next = NULL; */ + /* } */ + /* } */ + /* return start; */ } @@ -6,7 +6,7 @@ /* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */ -/* Updated: 2020/07/20 11:21:23 by nahaddac ### ########.fr */ +/* Updated: 2020/07/20 17:35:51 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,7 +66,7 @@ int main(int argc, char **argv, char **envp) path = path_update(NULL, env_search(env, "PATH")); - char *env_exec_path; + /* char *env_exec_path; */ // if ((env_exec_path = ft_htget(path, "env")) == NULL) // { // errorf("env: command not found\n"); @@ -104,7 +104,7 @@ int main(int argc, char **argv, char **envp) if (parser_out == NULL || parser_out->syntax_error) return (1); - ast_print(0, parser_out->ast); + /* ast_print(0, parser_out->ast); */ /* printf("===cmd_argv===\n"); */ /* ft_lstiter(parser_out->ast->cmd_argv, token_debug); */ diff --git a/src/ms_glob.c b/src/ms_glob.c index 19be81c..059ff1c 100644 --- a/src/ms_glob.c +++ b/src/ms_glob.c @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/05 11:44:07 by charles #+# #+# */ -/* Updated: 2020/07/19 15:21:08 by charles ### ########.fr */ +/* Updated: 2020/07/20 17:14:04 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,8 @@ #define MATCHES_VEC_START_SIZE 16 +static char g_glob_path[PATH_MAX]; + /* ** \brief Glob directory iteration function ** for subdirectory matches @@ -31,23 +33,15 @@ */ static int glob_iter_subdir( - char *dirname, struct dirent *entry, struct s_glob_param *param, char *subdir_pattern ) { - char subdir_name[PATH_MAX]; t_ftvec *subdir_matches; size_t i; - ft_strcat3(ft_strcpy(subdir_name, dirname), "/", entry->d_name); - errno = 0; - chdir(subdir_name); - if (errno == EACCES) - return (0); subdir_matches = glob_matches(subdir_pattern); - chdir(dirname); if (subdir_matches == NULL) return (-1); i = 0; @@ -78,7 +72,9 @@ static int glob_iter( ) { char *subdir_pattern; + int ret; + (void)dirname; if (param->pattern[0] != '.' && entry->d_name[0] == '.') return (0); if ((subdir_pattern = ft_strchr(param->pattern, '/')) != NULL) @@ -89,7 +85,6 @@ static int glob_iter( subdir_pattern[-1] = '/'; return (0); } - /* printf("%s %s\n", dirname, entry->d_name); */ if (subdir_pattern != NULL) { if (entry->d_type != DT_DIR && entry->d_type != DT_LNK) @@ -97,7 +92,10 @@ static int glob_iter( subdir_pattern[-1] = '/'; return (0); } - return (glob_iter_subdir(dirname, entry, param, subdir_pattern)); + ft_strcat3(g_glob_path, "/", entry->d_name); + ret = glob_iter_subdir(entry, param, subdir_pattern); + *ft_strrchr(g_glob_path, '/') = '\0'; + return (ret); } if (ft_vecpush_safe(param->matches, ft_strdup(entry->d_name)) == NULL) return (-1); @@ -112,48 +110,16 @@ static int glob_iter( t_ftvec *glob_matches(char *pattern) { - char dirname[PATH_MAX]; struct s_glob_param param; - bool absolute; - size_t i; - if (getcwd(dirname, PATH_MAX) == NULL) + param.pattern = pattern; + if ((param.matches = ft_vecnew(MATCHES_VEC_START_SIZE)) == NULL) return (NULL); - absolute = *pattern == '/'; - if (*pattern == '/') - pattern++; - if ((param.pattern = ft_strdup(pattern)) == NULL || - (param.matches = ft_vecnew(MATCHES_VEC_START_SIZE)) == NULL) + if (utils_directory_iter(g_glob_path, ¶m, (t_directory_iter_func)glob_iter) == -1) { - free(param.pattern); - return (NULL); - } - if (absolute) - chdir("/"); - if (utils_directory_iter(absolute ? "/" : dirname, ¶m, - (t_directory_iter_func)glob_iter) == -1) - { - chdir(dirname); - free(param.pattern); ft_vecdestroy(param.matches, free); return (NULL); } - chdir(dirname); - free(param.pattern); - if (absolute) - { - i = 0; - while (i < param.matches->size) - { - param.matches->data[i] = ft_strjoinf("/", param.matches->data[i], FT_STRJOINF_SND); - if (param.matches->data[i] == NULL) - { - ft_vecdestroy(param.matches, free); - return (NULL); - } - i++; - } - } return (param.matches); } @@ -169,9 +135,26 @@ char *ms_glob(char *pattern) { char *join; t_ftvec *matches; + bool absolute; + size_t i; - if ((matches = glob_matches(pattern)) == NULL) + absolute = *pattern == '/'; + if (absolute) + ft_strcpy(g_glob_path, "/"); + else if (getcwd(g_glob_path, PATH_MAX) == NULL) + return (NULL); + if ((matches = glob_matches(absolute ? pattern + 1 : pattern)) == NULL) return (NULL); + if (absolute) + { + i = -1; + while (++i < matches->size) + if ((matches->data[i] = ft_strjoinf("/", matches->data[i], FT_STRJOINF_SND)) == NULL) + { + ft_vecdestroy(matches, free); + return (NULL); + } + } ft_vecsort(matches, ft_compar_str); if (ft_vecpush(matches, NULL) == NULL || (join = ft_strsjoin((char**)matches->data, " ")) == NULL) diff --git a/src/preprocess.c b/src/preprocess.c index a834624..c9fbd8a 100644 --- a/src/preprocess.c +++ b/src/preprocess.c @@ -6,7 +6,7 @@ /* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/03 08:58:49 by charles #+# #+# */ -/* Updated: 2020/07/20 14:12:41 by nahaddac ### ########.fr */ +/* Updated: 2020/07/20 17:36:09 by charles ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/utils.c b/src/utils.c index 3a27290..b301751 100644 --- a/src/utils.c +++ b/src/utils.c @@ -6,7 +6,7 @@ /* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 11:56:31 by cacharle #+# #+# */ -/* Updated: 2020/07/19 14:53:27 by charles ### ########.fr */ +/* Updated: 2020/07/20 17:06:21 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,9 +26,8 @@ int utils_directory_iter( DIR *dir; struct dirent *entry; - errno = 0; - if ((dir = opendir(dirname)) == NULL) // add fail safe - return (errno == EACCES ? -2 : -1); + if ((dir = opendir(dirname)) == NULL) // EACCES and Not a directory with glob are ignored by bash + return (-2); while ((entry = readdir(dir)) != NULL) if (f(dirname, entry, param) == -1) { |
