gnl bonus working
This commit is contained in:
@ -1,73 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/24 11:51:43 by madumerg #+# #+# */
|
||||
/* Updated: 2023/12/08 17:21:26 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "get_next_line.h"
|
||||
|
||||
size_t ft_strlen(char *str)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *ft_strjoin(char *s1, char *s2)
|
||||
{
|
||||
size_t len;
|
||||
size_t i;
|
||||
size_t j;
|
||||
char *str;
|
||||
|
||||
if (!s2)
|
||||
return (NULL);
|
||||
len = ft_strlen(s1) + ft_strlen(s2);
|
||||
str = malloc(sizeof(char) * (len + 1));
|
||||
if (!str)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (s1[i] != '\0')
|
||||
{
|
||||
str[i] = s1[i];
|
||||
i++;
|
||||
}
|
||||
j = 0;
|
||||
while (s2[j] != '\0')
|
||||
str[i++] = s2[j++];
|
||||
free(s1);
|
||||
str[i] = '\0';
|
||||
return (str);
|
||||
}
|
||||
|
||||
void *ft_calloc(size_t ct, size_t size)
|
||||
{
|
||||
char *str;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (size == 0 || ct == 0)
|
||||
return (malloc(1));
|
||||
if ((int)size < 0 && (int)ct < 0)
|
||||
return (NULL);
|
||||
if ((unsigned long long)(size * ct) > 4294967295)
|
||||
return (NULL);
|
||||
str = malloc(size * ct);
|
||||
if (!str)
|
||||
return (NULL);
|
||||
while (i < (ct * size))
|
||||
{
|
||||
*(unsigned char *)(str + i) = '\0';
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/01 17:11:59 by adjoly #+# #+# */
|
||||
/* Updated: 2023/12/08 18:17:17 by adjoly ### ########.fr */
|
||||
/* Updated: 2023/12/14 11:52:20 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/01 17:11:59 by adjoly #+# #+# */
|
||||
/* Updated: 2023/12/08 18:02:13 by adjoly ### ########.fr */
|
||||
/* Updated: 2023/12/14 11:57:16 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -41,20 +41,20 @@ char *get_next_line(int fd)
|
||||
{
|
||||
static char *buf[1024];
|
||||
char *res;
|
||||
size_t bytes_read;
|
||||
ssize_t bytes_read;
|
||||
|
||||
res = ft_calloc(1, 1);
|
||||
if (!buf[fd])
|
||||
buf[fd] = ft_calloc(sizeof(char), BUFFER_SIZE + 1);
|
||||
while (buf[fd] && res)
|
||||
{
|
||||
res = ft_strjoin(res, buf);
|
||||
res = ft_strjoin(res, buf[fd]);
|
||||
if (check_line(res, buf[fd]))
|
||||
return (res);
|
||||
bytes_read = read(fd, buf[fd], BUFFER_SIZE);
|
||||
if (bytes_read < 1)
|
||||
{
|
||||
free(&buf[fd]);
|
||||
free(buf[fd]);
|
||||
buf[fd] = NULL;
|
||||
if (res[0] != 0)
|
||||
return (res);
|
||||
|
Reference in New Issue
Block a user