Started from buttom go to the sky

This commit is contained in:
Raphaël 2024-04-28 19:59:01 +02:00
parent 96215449bd
commit f811e55dea
4781 changed files with 10121 additions and 1743 deletions

26
stdme/src/mem/mem_alloc.c Normal file
View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_alloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/06 14:47:49 by maiboyer #+# #+# */
/* Updated: 2023/12/09 18:14:11 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem_alloc.h"
#include <stdlib.h>
void *mem_alloc(t_usize size)
{
void *out;
size_t i;
i = 0;
out = malloc(size);
while (out && i < size)
((t_u8 *)out)[i++] = 0;
return (out);
}

View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_alloc_array.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 15:53:21 by maiboyer #+# #+# */
/* Updated: 2023/12/09 18:14:47 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem_alloc.h"
#include "me/mem/mem_alloc_array.h"
#include <stdlib.h>
void *mem_alloc_array(t_usize item_count, t_usize item_size)
{
t_usize multiplied;
multiplied = item_count * item_size;
if (multiplied == 0 || multiplied / item_count != item_size)
return (NULL);
return (mem_alloc(multiplied));
}

View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_compare.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
/* Updated: 2023/12/09 15:00:58 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem_compare.h"
t_i32 mem_compare(const void *lhs, const void *rhs, t_usize count)
{
t_usize i;
t_u8 *lhs_;
t_u8 *rhs_;
i = 0;
lhs_ = (t_u8 *)lhs;
rhs_ = (t_u8 *)rhs;
while (i < count)
{
if (lhs_[i] - rhs_[i])
return ((t_i32)(lhs_[i] - rhs_[i]));
i++;
}
return (0);
}

32
stdme/src/mem/mem_copy.c Normal file
View file

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_copy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
/* Updated: 2023/12/09 15:01:08 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem_copy.h"
void *mem_copy(void *destination, const void *source, t_usize count)
{
t_usize i;
t_u8 *dst;
t_u8 *src;
i = 0;
dst = (t_u8 *)destination;
src = (t_u8 *)source;
if (dst == src)
return (destination);
while (i < count)
{
dst[i] = src[i];
i++;
}
return (destination);
}

29
stdme/src/mem/mem_find.c Normal file
View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_find.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
/* Updated: 2023/12/09 15:01:36 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem_find.h"
void *mem_find(void *buf, t_u8 find, t_usize count)
{
t_usize i;
t_u8 *buf_bytes;
i = 0;
buf_bytes = (t_u8 *)buf;
while (i < count)
{
if (buf_bytes[i] == find)
return ((void *)&buf_bytes[i]);
i++;
}
return (NULL);
}

View file

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_find_bytes.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
/* Updated: 2024/01/06 17:14:23 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem_find_bytes.h"
#include "stdio.h"
void *mem_find_bytes(void *buf, t_u8 *find, t_usize find_len, t_usize count)
{
t_usize i;
t_usize j;
t_u8 *buf_bytes;
i = 0;
buf_bytes = (t_u8 *)buf;
while (i < count)
{
j = 0;
while (j < find_len && i + j < count)
{
if (buf_bytes[i + j] != find[j])
break ;
j++;
}
if (j == find_len)
return ((void *)&buf_bytes[i]);
i++;
}
return (NULL);
}

42
stdme/src/mem/mem_move.c Normal file
View file

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_move.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
/* Updated: 2023/12/09 15:01:43 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem_move.h"
void *mem_move(void *destination, const void *source, t_usize count)
{
t_usize i;
t_u8 *dst;
t_u8 *src;
i = 0;
dst = (t_u8 *)destination;
src = (t_u8 *)source;
if (dst < src)
{
while (i < count)
{
dst[i] = src[i];
i++;
}
}
else if (dst > src)
{
i = count;
while (i > 0)
{
i--;
dst[i] = src[i];
}
}
return (destination);
}

27
stdme/src/mem/mem_set.c Normal file
View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_set.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
/* Updated: 2023/12/09 18:15:22 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem_set.h"
void mem_set(void *buf, t_u8 fill_by, t_usize count)
{
t_usize i;
t_u8 *buf_bytes;
i = 0;
buf_bytes = (t_u8 *)buf;
while (i < count)
{
buf_bytes[i] = fill_by;
i++;
}
}

View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_set_zero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:58:11 by maiboyer #+# #+# */
/* Updated: 2023/12/09 15:01:57 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem_set_zero.h"
void mem_set_zero(void *buf, t_usize count)
{
t_u8 *buffer;
t_usize index;
index = 0;
buffer = (t_u8 *)buf;
while (index < count)
{
buffer[index] = 0;
index++;
}
}