1
0
mirror of https://github.com/KeyZox71/ft_minipowershell.git synced 2025-05-14 00:08:47 +02:00

🔨」 fix(libft): replaced libft by a better one :D

This commit is contained in:
y-syo
2024-04-29 13:53:00 +02:00
parent 77786466e3
commit 73bb992b01
77 changed files with 1511 additions and 1320 deletions

18
libft/src/mem/ft_bzero.c Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 22:00:28 by mmoussou #+# #+# */
/* Updated: 2023/11/01 22:00:32 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
ft_memset(s, 0, n);
}

30
libft/src/mem/ft_calloc.c Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 21:55:05 by mmoussou #+# #+# */
/* Updated: 2023/11/06 13:58:47 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t n, size_t elsize)
{
void *t;
size_t size;
if (n <= 0 || elsize <= 0)
return (malloc(0));
if ((elsize * n / n) != elsize)
return (NULL);
size = n * elsize;
t = malloc(size);
if (!t)
return (NULL);
ft_bzero(t, size);
return (t);
}

72
libft/src/mem/ft_free.c Normal file
View File

@ -0,0 +1,72 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 19:27:31 by mmoussou #+# #+# */
/* Updated: 2024/01/18 01:05:44 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void free_str(char **str)
{
free(*str);
*str = NULL;
}
void free_stack(t_stack **stack)
{
if (*stack && (*stack)->next)
free_stack(&(*stack)->next);
free(*stack);
*stack = NULL;
}
void free_list(t_list **lst)
{
if (*lst && (*lst)->next)
free_list(&(*lst)->next);
free(*lst);
*lst = NULL;
}
void free_tab(char ***arr)
{
int i;
i = 0;
while ((*arr)[i])
{
free((*arr)[i]);
i++;
}
free(*arr);
*arr = NULL;
}
void ft_free(const char *str, ...)
{
va_list args;
size_t i;
if (!str)
return ;
va_start(args, str);
i = 0;
while (str[i])
{
if (str[i] == 'c')
free_str(va_arg(args, char **));
if (str[i] == 's')
free_stack(va_arg(args, t_stack **));
if (str[i] == 'l')
free_list(va_arg(args, t_list **));
if (str[i] == 'a')
free_tab(va_arg(args, char ***));
i++;
}
}

31
libft/src/mem/ft_memchr.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 21:52:59 by mmoussou #+# #+# */
/* Updated: 2023/11/10 17:01:28 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
if (!s || !n)
return (NULL);
i = 0;
while (i < n)
{
if (((unsigned char *)s)[i] == (unsigned char)c)
return ((void *)s + i);
i++;
}
if ((unsigned char)c == 0)
return ((void *)s + i);
return (NULL);
}

33
libft/src/mem/ft_memcmp.c Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 21:57:12 by mmoussou #+# #+# */
/* Updated: 2023/11/13 19:47:03 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned char *ptr1;
unsigned char *ptr2;
size_t i;
i = 0;
if (!n)
return (0);
ptr1 = (unsigned char *) s1;
ptr2 = (unsigned char *) s2;
while (i < (n - 1) && *ptr1 == *ptr2)
{
ptr1++;
ptr2++;
i++;
}
return (*ptr1 - *ptr2);
}

33
libft/src/mem/ft_memcpy.c Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 22:02:34 by mmoussou #+# #+# */
/* Updated: 2023/11/01 22:08:52 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memcpy(void *dst, const void *src, size_t n)
{
char *ptr1;
char *ptr2;
size_t i;
i = 0;
if (dst && src)
{
ptr1 = (char *)dst;
ptr2 = (char *)src;
while (i < n)
{
ptr1[i] = ptr2[i];
i++;
}
}
return (dst);
}

View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 21:58:13 by mmoussou #+# #+# */
/* Updated: 2023/11/11 11:43:35 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dst, const void *src, size_t n)
{
char *ptr1;
char *ptr2;
size_t i;
i = 0;
if (dst && src)
{
ptr1 = (char *)dst;
ptr2 = (char *)src;
if (ptr1 > ptr2)
while (n--)
ptr1[n] = ptr2[n];
else
{
while (i < n)
{
ptr1[i] = ptr2[i];
i++;
}
}
}
return (dst);
}

31
libft/src/mem/ft_memset.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 22:03:03 by mmoussou #+# #+# */
/* Updated: 2023/11/01 22:03:04 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memset(void *s, int c, size_t n)
{
char *ptr;
size_t i;
i = 0;
if (s)
{
ptr = (char *)s;
while (i < n)
{
ptr[i] = c;
i++;
}
}
return (s);
}