1
0

day finished

This commit is contained in:
Adam Joly
2023-11-04 18:37:19 +01:00
parent f10ad6adac
commit e2bc65f049
9 changed files with 72 additions and 13 deletions

View File

@ -6,7 +6,7 @@
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
# Updated: 2023/11/03 23:05:37 by adjoly ### ########.fr #
# Updated: 2023/11/04 15:37:27 by adjoly ### ########.fr #
# #
# **************************************************************************** #
@ -31,6 +31,8 @@ SRCS = ft_atoi.c \
ft_substr.c \
ft_tolower.c \
ft_toupper.c \
ft_strlcat.c \
ft_strjoin.c \
OBJS = $(SRCS:.c=.o)
@ -41,6 +43,10 @@ HEADER = libft.h
$(NAME): $(OBJS)
ar -rcs $(NAME) $(OBJS)
so:
$(CC) -nostartfiles -fPIC $(CFLAGS) $(SRCS)
gcc -nostartfiles -shared -o libft.so $(OBJS)
%.o: %.c
$(CC) $(FLAGS) -I $(HEADER) $< -c -o $@

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/02 10:21:55 by adjoly #+# #+# */
/* Updated: 2023/11/02 11:30:30 by adjoly ### ########.fr */
/* Updated: 2023/11/04 14:13:12 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,7 +17,7 @@ void *ft_memcpy(void *dest, const void *src, size_t n)
size_t i;
i = 0;
if (src == NULL || dest == NULL || n == 0)
if (src == NULL && dest == NULL)
{
return (dest);
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 15:45:18 by adjoly #+# #+# */
/* Updated: 2023/11/02 10:08:05 by adjoly ### ########.fr */
/* Updated: 2023/11/04 15:32:14 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,7 +15,7 @@ char *ft_strchr(const char *s, int c)
int i;
int j;
char *str_result;
// initialize str_result
i = 0;
j = 0;
while (s[i] != c || s[i])
@ -29,6 +29,6 @@ char *ft_strchr(const char *s, int c)
}
return (str_result);
}
str_result[0] = '\0';
str_result[i] = '\0';
return (str_result);
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 22:57:39 by adjoly #+# #+# */
/* Updated: 2023/11/04 11:10:30 by adjoly ### ########.fr */
/* Updated: 2023/11/04 14:40:17 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */

31
ft_strjoin.c Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 13:44:09 by adjoly #+# #+# */
/* Updated: 2023/11/04 14:06:43 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
int i;
char *result;
size_t len_s1;
size_t len_s2;
i = 0;
len_s1 = ft_strlen(s1);
len_s2 = ft_strlen(s2);
result = malloc(len_s1 + len_s2 + 1);
if (result == NULL)
return (NULL);
ft_memcpy(result, s1, len_s1);
ft_memcpy(result + len_s1, s2, len_s2);
return (result);
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 15:59:31 by adjoly #+# #+# */
/* Updated: 2023/11/03 17:12:22 by adjoly ### ########.fr */
/* Updated: 2023/11/04 16:14:32 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,5 +14,25 @@
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t i;
size_t j;
size_t len_dst;
size_t len_src;
if (dst == NULL && size == 0)
return (0);
i = 0;
j = ft_strlen(dst);
len_src = ft_strlen(src);
len_dst = ft_strlen(dst);
if (size <= j)
return (len_src + size);
while (j < size - 1 && src[i])
{
dst[j] = src[i];
i++;
j++;
}
dst[j] = '\0';
return (len_src + len_dst);
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/02 17:59:58 by adjoly #+# #+# */
/* Updated: 2023/11/03 09:56:01 by adjoly ### ########.fr */
/* Updated: 2023/11/04 15:18:28 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,7 +26,7 @@ char *ft_substr(char const *s, unsigned int start, size_t len)
result[0] = '\0';
return (result);
}
result = malloc(len * sizeof(char));
result = malloc((len + 1) * sizeof(char));
if (result == NULL)
return (NULL);
while (i < len && s[start + i])

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 10:06:03 by adjoly #+# #+# */
/* Updated: 2023/11/03 23:06:30 by adjoly ### ########.fr */
/* Updated: 2023/11/04 14:07:28 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -37,5 +37,7 @@ size_t ft_strlen(const char *s);
char *ft_substr(char const *s, unsigned int start, size_t len);
int ft_tolower(int c);
int ft_toupper(int c);
size_t ft_strlcat(char *dst, const char *src, size_t size);
char *ft_strjoin(char const *s1, char const *s2);
#endif

BIN
libft.so Executable file

Binary file not shown.