add protect bonus
This commit is contained in:
@ -6,12 +6,11 @@
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/01 17:11:59 by adjoly #+# #+# */
|
||||
/* Updated: 2023/12/14 13:06:54 by adjoly ### ########.fr */
|
||||
/* Updated: 2023/12/14 13:27:41 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "get_next_line.h"
|
||||
#include <unistd.h>
|
||||
|
||||
char check_line(char *res, char *buf)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/01 17:11:59 by adjoly #+# #+# */
|
||||
/* Updated: 2023/12/14 11:57:16 by adjoly ### ########.fr */
|
||||
/* Updated: 2023/12/14 13:27:45 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -37,12 +37,22 @@ char check_line(char *res, char *buf)
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *gnl_end_line(char *res)
|
||||
{
|
||||
if (res[0] != 0)
|
||||
return (res);
|
||||
free(res);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *get_next_line(int fd)
|
||||
{
|
||||
static char *buf[1024];
|
||||
char *res;
|
||||
ssize_t bytes_read;
|
||||
|
||||
if (BUFFER_SIZE <= 0 || fd < 0 || fd > 1023)
|
||||
return (NULL);
|
||||
res = ft_calloc(1, 1);
|
||||
if (!buf[fd])
|
||||
buf[fd] = ft_calloc(sizeof(char), BUFFER_SIZE + 1);
|
||||
@ -56,30 +66,9 @@ char *get_next_line(int fd)
|
||||
{
|
||||
free(buf[fd]);
|
||||
buf[fd] = NULL;
|
||||
if (res[0] != 0)
|
||||
return (res);
|
||||
free(res);
|
||||
return (NULL);
|
||||
return (gnl_end_line(res));
|
||||
}
|
||||
buf[fd][bytes_read] = 0;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*#include <unistd.h>
|
||||
void ft_putstr(char *str){if (str == NULL){return ;}int i = 0;while(str[i]){write(1, &str[i], 1);i++;}}
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
int main(void)
|
||||
{
|
||||
char *ln;
|
||||
int fd;
|
||||
fd = open("test.txt", O_RDONLY);
|
||||
while (ln)
|
||||
{
|
||||
ln = get_next_line(fd);
|
||||
ft_putstr(ln);
|
||||
free(ln);
|
||||
}
|
||||
close(fd);
|
||||
}*/
|
||||
|
Reference in New Issue
Block a user