nouvelle chasse aux leaks..
This commit is contained in:
127
get_next_line.c
127
get_next_line.c
@@ -12,67 +12,84 @@
|
|||||||
|
|
||||||
#include "get_next_line.h"
|
#include "get_next_line.h"
|
||||||
|
|
||||||
/*
|
|
||||||
** //:set noendofline binary
|
//:set noendofline binary
|
||||||
** //https://github.com/lgrellie/gnl_tester
|
//https://github.com/lgrellie/gnl_tester
|
||||||
** //https://github.com/Mazoise/42TESTERS-GNL
|
//https://github.com/Mazoise/42TESTERS-GNL
|
||||||
** //https://github.com/charMstr/GNL_lover
|
//https://github.com/charMstr/GNL_lover
|
||||||
** //https://github.com/mrjvs/42cursus_gnl_tests
|
//https://github.com/mrjvs/42cursus_gnl_tests
|
||||||
** //https://github.com/Sherchryst/gnlkiller
|
//https://github.com/Sherchryst/gnlkiller
|
||||||
** //https://github.com/Hellio404/Get_Next_Line_Tester
|
//https://github.com/Hellio404/Get_Next_Line_Tester
|
||||||
** //https://github.com/TinfoilPancakes/get-next-line-testing-tools
|
//https://github.com/TinfoilPancakes/get-next-line-testing-tools
|
||||||
**
|
|
||||||
** #include <stdio.h> //for printf
|
#include <stdio.h> //for printf
|
||||||
** #include <fcntl.h> //for open
|
#include <fcntl.h> //for open
|
||||||
**
|
|
||||||
** int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
** {
|
{
|
||||||
** int *fd;
|
int *fd;
|
||||||
** int i = 0;
|
int i = 0;
|
||||||
** int j = 0;
|
int j = 0;
|
||||||
** int ret = 1;
|
int ret;
|
||||||
** char *line = NULL;
|
char *line = NULL;
|
||||||
**
|
|
||||||
** fd = (int *)malloc(sizeof(int) * ac);
|
fd = (int *)malloc(sizeof(int) * ac);
|
||||||
** while (++i <= ac - 1)
|
while (++i <= ac - 1)
|
||||||
** fd[i - 1] = open(av[i], O_RDONLY);
|
fd[i - 1] = open(av[i], O_RDONLY);
|
||||||
** i = 0;
|
i = 0;
|
||||||
** while (j < ac - 1)
|
while (j < ac - 1)
|
||||||
** {
|
{
|
||||||
** if (ret > 0)
|
if ((ret = get_next_line(fd[i], &line)))
|
||||||
** {
|
{
|
||||||
** ret = get_next_line(fd[i], &line);
|
printf("[fd%i-%i] %s\n", fd[i], ret, line);
|
||||||
** printf("[fd%i-%i] %s\n", fd[i], ret, line);
|
free(line);
|
||||||
** free(line);
|
j = 0;
|
||||||
** j = 0;
|
}
|
||||||
** }
|
else if (*line != '\0')
|
||||||
** else
|
{
|
||||||
** {
|
printf("[fd%i-%i] %s\n", fd[i], ret, line);
|
||||||
** printf("[fd%i-%i]*FINI*\n", fd[i], ret);
|
free(line);
|
||||||
** j++;
|
}
|
||||||
** }
|
else
|
||||||
** i++;
|
{
|
||||||
** if (i >= ac - 1)
|
printf("[fd%i-%i]*FINI*\n", fd[i], ret);
|
||||||
** i = 0;
|
j++;
|
||||||
** }
|
}
|
||||||
** free(fd);
|
i++;
|
||||||
** //while (1);
|
if (i >= ac - 1)
|
||||||
** return (0);
|
i = 0;
|
||||||
** }
|
}
|
||||||
*/
|
free(fd);
|
||||||
|
//while (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int free_lst(t_gnlist **lst, int ret)
|
int free_lst(t_gnlist **lst, int ret)
|
||||||
{
|
{
|
||||||
t_gnlist *tmp;
|
t_gnlist *tmp;
|
||||||
|
|
||||||
tmp = *lst;
|
tmp = *lst;
|
||||||
while ((*lst)->next != tmp)
|
//while (tmp->next != *lst)
|
||||||
(*lst) = (*lst)->next;
|
// tmp = tmp->next;
|
||||||
(*lst)->next = (*lst)->next->next;
|
//tmp->next = tmp->next->next;
|
||||||
free(tmp->str);
|
|
||||||
free(tmp);
|
//////////////////////////////////////////////////////////
|
||||||
tmp = NULL;
|
int count = 1; //
|
||||||
*lst = tmp;
|
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;
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user