Archived
1
0

libft reformat

This commit is contained in:
Adam Joly
2024-02-04 15:11:02 +01:00
parent 6486eb4b3f
commit 45b737cf5f
64 changed files with 730 additions and 205 deletions

18
mem/ft_bzero.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 11:58:03 by adjoly #+# #+# */
/* Updated: 2024/02/04 13:55:51 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void ft_bzero(void *s, size_t n)
{
ft_memset(s, '\0', n);
}

36
mem/ft_calloc.c Normal file
View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 16:02:26 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:22:20 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
char *result;
size_t i;
i = 0;
if (nmemb == 0 || size == 0)
return (malloc(1));
if (((unsigned long long)(size * nmemb) > 4294967295))
return (NULL);
if ((int)size < 0 && (int)nmemb < 0)
return (NULL);
result = malloc(size * nmemb);
if (!result)
return (NULL);
while (i < (size * nmemb))
{
*(unsigned char *)(result + i) = '\0';
i++;
}
return (result);
}

27
mem/ft_memchr.c Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 14:52:53 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:36:28 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
i = 0;
while (i < n)
{
if (((unsigned char *)s)[i] == (unsigned char)c)
return (((void *)s + i));
i++;
}
return (NULL);
}

25
mem/ft_memcmp.c Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/08 12:04:48 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:36:46 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
i = 0;
if (n == 0)
return (0);
while (((unsigned char *)s1)[i] == ((unsigned char *)s2)[i] && i < n - 1)
i++;
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
}

30
mem/ft_memcpy.c Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/02 10:21:55 by adjoly #+# #+# */
/* Updated: 2024/02/04 15:00:19 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void *ft_memcpy(void *dest, const void *src, size_t n)
{
size_t i;
i = 0;
if (!src && !dest)
{
return (dest);
}
while (i < n)
{
((unsigned char *)dest)[i] = ((unsigned char *)src)[i];
i++;
}
return (dest);
}

27
mem/ft_memmove.c Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 15:04:04 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:38:10 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void *ft_memmove(void *dest, const void *src, size_t n)
{
size_t i;
i = -1;
if (dest > src)
while (n-- > 0)
((unsigned char *)dest)[n] = ((unsigned char *)src)[n];
else if (dest < src)
while (++i < n)
((unsigned char *)dest)[i] = ((unsigned char *)src)[i];
return (dest);
}

26
mem/ft_memset.c Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 17:40:22 by adjoly #+# #+# */
/* Updated: 2024/02/04 14:37:55 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
void *ft_memset(void *s, int c, size_t n)
{
size_t i;
i = 0;
while (i < n)
{
((char *)(s))[i] = c;
i++;
}
return (s);
}