A lot of edit but adding the struct (Yes, i just use parameters of the function util now, See u morrow)

This commit is contained in:
Raphaël 2024-04-01 01:55:59 +02:00
parent 9c4dfafdf7
commit 56655f5426
15 changed files with 403 additions and 30 deletions

18
libft/ft_bzero.c Normal file
View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:43:13 by rparodi #+# #+# */
/* Updated: 2024/03/31 22:29:48 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
void ft_bzero(void *s, t_usize n)
{
ft_memset(s, 0, n);
}

31
libft/ft_calloc.c Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:47:17 by rparodi #+# #+# */
/* Updated: 2024/03/31 22:32:48 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
void *ft_calloc(t_usize nmemb, t_usize size)
{
t_usize total;
t_str to_return;
if (nmemb == 0 || size == 0)
return ((void *)malloc(1));
total = nmemb * size;
if (total / nmemb != size && total / size != nmemb)
return (NULL);
to_return = (char *)malloc(total);
if (to_return == NULL)
to_return = NULL;
else
ft_bzero(to_return, total);
return (to_return);
}

28
libft/ft_memset.c Normal file
View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:50:29 by rparodi #+# #+# */
/* Updated: 2024/03/31 22:32:32 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
void *ft_memset(void *s, t_i32 c, t_usize n)
{
t_str str;
t_usize i;
i = 0;
str = (t_str)s;
while (i < n)
{
str[i] = c;
i++;
}
return (str);
}

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:56:56 by rparodi #+# #+# */
/* Updated: 2024/03/31 19:51:17 by rparodi ### ########.fr */
/* Updated: 2024/03/31 21:57:48 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,7 +20,7 @@ int ft_strcmp(const char *s1, const char *s2)
i = 0;
while ((s1[i] || s2[i]))
{
if (s1[i] != s2[i])
if (s1[i] != s2[i] && s1 && s2)
{
diff = (unsigned char)s1[i] - (unsigned char)s2[i];
return (diff);

26
libft/ft_strdup.c Normal file
View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:53:59 by rparodi #+# #+# */
/* Updated: 2024/04/01 01:41:35 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
t_str ft_strdup(t_const_str s)
{
t_usize len;
t_str to_return;
len = ft_strlen(s) + 1;
to_return = (t_str)malloc(sizeof(t_i8) * len);
if (!to_return)
return (NULL);
ft_strlcpy(to_return, s, len);
return (to_return);
}

31
libft/ft_strlcpy.c Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:55:25 by rparodi #+# #+# */
/* Updated: 2024/04/01 01:38:28 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
t_usize ft_strlcpy(t_str dst, t_const_str src, t_usize size)
{
t_usize i;
i = 0;
while (src[i] && i + 1 < size)
{
dst[i] = src[i];
i++;
}
if (size > 0)
{
dst[i] = '\0';
i++;
}
return (ft_strlen(src));
}

23
libft/ft_strlen.c Normal file
View file

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:56:24 by rparodi #+# #+# */
/* Updated: 2024/04/01 01:37:04 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
size_t ft_strlen(t_const_str s)
{
t_usize i;
i = 0;
while (s[i] != '\0')
i++;
return (i);
}