From 872595f75baec6ebd704d5725504dcd836f0b0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 15 Oct 2024 11:19:02 +0200 Subject: [PATCH] ft_memset: initial implementation --- Makefile | 5 +++-- ft_memset.c | 26 ++++++++++++++++++++++++++ libft.h | 4 +++- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 ft_memset.c diff --git a/Makefile b/Makefile index 131260e..1f4f1fd 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: kcolin +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/10/14 13:43:59 by kcolin #+# #+# # -# Updated: 2024/10/14 15:11:56 by kcolin ### ########.fr # +# Updated: 2024/10/15 10:49:47 by kcolin ### ########.fr # # # # **************************************************************************** # @@ -17,7 +17,8 @@ SOURCES = ft_isalpha.c \ ft_isalnum.c \ ft_isascii.c \ ft_isprint.c \ - ft_strlen.c + ft_strlen.c \ + ft_memset.c OBJECTS = $(SOURCES:.c=.o) CC = gcc diff --git a/ft_memset.c b/ft_memset.c new file mode 100644 index 0000000..59479c0 --- /dev/null +++ b/ft_memset.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: kcolin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/15 10:46:44 by kcolin #+# #+# */ +/* Updated: 2024/10/15 10:58:03 by kcolin ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memset(void *dest, int c, t_size len) +{ + t_size i; + + i = 0; + while (i < len) + { + *((unsigned char *)dest + i) = (unsigned char)c; + i++; + } + return (dest); +} diff --git a/libft.h b/libft.h index 652605d..c16fbae 100644 --- a/libft.h +++ b/libft.h @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/15 10:11:54 by kcolin #+# #+# */ -/* Updated: 2024/10/15 10:40:58 by kcolin ### ########.fr */ +/* Updated: 2024/10/15 10:46:35 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,4 +23,6 @@ int ft_isprint(int c); t_size ft_strlen(const char *s); +void *ft_memset(void *dest, int c, t_size len); + #endif