81 lines
1.0 KiB
C
81 lines
1.0 KiB
C
|
#include "get_next_line.h"
|
||
|
|
||
|
void *ft_calloc(size_t nmemb, size_t size)
|
||
|
{
|
||
|
char *tab;
|
||
|
size_t i;
|
||
|
|
||
|
if (nmemb == 0 || size * nmemb / nmemb != size)
|
||
|
return (NULL);
|
||
|
tab = malloc(nmemb * size);
|
||
|
if (tab == NULL)
|
||
|
return (NULL);
|
||
|
i = 0;
|
||
|
while (i < size * nmemb)
|
||
|
{
|
||
|
tab[i] = 0;
|
||
|
i++;
|
||
|
}
|
||
|
return ((void *) tab);
|
||
|
}
|
||
|
|
||
|
void *ft_realloc(void *ptr, size_t size)
|
||
|
{
|
||
|
char *tab;
|
||
|
char *in;
|
||
|
size_t i;
|
||
|
|
||
|
in = ptr;
|
||
|
tab = ft_calloc(1, size);
|
||
|
if (tab == NULL)
|
||
|
return (NULL);
|
||
|
if (ptr == NULL)
|
||
|
return (tab);
|
||
|
i = 0;
|
||
|
while (in[i] != 0 && i < size)
|
||
|
{
|
||
|
tab[i] = in[i];
|
||
|
i++;
|
||
|
}
|
||
|
free(ptr);
|
||
|
return (tab);
|
||
|
}
|
||
|
|
||
|
char *ft_strcat(char *dst, char *src)
|
||
|
{
|
||
|
size_t i;
|
||
|
size_t j;
|
||
|
|
||
|
j = 0;
|
||
|
while (dst[j] != '\0')
|
||
|
j++;
|
||
|
i = 0;
|
||
|
if (src != NULL)
|
||
|
{
|
||
|
while (src[i] != '\0')
|
||
|
{
|
||
|
dst[i + j] = src[i];
|
||
|
i++;
|
||
|
}
|
||
|
}
|
||
|
dst[i] = '\0';
|
||
|
return (dst);
|
||
|
}
|
||
|
|
||
|
char *ft_strndup(char *src, size_t n)
|
||
|
{
|
||
|
char *out;
|
||
|
size_t i;
|
||
|
|
||
|
out = ft_calloc(n + 1, sizeof(char));
|
||
|
if (out == NULL)
|
||
|
return (NULL);
|
||
|
i = 0;
|
||
|
while (src[i] != '\0' && i < n)
|
||
|
{
|
||
|
out[i] = src[i];
|
||
|
i++;
|
||
|
}
|
||
|
return (out);
|
||
|
}
|