realpath is in

added realpath to libft
removed local references to realpath
This commit is contained in:
Tanguy MAZE 2019-01-29 18:26:04 +01:00
parent 9a1bc7b613
commit f88be73e8b
4 changed files with 4 additions and 75 deletions

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/18 13:12:34 by tmaze #+# #+# */ /* Created: 2018/11/18 13:12:34 by tmaze #+# #+# */
/* Updated: 2019/01/27 14:43:56 by tmaze ### ########.fr */ /* Updated: 2019/01/29 18:23:45 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -47,6 +47,4 @@ int ft_isin(char *str, char c);
char *check_path_slash(char *exec); char *check_path_slash(char *exec);
char *check_path_dot(char *exec, t_list *env); char *check_path_dot(char *exec, t_list *env);
char *ft_realpath(char *r_path, char **a_path);
#endif #endif

2
libft

@ -1 +1 @@
Subproject commit 19d3e23b743dc95d0301579d1c5a0b97b36695aa Subproject commit 4b44c49fc6caa15379cd821f967e53462d4dc837

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/07 16:44:40 by tmaze #+# #+# */ /* Created: 2019/01/07 16:44:40 by tmaze #+# #+# */
/* Updated: 2019/01/28 16:53:32 by tmaze ### ########.fr */ /* Updated: 2019/01/29 16:12:21 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -53,9 +53,9 @@ int cmd_cd_core(char *path, t_list **env, char opt)
{ {
t_envelem *pwd; t_envelem *pwd;
char *oldpwd; char *oldpwd;
char *c_path;
char *tmp; char *tmp;
opt = '\0';
if (check_path_slash_cd(path) == NULL) if (check_path_slash_cd(path) == NULL)
{ {
put_error_cd(path, "invalid path"); put_error_cd(path, "invalid path");

View File

@ -1,69 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_realpath.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/27 14:42:35 by tmaze #+# #+# */
/* Updated: 2019/01/28 15:32:44 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *ft_tabtopath(char **tab_path)
{
size_t total_size;
size_t i;
char *ret;
i = 0;
total_size = 0;
while (tab_path[i])
total_size += ft_strlen(tab_path[i++]);
if ((ret = ft_strnew(total_size + i)) == NULL)
return (NULL);
i = 0;
while (tab_path[i])
{
ft_strcat(ret, "/");
ft_strcat(ret, tab_path[i++]);
}
return (ret);
}
char *ft_realpath(char *r_path, char **a_path)
{
char **tab_path;
size_t i;
size_t j;
int strcmp;
i = 0;
if ((tab_path = ft_strsplit(r_path, '/')) == NULL)
return (NULL);
while (tab_path[i])
{
if ((strcmp = ft_strcmp(tab_path[i], "..")) == 0
|| ft_strcmp(tab_path[i], ".") == 0)
{
j = i;
if (strcmp == 0 && i != 0)
i = i - 1;
ft_strdel(&(tab_path[i]));
if (strcmp == 0 && i != 0)
ft_strdel(&(tab_path[j]));
while (tab_path[++j])
tab_path[j - ((strcmp == 0 && i != 0) ? 2 : 1)] = tab_path[j];
if (strcmp == 0 && i != 0)
tab_path[j - 2] = NULL;
tab_path[j - 1] = NULL;
}
else
i++;
}
*a_path = ft_tabtopath(tab_path);
ft_del_words_tables(&tab_path);
return (*a_path);
}