diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/b_export.c | 18 | ||||
-rw-r--r-- | src/f_alloc.c | 36 | ||||
-rw-r--r-- | src/f_alloc.h | 21 | ||||
-rw-r--r-- | src/f_fail.c | 7 | ||||
-rw-r--r-- | src/f_fail.h | 2 |
5 files changed, 61 insertions, 23 deletions
diff --git a/src/b_export.c b/src/b_export.c index 9fe5709..9a7c37d 100644 --- a/src/b_export.c +++ b/src/b_export.c @@ -64,28 +64,16 @@ static void while (msh->envp[i] != NULL) i++; if (!(nenvp = (char**)malloc((i + 2) * sizeof(char*)))) - { - lcom_clear(&msh->curr); - s_destroy(msh); - f_fail_alloc(msh); - } + f_fail_alloc_and_destroy(msh); i = 0; while (msh->envp[i] != NULL) { if (!(nenvp[i] = ft_strdup(msh->envp[i]))) - { - lcom_clear(&msh->curr); - s_destroy(msh); - f_fail_alloc(msh); - } + f_fail_alloc_and_destroy(msh); i++; } if (!(nenvp[i] = ft_strdup(var))) - { - lcom_clear(&msh->curr); - s_destroy(msh); - f_fail_alloc(msh); - } + f_fail_alloc_and_destroy(msh); nenvp[i + 1] = 0; ft_delwords(msh->envp); lvars_delone(&msh->vars, varname); diff --git a/src/f_alloc.c b/src/f_alloc.c new file mode 100644 index 0000000..bfa75c3 --- /dev/null +++ b/src/f_alloc.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* f_alloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> + +#include "s_destroy.h" +#include "s_lcom.h" +#include "s_struct.h" + +void + f_fail_alloc(t_msh *msh) +{ + ft_dprintf(STDERR_FILENO, "%s: %s\n", msh->shname, strerror(errno)); + exit(FT_RET_ALLOC); +} + +void + f_fail_alloc_and_destroy(t_msh *msh) +{ + lcom_clear(&msh->curr); + s_destroy(msh); + f_fail_alloc(msh); +} diff --git a/src/f_alloc.h b/src/f_alloc.h new file mode 100644 index 0000000..34a5e7d --- /dev/null +++ b/src/f_alloc.h @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* f_alloc.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef F_ALLOC_H +#define F_ALLOC_H + +#include "s_struct.h" + +void f_fail_alloc(t_msh *msh); +void f_fail_alloc_and_destroy(t_msh *msh); + +#endif diff --git a/src/f_fail.c b/src/f_fail.c index a3a1df1..5e6824f 100644 --- a/src/f_fail.c +++ b/src/f_fail.c @@ -49,10 +49,3 @@ void { write_fail(concern, FT_FAIL_TOO_MANY_ARGS, msh); } - -void - f_fail_alloc(t_msh *msh) -{ - ft_dprintf(STDERR_FILENO, "%s: %s\n", msh->shname, strerror(errno)); - exit(FT_RET_ALLOC); -} diff --git a/src/f_fail.h b/src/f_fail.h index 868fe75..4d7c8d4 100644 --- a/src/f_fail.h +++ b/src/f_fail.h @@ -14,6 +14,7 @@ #define F_FAIL_H #include "f_com.h" +#include "f_alloc.h" #include "f_chdir.h" #include "f_errno.h" #include "f_redir.h" @@ -26,6 +27,5 @@ void f_fail_too_many_args(const char concern[], void f_fail_identifier(const char concern[], const char identifier[], t_msh *msh); -void f_fail_alloc(t_msh *msh); #endif |