Working on ft_strlcpy()

This commit is contained in:
lalgarra 2025-10-05 14:57:01 +02:00
parent 95e346c2ee
commit 8065f4722e
3 changed files with 77 additions and 4 deletions

View file

@ -6,7 +6,7 @@
# By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2025/10/03 18:03:12 by lalgarra #+# #+# #
# Updated: 2025/10/05 14:09:02 by lalgarra ### ########.fr #
# Updated: 2025/10/05 14:41:54 by lalgarra ### ########.fr #
# #
# **************************************************************************** #
@ -20,7 +20,7 @@ CFLAGS += -Wall -Wextra -Werror -g3 -iquote $(LIBDIR) \
TESTS := ft_isalpha_test ft_isdigit_test ft_isalnum_test ft_isascii_test \
ft_isprint_test ft_toupper_test ft_tolower_test ft_strlen_test \
ft_memset_test ft_bzero_test ft_memcpy_test ft_calloc_test \
ft_memmove_test
ft_memmove_test ft_strlcpy_test
%_test : %_test.c
$(CC) $(CFLAGS) $*_test.c -L$(LIBDIR) -lft -o $*_test

View file

@ -6,7 +6,7 @@
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/05 13:21:43 by lalgarra #+# #+# */
/* Updated: 2025/10/05 14:02:12 by lalgarra ### ########.fr */
/* Updated: 2025/10/05 14:53:12 by lalgarra ### ########.fr */
/* */
/* ************************************************************************** */
@ -46,7 +46,8 @@ static void do_test1(char *prefix)
fd = STDOUT_FILENO;
ft_bzero(buf, 128);
ft_memcpy(buf, "Lorem ipsum dolor sit amet consectetur adipiscing elit.", 20);
ft_memcpy(buf,
"Lorem ipsum dolor sit amet consectetur adipiscing elit.", 20);
ft_putstr_fd(prefix, fd);
ft_putchar_fd('\n', fd);
ft_putstr_fd(buf, fd);

72
ft_strlcpy_test.c Normal file
View file

@ -0,0 +1,72 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/05 13:21:43 by lalgarra #+# #+# */
/* Updated: 2025/10/05 14:52:21 by lalgarra ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdio.h>
#include <string.h>
/*
static void do_test3(char *prefix)
{
int *buff;
size_t buflen;
size_t size;
buflen = 5;
size = 0;
buff = ft_calloc(buflen, size);
printf("%ssize= %lu; buff == NULL: %i\n", prefix, size, buff == NULL);
free(buff);
}
static void do_test2(char *prefix)
{
int *buff;
size_t buflen;
buflen = 0;
buff = ft_calloc(buflen, sizeof(int));
printf("%sbuflen = %lu; buff == NULL: %i\n", prefix, buflen, buff == NULL);
free(buff);
}
*/
static void do_test1(char *prefix)
{
char src[128];
char dest[128];
int fd;
size_t size;
size_t res;
fd = STDOUT_FILENO;
size = 10;
bzero(dest, size);
memcpy(src, "Lorem ipsum dolor sit amet consectetur adipiscing elit.", 56);
memset(dest, 'X', size + 2);
ft_putstr_fd(prefix, fd);
ft_putstr_fd("src:[", fd);
ft_putstr_fd(src, fd);
ft_putstr_fd("], dest:[", fd);
ft_putstr_fd(dest, fd);
res = ft_strlcpy(dest, src, size);
ft_putstr_fd("], result:[", fd);
ft_putnbr_fd((int) res, fd);
ft_putstr_fd("], dest:[", fd);
ft_putstr_fd(dest, fd);
ft_putendl_fd("]", fd);
}
int main(void)
{
do_test1("test 1: ");
return (0);
}