diff options
| -rw-r--r-- | Makefile | 5 | ||||
| -rw-r--r-- | libft/Makefile | 15 | ||||
| -rw-r--r-- | libft/include/libft.h (renamed from libft/inc/libft.h) | 0 | ||||
| -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 | 
8 files changed, 76 insertions, 28 deletions
| @@ -3,14 +3,14 @@ default: all  #--------------------------------- SHELL --------------------------------------#  #==============================================================================#  SHELL			:= /bin/sh -OS				= $(shell uname) +OS				 = $(shell uname)  #==============================================================================#  #------------------------------ DIRECTORIES -----------------------------------#  #==============================================================================#  SRCS_DIR		 = src/  OBJS_DIR		 = obj/  LFT_DIR			 = libft/ -LFT_INCS_DIR	 = ${LFT_DIR}inc/ +LFT_INCS_DIR	 = ${LFT_DIR}include/  LFT_SRCS_DIR	 = ${LFT_DIR}src/  #==============================================================================#  #--------------------------------- FILES --------------------------------------# @@ -30,6 +30,7 @@ SRCS_NAME		+= e_externs_next  SRCS_NAME		+= e_externs_pipes  SRCS_NAME		+= e_lcom  SRCS_NAME		+= e_pipes +SRCS_NAME		+= f_alloc  SRCS_NAME		+= f_chdir  SRCS_NAME		+= f_com  SRCS_NAME		+= f_errno diff --git a/libft/Makefile b/libft/Makefile index 6803f66..ac06d94 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -3,10 +3,11 @@ default: all  #--------------------------------- Shell --------------------------------------#  #==============================================================================#  SHELL		:= /bin/sh +OS			 = $(shell uname)  #==============================================================================#  #------------------------------ Directories -----------------------------------#  #==============================================================================# -INCS_DIR	= inc/ +INCS_DIR	= include/  SRCS_DIR	= src/  OBJS_DIR	= obj/  #==============================================================================# @@ -120,9 +121,17 @@ OS			= $(shell uname)  #==============================================================================#  #-------------------------------- Compiler ------------------------------------#  #==============================================================================# -CC			= clang +ifeq (${OS}, FreeBSD) +CC			 = /usr/bin/cc +endif +ifeq (${OS}, Linux) +CC			 = /usr/bin/clang-9 +endif +ifeq (${OS}, Darwin) +CC			 = clang +endif  #------------------------------------------------------------------------------# -CFLAGS		= -std=c89 +CFLAGS		 = -std=c89  CFLAGS		+= -Wall  CFLAGS		+= -Wextra  CFLAGS		+= -Werror diff --git a/libft/inc/libft.h b/libft/include/libft.h index 5ddb471..5ddb471 100644 --- a/libft/inc/libft.h +++ b/libft/include/libft.h 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 | 
