From 5ad7f13d931526f274079bfee0f7a2497b39f4ed Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Mon, 30 Dec 2019 19:42:38 +0100 Subject: [PATCH] erreur en cas de mauvais nom de fichier --- get_next_line.c | 57 ++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/get_next_line.c b/get_next_line.c index 94027ca..fffae83 100644 --- a/get_next_line.c +++ b/get_next_line.c @@ -1,15 +1,3 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: hulamy +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/12/29 18:07:43 by hulamy #+# #+# */ -/* Updated: 2019/12/29 18:08:47 by hulamy ### ########.fr */ -/* */ -/* ************************************************************************** */ - #include "get_next_line.h" @@ -39,20 +27,24 @@ i = 0; while (j < ac - 1) { - if ((ret = get_next_line(fd[i], &line))) + if ((ret = get_next_line(fd[i], &line)) > 0) { printf("[fd%i-%i] %s\n", fd[i], ret, line); free(line); j = 0; } - else if (*line != '\0') + else if (ret == -1) { - printf("[fd%i-%i] %s\n", fd[i], ret, line); + printf("[fd%i-%i]*ERROR*\n", fd[i], ret); free(line); + j++; } + else if (*line != '\0') + printf("[fd%i-%i] %s\n", fd[i], ret, line); else { - printf("[fd%i-%i]*FINI*\n", fd[i], ret); + printf("[fd%i-%i]*FINI*(%s)\n", fd[i], ret, line); + free(line); j++; } i++; @@ -70,26 +62,19 @@ int free_lst(t_gnlist **lst, int ret) t_gnlist *tmp; tmp = *lst; - //while (tmp->next != *lst) - // tmp = tmp->next; - //tmp->next = tmp->next->next; - - ////////////////////////////////////////////////////////// - int count = 1; // - while (tmp->next != *lst) // - { // - printf("-%i", tmp->lfd); // - tmp = tmp->next; // - count++; // - } // - printf("-%i-(%i)", tmp->lfd, count); // - tmp->next = tmp->next->next; // - printf("(%i-%i)", tmp->lfd, tmp->next->lfd); // - ////////////////////////////////////////////////////////// - - free((*lst)->str); - free(*lst); - *lst = NULL; + while (tmp != NULL && tmp->next != *lst && tmp->str == '\0') + tmp = tmp->next; + if (ret == -1 || tmp->str == '\0') + { + while (tmp != NULL) + { + tmp = (*lst)->next; + free((*lst)->str); + free(*lst); + *lst = NULL; + *lst = tmp; + } + } return (ret); }