1
0
This commit is contained in:
2023-12-06 11:45:25 +01:00
parent 1946d4bc41
commit e2c6462e90
4 changed files with 26 additions and 13 deletions

BIN
a.out Executable file

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/04 18:44:34 by adjoly ### ########.fr */
/* Updated: 2023/12/06 11:18:18 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -34,17 +34,9 @@ char *get_next_line(int fd)
if (BUFFER_SIZE <= 0 || fd < 0)
return (NULL);
res = malloc(1);
if (!res)
return (NULL);
res[0] = '\0';
res = ft_calloc(1, 1);
if (!buf)
{
buf = malloc((BUFFER_SIZE + 1) * sizeof(char));
if (!buf)
return (NULL);
buf[0] = '\0';
}
buf = ft_calloc(sizeof(char), BUFFER_SIZE + 1);
while (1)
{
tmp = ft_strjoin(res, buf);

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 17:12:00 by adjoly #+# #+# */
/* Updated: 2023/12/04 18:38:21 by adjoly ### ########.fr */
/* Updated: 2023/12/06 11:16:29 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,6 +24,7 @@ char *get_next_line(int fd);
char *ft_strjoin(char *s1, char *s2);
size_t ft_strlen_til_nl(char *s);
size_t ft_strlen(char *s);
void *ft_calloc(size_t nmemb, size_t size);
size_t ft_strlcpy(char *dst, char *src, size_t size);
#endif

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 17:12:02 by adjoly #+# #+# */
/* Updated: 2023/12/04 18:42:35 by adjoly ### ########.fr */
/* Updated: 2023/12/06 11:21:57 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -78,3 +78,23 @@ size_t ft_strlcpy(char *dst, char *src, size_t size)
dst[i] = '\0';
return (ft_strlen(src));
}
void *ft_calloc(size_t nmemb, size_t size)
{
size_t i;
void *result;
if (size != 0 && nmemb != 0 && (nmemb * size) / nmemb != size)
return (NULL);
if (nmemb == 0 || size == 0)
return (malloc(1));
result = malloc(size * nmemb);
if (result == NULL)
return (NULL);
while (i < size * nmemb)
{
*(unsigned char *)(result + i) = '\0';
i++;
}
return (result);
}