Archived
1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
FDF/get_next_line/get_next_line_utils.c

77 lines
1.8 KiB
C
Raw Normal View History

2023-12-12 13:28:15 +01:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 17:12:02 by adjoly #+# #+# */
2024-01-04 16:36:32 +01:00
/* Updated: 2024/01/04 00:47:44 by adjoly ### ########.fr */
2023-12-12 13:28:15 +01:00
/* */
/* ************************************************************************** */
#include "get_next_line.h"
2023-12-23 09:25:01 +01:00
#include "../libft/libft.h"
2023-12-12 13:28:15 +01:00
2024-01-04 16:36:32 +01:00
// size_t ft_strlen_gnl(char *s)
2023-12-23 09:25:01 +01:00
// {
// size_t i;
2024-01-04 16:36:32 +01:00
2023-12-23 09:25:01 +01:00
// i = 0;
// while (s[i])
// i++;
// return (i);
// }
2023-12-12 13:28:15 +01:00
2024-01-04 16:36:32 +01:00
char *ft_strjoin_gnl(char *s1, char *s2)
2023-12-12 13:28:15 +01:00
{
char *result;
size_t i;
size_t j;
i = 0;
j = 0;
if (!s2)
return (NULL);
2024-01-04 16:36:32 +01:00
result = ft_calloc_gnl((ft_strlen(s1) + ft_strlen(s2) + 1), 1);
2023-12-12 13:28:15 +01:00
if (result == NULL)
return (NULL);
while (s1[i])
{
result[i] = s1[i];
i++;
}
while (s2[j])
{
result[i] = s2[j];
i++;
j++;
}
free(s1);
result[i] = '\0';
return (result);
}
2024-01-04 16:36:32 +01:00
void *ft_calloc_gnl(size_t nmemb, size_t size)
2023-12-12 13:28:15 +01:00
{
2023-12-18 17:19:34 +01:00
char *result;
2023-12-12 13:28:15 +01:00
size_t i;
i = 0;
if (nmemb == 0 || size == 0)
return (malloc(1));
2023-12-18 17:19:34 +01:00
if (((unsigned long long)(size * nmemb) > 4294967295))
2023-12-12 13:28:15 +01:00
return (NULL);
2023-12-18 17:19:34 +01:00
if ((int)size < 0 && (int)nmemb < 0)
2023-12-12 13:28:15 +01:00
return (NULL);
2023-12-18 17:19:34 +01:00
result = malloc(size * nmemb);
if (!result)
2023-12-12 13:28:15 +01:00
return (NULL);
2023-12-18 17:19:34 +01:00
while (i < (size * nmemb))
2023-12-12 13:28:15 +01:00
{
2023-12-18 17:19:34 +01:00
*(unsigned char *)(result + i) = '\0';
2023-12-12 13:28:15 +01:00
i++;
}
2023-12-18 17:19:34 +01:00
return (result);
2023-12-12 13:28:15 +01:00
}