static char *concatenate(char *path, char *pwd) { char *extract; char *tmp; while ((extract = ft_strdupchr(path, '/'))) { if (!ft_strcmp(extract, "..")) { tmp = ft_strrchr(pwd, '/'); ft_bzero(tmp, ft_strlen(tmp)); move_str(&path, 3, -3, ft_strlen(path)); ft_bzero(path + ft_strlen(path) - 3, 3); } else { pwd = ft_freejoin(pwd, "/"); pwd = ft_freejoin(pwd, extract); move_str(&path, ft_strlen(extract) + 1, -(ft_strlen(extract) + 1), ft_strlen(pwd)); } ft_strdel(&extract); } if (ft_strcmp(pwd, "/")) pwd = ft_freejoin(pwd, "/"); return (ft_freejoin(pwd, path)); }
int get_next_line(int const fd, char **line) { char buf[BUFF_SIZE + 1]; int ret; static t_list *list = NULL; t_list *begin; char *copy; if (fd < 0 || line == NULL || read(fd, buf, 0) < 0) return (-1); begin = list; list = ft_findfd(&begin, fd); while (!ft_strchr(list->content, '\n') && (ret = read(fd, buf, BUFF_SIZE))) list->content = ft_freejoin(list->content, buf, ret); ret = 0; while (((char*)list->content)[ret] && ((char*)list->content)[ret] != '\n') ++ret; *line = ft_strsub(list->content, 0, ret); if (((char*)list->content)[ret] == '\n') ++ret; copy = list->content; list->content = ft_strdup(list->content + ret); free(copy); list = begin; return (ret ? 1 : 0); }