diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-09 10:53:57 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-09 10:53:57 +0200 |
| commit | c16cf5fcc4a421608bf3c291ef84a79b7dbe7591 (patch) | |
| tree | 2c7b814f7e9eee40d34a6cf26b4948c39fecfc4c /src/path.c | |
| parent | 9dca7dc98e46d5b29e236f2970072ffaf582e13e (diff) | |
| parent | 9fabc25a980550afc6337fd729632462f2680daa (diff) | |
| download | minishell-c16cf5fcc4a421608bf3c291ef84a79b7dbe7591.tar.gz minishell-c16cf5fcc4a421608bf3c291ef84a79b7dbe7591.tar.bz2 minishell-c16cf5fcc4a421608bf3c291ef84a79b7dbe7591.zip | |
Merge branch 'eval'
Diffstat (limited to 'src/path.c')
| -rw-r--r-- | src/path.c | 28 |
1 files changed, 11 insertions, 17 deletions
@@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/27 15:51:01 by cacharle #+# #+# */ -/* Updated: 2020/04/01 17:55:28 by charles ### ########.fr */ +/* Updated: 2020/04/05 12:09:05 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ */ #include "minishell.h" +#include "utils.h" /* ** \brief Number of buckets of a path hash table @@ -31,24 +32,17 @@ ** \return Same path or NULL on error */ -static t_path st_path_dir_update(t_path path, char *dirname) +static int st_add_file(char *dirname, struct dirent *entry, void *path) { - DIR *dir; - struct dirent *entry; - char *tmp; + char *filepath; - if ((dir = opendir(dirname)) == NULL) - return (NULL); - while ((entry = readdir(dir)) != NULL) + if ((filepath = ft_strjoin3(dirname, "/", entry->d_name)) == NULL || + ft_htset((t_path)path, entry->d_name, filepath, free) == NULL) { - if ((tmp = ft_strjoin3(dirname, "/", entry->d_name)) == NULL) - return (NULL); - if (ft_htset(path, entry->d_name, tmp, ht_del_str_entry) == NULL) - return (NULL); + free(filepath); + return (-1); } - if (closedir(dir) == -1) - return (NULL); - return (path); + return (0); } /* @@ -71,8 +65,8 @@ t_path path_update(t_path path, char *path_var) if ((dirs = ft_split(path_var, ':')) == NULL) return (NULL); i = -1; - while (dirs[++i] != NULL) - if (st_path_dir_update(path, dirs[i]) == NULL) + while (dirs[++i] != NULL) // carefull with non existant dir error + if (utils_directory_iter(dirs[i], path, st_add_file) == -1) return (ft_split_destroy(dirs)); ft_split_destroy(dirs); return (path); |
