diff options
| author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-28 18:57:09 +0200 | 
|---|---|---|
| committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-28 18:57:09 +0200 | 
| commit | 2d75e800a1cd3dff630ec0080a864ef1779496c9 (patch) | |
| tree | fa1ffe1d148a0cb731d8622c635963dd450fd084 | |
| parent | TODO.org update (diff) | |
| download | 42-minishell-2d75e800a1cd3dff630ec0080a864ef1779496c9.tar.gz 42-minishell-2d75e800a1cd3dff630ec0080a864ef1779496c9.tar.bz2 42-minishell-2d75e800a1cd3dff630ec0080a864ef1779496c9.tar.xz 42-minishell-2d75e800a1cd3dff630ec0080a864ef1779496c9.tar.zst 42-minishell-2d75e800a1cd3dff630ec0080a864ef1779496c9.zip  | |
New libft funcs
Diffstat (limited to '')
| -rw-r--r-- | libft/Makefile | 2 | ||||
| -rw-r--r-- | libft/include/libft.h | 2 | ||||
| -rw-r--r-- | libft/src/ft_abs.c | 16 | ||||
| -rw-r--r-- | libft/src/ft_labs.c | 16 | ||||
| -rw-r--r-- | src/p_redirs.c | 21 | 
5 files changed, 46 insertions, 11 deletions
diff --git a/libft/Makefile b/libft/Makefile index 1c90f66..701d902 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -115,6 +115,8 @@ SRCS_NAME	+= ft_printf_cat_output.c  SRCS_NAME	+= ft_printf_flag_to_atoi.c  SRCS_NAME	+= ft_strsubst.c  SRCS_NAME	+= ft_strsubst_s.c +SRCS_NAME	+= ft_abs.c +SRCS_NAME	+= ft_labs.c  #------------------------------------------------------------------------------#  SRCS		= $(addprefix ${SRCS_DIR},${SRCS_NAME})  #------------------------------------------------------------------------------# diff --git a/libft/include/libft.h b/libft/include/libft.h index edd04d4..d2bea38 100644 --- a/libft/include/libft.h +++ b/libft/include/libft.h @@ -163,6 +163,8 @@ int						ft_putendl(const char *s);  int						ft_putchar_fd(char c, int fd);  int						ft_putstr_fd(char *s, int fd);  int						ft_strcmp(const char *s1, const char *s2); +int						ft_abs(int j); +long					ft_labs(long j);  long					ft_memlchr(const void *s, int c, size_t n);  long					ft_strlchr(const char *s, int c);  size_t					ft_strlen(const char *s); diff --git a/libft/src/ft_abs.c b/libft/src/ft_abs.c new file mode 100644 index 0000000..c732fee --- /dev/null +++ b/libft/src/ft_abs.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/*                                                                            */ +/*                                                        :::      ::::::::   */ +/*   ft_abs.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   */ +/*                                                                            */ +/* ************************************************************************** */ + +int		ft_abs(int j) +{ +	return ((j < 0) ? (-j) : (j)); +} diff --git a/libft/src/ft_labs.c b/libft/src/ft_labs.c new file mode 100644 index 0000000..980c005 --- /dev/null +++ b/libft/src/ft_labs.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/*                                                                            */ +/*                                                        :::      ::::::::   */ +/*   ft_labs.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   */ +/*                                                                            */ +/* ************************************************************************** */ + +long	ft_labs(long j) +{ +	return ((j < 0) ? (-j) : (j)); +} diff --git a/src/p_redirs.c b/src/p_redirs.c index b615d01..eeaefea 100644 --- a/src/p_redirs.c +++ b/src/p_redirs.c @@ -56,28 +56,27 @@ static size_t	p_get_path(char path[],  {  	char	h[PATH_MAX];  	size_t	pos[2]; -	size_t	hlen; -	size_t	len; +	size_t	len[2]; -	hlen = 0; -	tmp.redir = (tmp.redir < 0) ? (-tmp.redir) : (tmp.redir); -	tmp.ptr += tmp.redir; +	len[1] = 0; +	tmp.ptr += ft_abs(tmp.redir); +	tmp.ptr += (tmp.redir == -2 && *tmp.ptr == '-') ? (1) : (0);  	while (*tmp.ptr != C_NUL && ft_iswhitespace(*tmp.ptr) == TRUE)  		tmp.ptr++;  	if (*tmp.ptr == C_TILDE && u_get_var_value(h, "$HOME", PATH_MAX, msh) == 0)  	{  		ft_strlcpy(path, h, PATH_MAX); -		hlen = ft_strlen(h); +		len[1] = ft_strlen(h);  		tmp.ptr++;  	}  	pos[0] = (tmp.ptr - tmp.word); -	while (*tmp.ptr != C_NUL && ft_iswhitespace(*tmp.ptr) == FALSE && -		u_is_not_escaped(tmp.word, tmp.ptr) == TRUE) +	while (*tmp.ptr != C_NUL && ft_iswhitespace(*tmp.ptr) == FALSE +		&& u_is_not_escaped(tmp.word, tmp.ptr) == TRUE)  		tmp.ptr++;  	pos[1] = (tmp.ptr - tmp.word); -	len = (pos[1] - pos[0]); -	len = ((hlen + len + 1) > PATH_MAX) ? (PATH_MAX - 1) : (len); -	ft_strlcpy(path + hlen, tmp.word + pos[0], len + 1); +	len[0] = (pos[1] - pos[0]); +	len[0] = ((len[1] + len[0] + 1) > PATH_MAX) ? (PATH_MAX - 1) : (len[0]); +	ft_strlcpy(path + len[1], tmp.word + pos[0], len[0] + 1);  	return (pos[1]);  }  | 
