From eaa1afda5f0ffd05d50678e3ecddb5c2ce67712f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gu=C3=A9len?= Date: Fri, 14 Feb 2025 18:24:46 +0100 Subject: [PATCH] WIP: internal environment manipulation Added a function to join two strings putting a separator in between. (Predicted useful for PATH manipulation and general translation of internal structure back to char ** form) --- libft/libft.h | 1 + libft/libft/Makefile | 2 +- libft/libft/ft_strjoin_sepc.c | 29 +++++++++++++++++++++++++++++ libft/libft/libft.h | 1 + 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 libft/libft/ft_strjoin_sepc.c diff --git a/libft/libft.h b/libft/libft.h index 79e36dd..027a2e7 100644 --- a/libft/libft.h +++ b/libft/libft.h @@ -153,6 +153,7 @@ int max_int(int a, int b); int min_int(int a, int b); long max_long(long a, long b); long min_long(long a, long b); +char *ft_strjoin_sepc(char *s1, char *s2, char sep); /*BONUSLIBFT*/ t_list *ft_lstnew(void *content); void ft_lstadd_front(t_list **lst, t_list *new); diff --git a/libft/libft/Makefile b/libft/libft/Makefile index 4d12ce8..cf86ed9 100644 --- a/libft/libft/Makefile +++ b/libft/libft/Makefile @@ -10,7 +10,7 @@ SOURCES = ft_atoi.c ft_itoa.c ft_putendl_fd.c ft_strlcat.c ft_substr.c \ ft_memcmp.c ft_split.c ft_strmapi.c ft_isalpha.c ft_memcpy.c ft_strchr.c \ ft_strncmp.c ft_isascii.c ft_memmove.c ft_strdup.c ft_strnstr.c \ ft_isdigit.c ft_memset.c ft_striteri.c ft_strrchr.c ft_isprint.c \ - ft_putchar_fd.c ft_strjoin.c ft_strtrim.c ft_min_max.c + ft_putchar_fd.c ft_strjoin.c ft_strtrim.c ft_min_max.c ft_strjoin_sepc.c BONUSSOURCES = ft_lstnew_bonus.c ft_lstadd_back_bonus.c ft_lstsize_bonus.c \ ft_lstadd_front_bonus.c ft_lstclear_bonus.c ft_lstdelone_bonus.c \ ft_lstiter_bonus.c ft_lstlast_bonus.c ft_lstmap_bonus.c diff --git a/libft/libft/ft_strjoin_sepc.c b/libft/libft/ft_strjoin_sepc.c new file mode 100644 index 0000000..bdc2115 --- /dev/null +++ b/libft/libft/ft_strjoin_sepc.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin_sepc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jguelen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/14 18:08:52 by jguelen #+# #+# */ +/* Updated: 2025/02/14 18:15:28 by jguelen ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strjoin_sepc(char *s1, char *s2, char sep) +{ + char *new; + size_t len1; + size_t len2; + + len1 = ft_strlen(s1); + len2 = ft_strlen(s2); + new = malloc((len1 + len2 + 2) * sizeof(char)); + ft_memmove(new, s1, len1); + new[len1] = sep; + ft_memmove(new + len1 + 1, s2, len2); + new[len1 + len2 + 1] = '\0'; + return (new); +} diff --git a/libft/libft/libft.h b/libft/libft/libft.h index 06c53fe..dd39740 100644 --- a/libft/libft/libft.h +++ b/libft/libft/libft.h @@ -63,6 +63,7 @@ int max_int(int a, int b); int min_int(int a, int b); long max_long(long a, long b); long min_long(long a, long b); +char *ft_strjoin_sepc(char *s1, char *s2, char sep); /*BONUS*/ t_list *ft_lstnew(void *content); void ft_lstadd_front(t_list **lst, t_list *new);