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