76 lines
1.7 KiB
C
76 lines
1.7 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* get_next_line_utils_bonus.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/11/07 17:19:41 by erey-bet #+# #+# */
|
|
/* Updated: 2022/11/15 19:57:30 by erey-bet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "get_next_line.h"
|
|
|
|
void *ft_calloc(size_t nitems, size_t size)
|
|
{
|
|
size_t i;
|
|
char *tmp;
|
|
|
|
if (nitems == 0 || size == 0)
|
|
return (malloc(0));
|
|
if (nitems * size < nitems)
|
|
return (NULL);
|
|
tmp = malloc(nitems * size);
|
|
if (tmp == NULL)
|
|
return (NULL);
|
|
i = 0;
|
|
while (i < nitems * size)
|
|
{
|
|
tmp[i] = '\0';
|
|
i++;
|
|
}
|
|
return (tmp);
|
|
}
|
|
|
|
size_t ft_strlen(const char *str)
|
|
{
|
|
int i;
|
|
|
|
if (str == NULL)
|
|
return (0);
|
|
i = 0;
|
|
while (str[i] != '\0')
|
|
i++;
|
|
return (i);
|
|
}
|
|
|
|
int ft_strchr(const char *str, int search)
|
|
{
|
|
int i;
|
|
|
|
i = 0;
|
|
while (str[i] || str[i] == (unsigned char)search)
|
|
{
|
|
if (str[i] == (unsigned char)search)
|
|
return (i);
|
|
i++;
|
|
}
|
|
return (-1);
|
|
}
|
|
|
|
void ft_strlcpy(char *dest, const char *src, size_t size)
|
|
{
|
|
size_t i;
|
|
|
|
i = 0;
|
|
if (!size || !dest || !src)
|
|
return ;
|
|
while (i < size - 1 && src[i] != '\0')
|
|
{
|
|
dest[i] = src[i];
|
|
i++;
|
|
}
|
|
dest[i] = '\0';
|
|
}
|