base struct
This commit is contained in:
26
lib/libft/srcs/mem/ft_bzero.c
Normal file
26
lib/libft/srcs/mem/ft_bzero.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/10 16:07:05 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:14:55 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
char *ps;
|
||||
size_t i;
|
||||
|
||||
if (n == 0 || !s)
|
||||
return ;
|
||||
ps = (char *)s;
|
||||
i = 0;
|
||||
while (i < n)
|
||||
ps[i++] = 0;
|
||||
}
|
||||
26
lib/libft/srcs/mem/ft_memchr.c
Normal file
26
lib/libft/srcs/mem/ft_memchr.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/14 11:38:35 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:14:59 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
char *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
const unsigned char *ps;
|
||||
|
||||
ps = (const unsigned char *)s;
|
||||
i = -1;
|
||||
while (++i < n)
|
||||
if (ps[i] == (unsigned char)c)
|
||||
return ((char *)&ps[i]);
|
||||
return (NULL);
|
||||
}
|
||||
28
lib/libft/srcs/mem/ft_memcmp.c
Normal file
28
lib/libft/srcs/mem/ft_memcmp.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/14 11:54:32 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:15:04 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
const unsigned char *ps1;
|
||||
const unsigned char *ps2;
|
||||
|
||||
ps1 = (const unsigned char *)s1;
|
||||
ps2 = (const unsigned char *)s2;
|
||||
i = -1;
|
||||
while (++i < n)
|
||||
if (ps1[i] != ps2[i])
|
||||
return (ps1[i] - ps2[i]);
|
||||
return (0);
|
||||
}
|
||||
29
lib/libft/srcs/mem/ft_memcpy.c
Normal file
29
lib/libft/srcs/mem/ft_memcpy.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/11 09:21:39 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:15:09 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
{
|
||||
unsigned char *pdst;
|
||||
const unsigned char *psrc;
|
||||
size_t i;
|
||||
|
||||
if (!dst && !src)
|
||||
return (0);
|
||||
pdst = (unsigned char *)dst;
|
||||
psrc = (const unsigned char *)src;
|
||||
i = -1;
|
||||
while (++i < n)
|
||||
pdst[i] = psrc[i];
|
||||
return (dst);
|
||||
}
|
||||
37
lib/libft/srcs/mem/ft_memmove.c
Normal file
37
lib/libft/srcs/mem/ft_memmove.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/12 09:37:46 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:15:14 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
void *ft_memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
unsigned char *pdst;
|
||||
const unsigned char *psrc;
|
||||
|
||||
if (!dest && !src)
|
||||
return (0);
|
||||
pdst = (unsigned char *)dest;
|
||||
psrc = (const unsigned char *)src;
|
||||
if (pdst < psrc)
|
||||
{
|
||||
while (n--)
|
||||
*pdst++ = *psrc++;
|
||||
}
|
||||
else
|
||||
{
|
||||
pdst += n;
|
||||
psrc += n;
|
||||
while (n--)
|
||||
*(--pdst) = *(--psrc);
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
28
lib/libft/srcs/mem/ft_memset.c
Normal file
28
lib/libft/srcs/mem/ft_memset.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/10 13:06:54 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:15:21 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
void *ft_memset(void *b, int c, size_t len)
|
||||
{
|
||||
unsigned char *ptr;
|
||||
size_t i;
|
||||
|
||||
ptr = (unsigned char *)b;
|
||||
i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
ptr[i] = c;
|
||||
i++;
|
||||
}
|
||||
return (b);
|
||||
}
|
||||
Reference in New Issue
Block a user