aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/minishell.h10
m---------libft0
m---------minishell_test0
-rw-r--r--src/path.c28
-rw-r--r--src/utils.c23
5 files changed, 20 insertions, 41 deletions
diff --git a/include/minishell.h b/include/minishell.h
index 573ac29..085f082 100644
--- a/include/minishell.h
+++ b/include/minishell.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/26 15:33:51 by cacharle #+# #+# */
-/* Updated: 2020/09/09 14:04:00 by charles ### ########.fr */
+/* Updated: 2020/09/09 15:42:03 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -125,14 +125,6 @@ void signal_sigterm(int signum);
** utils.c
*/
-typedef int (*t_directory_iter_func)(char*, struct dirent*, void*);
-
-int utils_directory_iter(
- char *dirname,
- void *param,
- t_directory_iter_func f
-);
-
size_t utils_var_end(char *name);
bool utils_valid_identifier(char *name);
bool utils_start_with_valid_identifier(char *name);
diff --git a/libft b/libft
-Subproject d3cf16e078e92ab85e5ad2f30f2c07ce382fd98
+Subproject 50876fe6b9e369d6b51bac9fa62b790ef5bda9d
diff --git a/minishell_test b/minishell_test
-Subproject fb3df181b71d3bed23f43ea4a6fcd8111d4c869
+Subproject f571ffc6beb34cf0d4a171e5b5aa70a1d2b8365
diff --git a/src/path.c b/src/path.c
index 1234998..0de0bad 100644
--- a/src/path.c
+++ b/src/path.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/27 15:51:01 by cacharle #+# #+# */
-/* Updated: 2020/07/17 10:48:31 by charles ### ########.fr */
+/* Updated: 2020/09/09 15:49:50 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -28,19 +28,27 @@
** in the directory named `dirname`.
** \param path Path hash table
** \param dirname directory name
-** \return Same path or NULL on error
+** \return -1 on error, 0 or -2 otherwise
*/
-static int st_add_file(char *dirname, struct dirent *entry, void *path)
+static int st_add_directory(t_path path, char *dirname)
{
- char *filepath;
+ DIR *dir;
+ struct dirent *entry;
- if ((filepath = ft_strjoin3(dirname, "/", entry->d_name)) == NULL ||
- ft_htset((t_path)path, entry->d_name, filepath, free) == NULL)
+ if ((dir = opendir(dirname)) == NULL)
+ return (-2);
+ while ((entry = readdir(dir)) != NULL)
{
- free(filepath);
- return (-1);
+ if (ft_htset_safe(path, entry->d_name,
+ ft_strjoin3(dirname, "/", entry->d_name), free) == NULL)
+ {
+ closedir(dir);
+ return (-1);
+ }
}
+ if (closedir(dir) == -1)
+ return (-1);
return (0);
}
@@ -66,8 +74,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) // carefull with non existant dir error
- if (utils_directory_iter(dirs[i], path, st_add_file) == -1)
+ while (dirs[++i] != NULL)
+ if (st_add_directory(path, dirs[i]) == -1)
return (ft_split_destroy(dirs));
ft_split_destroy(dirs);
return (path);
diff --git a/src/utils.c b/src/utils.c
index d511195..55c190b 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/09/09 14:05:53 by charles ### ########.fr */
+/* Updated: 2020/09/09 15:41:04 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,27 +17,6 @@
#include "minishell.h"
-int utils_directory_iter(
- char *dirname,
- void *param,
- int (*f)(char*, struct dirent*, void*)
-)
-{
- DIR *dir;
- struct dirent *entry;
-
- 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)
- {
- closedir(dir);
- return (-1);
- }
- if (closedir(dir) == -1)
- return (-1);
- return (0);
-}
/* bool utils_is_var_name(char *name) */
/* { */