toujours un pbm dans le free
This commit is contained in:
172
get_next_line.c
172
get_next_line.c
@@ -1,86 +1,100 @@
|
||||
#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;
|
||||
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)) > 0)
|
||||
{
|
||||
printf(" [fd%i-%i] \n", fd[i], ret );
|
||||
free(line);
|
||||
j = 0;
|
||||
}
|
||||
else if (ret == -1)
|
||||
{
|
||||
printf("[fd%i-%i]*ERROR*\n", fd[i], ret);
|
||||
free(line);
|
||||
j++;
|
||||
}
|
||||
else if (*line != '\0')
|
||||
printf(" [fd%i-%i] \n", fd[i], ret);
|
||||
else
|
||||
{
|
||||
printf("[fd%i-%i]*FINI*\n", fd[i], ret);
|
||||
free(line);
|
||||
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
|
||||
**
|
||||
** void ft_putchar(char c){
|
||||
** write(1, &c, 1);
|
||||
** }
|
||||
**
|
||||
** void ft_putstr(char *s)
|
||||
** {
|
||||
** while (s && *s)
|
||||
** ft_putchar(*s++);
|
||||
** }
|
||||
**
|
||||
** void ft_putnbr(int n)
|
||||
** {
|
||||
** long l;
|
||||
**
|
||||
** l = n;
|
||||
** if (l < 0)
|
||||
** {
|
||||
** ft_putchar('-');
|
||||
** l *= -1;
|
||||
** }
|
||||
** if (l >= 10)
|
||||
** ft_putnbr(l / 10);
|
||||
** ft_putchar((l % 10) + '0');
|
||||
** }
|
||||
**
|
||||
** 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)) > 0)
|
||||
** {
|
||||
** printf(" [fd%i-%i] \n", fd[i], ret );
|
||||
** free(line);
|
||||
** j = 0;
|
||||
** }
|
||||
** else if (ret == -1)
|
||||
** {
|
||||
** printf("[fd%i-%i]*ERROR*\n", fd[i], ret);
|
||||
** free(line);
|
||||
** j++;
|
||||
** }
|
||||
** else if (*line != '\0')
|
||||
** printf(" [fd%i-%i] \n", fd[i], ret);
|
||||
** else
|
||||
** {
|
||||
** printf("[fd%i-%i]*FINI*\n", fd[i], ret);
|
||||
** free(line);
|
||||
** 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;
|
||||
int count;
|
||||
|
||||
tmp = *lst;
|
||||
count = 0;
|
||||
while (tmp != NULL && tmp->next != *lst && tmp->str[0] == '\0')
|
||||
{
|
||||
count++;
|
||||
tmp = *lst; // t_gnlist *tmp2;/*ft_putstr("\n");*/ft_putstr("(");
|
||||
while (tmp->next != *lst)
|
||||
{ // ft_putnbr(tmp->lfd);ft_putstr("-");
|
||||
tmp = tmp->next;
|
||||
}
|
||||
printf("%i", count);
|
||||
// if (ret == -1 || tmp->str == '\0')
|
||||
// {
|
||||
// while (tmp != NULL)
|
||||
// {
|
||||
// tmp = (*lst)->next;
|
||||
// free((*lst)->str);
|
||||
// free(*lst);
|
||||
// *lst = NULL;
|
||||
// *lst = tmp;
|
||||
// }
|
||||
// }
|
||||
} // ft_putnbr(tmp->lfd);ft_putstr("-(");ft_putnbr(tmp->next->lfd);ft_putstr("))");
|
||||
tmp->next = (*lst)->next; // ft_putstr("->(");ft_putnbr(tmp->lfd);ft_putstr("-");ft_putnbr(tmp->next->lfd);ft_putstr(")");
|
||||
free((*lst)->str);
|
||||
free(*lst);
|
||||
*lst = (*lst == tmp) ? NULL : tmp; // tmp2=tmp;ft_putstr("(");while(tmp2->next!=tmp){ft_putnbr(tmp2->lfd);ft_putstr("-");tmp2=tmp2->next;}ft_putnbr(tmp2->lfd);ft_putstr("-(");ft_putnbr(tmp2->next->lfd);ft_putstr("))");
|
||||
return (ret);
|
||||
}
|
||||
|
||||
@@ -88,11 +102,13 @@ int multi_fd(int fd, t_gnlist **lst)
|
||||
{
|
||||
t_gnlist *tmp;
|
||||
|
||||
tmp = *lst;
|
||||
tmp = *lst; // t_gnlist *tmp2;ft_putstr(" multi(fd:");ft_putnbr(fd);ft_putstr("-(check:");tmp2=tmp;while(tmp2 && tmp2->next!=tmp){ft_putnbr(tmp2->lfd);ft_putstr("-");tmp2=tmp2->next;}if(tmp2)ft_putnbr(tmp2->lfd);ft_putstr(")-(start:");
|
||||
while (*lst && (*lst)->lfd != fd && (*lst)->next != tmp)
|
||||
{ // ft_putnbr((*lst)->lfd);ft_putstr("-");
|
||||
*lst = (*lst)->next;
|
||||
} // if(*lst)ft_putnbr((*lst)->lfd);ft_putstr(")-(");
|
||||
if (!tmp || ((*lst)->next == tmp && (*lst)->lfd != fd))
|
||||
{
|
||||
{ // ft_putstr("create ");
|
||||
if (!(tmp = (t_gnlist*)malloc(sizeof(*tmp))))
|
||||
return (0);
|
||||
tmp->lfd = fd;
|
||||
@@ -106,7 +122,7 @@ int multi_fd(int fd, t_gnlist **lst)
|
||||
else
|
||||
tmp->next = tmp;
|
||||
*lst = tmp;
|
||||
}
|
||||
} // ft_putstr("lfd:");ft_putnbr((*lst)->lfd);ft_putstr(")-(");tmp2=*lst;while(tmp2->next!=*lst){ft_putnbr(tmp2->lfd);ft_putstr("-");tmp2=tmp2->next;}ft_putnbr(tmp2->lfd);ft_putstr("-(");ft_putnbr(tmp2->next->lfd);ft_putstr("))");
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user