So long...
This commit is contained in:
89
get_next_line/get_next_line_utils.c
Executable file
89
get_next_line/get_next_line_utils.c
Executable file
@@ -0,0 +1,89 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/23 12:07:48 by aortigos #+# #+# */
|
||||
/* Updated: 2025/02/15 09:55:55 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "get_next_line.h"
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
char *str;
|
||||
size_t i;
|
||||
|
||||
str = (char *)s;
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
str[i] = '\0';
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void *ft_calloc(size_t n, size_t size)
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
ptr = malloc(n * size);
|
||||
if (!ptr)
|
||||
return (NULL);
|
||||
ft_bzero(ptr, n * size);
|
||||
return (ptr);
|
||||
}
|
||||
|
||||
size_t ft_strlen(const char *str)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = (char *)s;
|
||||
while (*str != c && *str != 0)
|
||||
str++;
|
||||
if (*str == c)
|
||||
return (str);
|
||||
else
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
char *new;
|
||||
int i;
|
||||
int len1;
|
||||
int len2;
|
||||
|
||||
len1 = ft_strlen(s1);
|
||||
len2 = ft_strlen(s2);
|
||||
new = (char *)malloc(sizeof(char) * (len1 + len2 + 1));
|
||||
if (!new || !s1 || !s2)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (s1[i] != 0)
|
||||
{
|
||||
new[i] = s1[i];
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while (s2[i] != 0)
|
||||
{
|
||||
new[len1 + i] = s2[i];
|
||||
i++;
|
||||
}
|
||||
new[len1 + len2] = '\0';
|
||||
return (new);
|
||||
}
|
||||
Reference in New Issue
Block a user