c_piscine__offshore_mains/c02/ex10.c

94 lines
3.1 KiB
C
Raw Normal View History

2023-11-28 15:40:55 +00:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ex10.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: achubuko <achubuko@student.42yerevan.am> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/28 01:25:43 by achubuko #+# #+# */
/* Updated: 2023/11/28 01:26:11 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
#include <tests.h>
#include <stdlib.h>
#define TEST_BUF_SIZE 100
unsigned int ft_strlcpy(char *dest, char *src, unsigned int size);
int main(void)
{
char s[TEST_BUF_SIZE] = TEST_SOURCE;
char d[TEST_BUF_SIZE] = TEST_DESTINATION;
size_t r1;
char s1[TEST_BUF_SIZE] = TEST_SOURCE;
char d1[TEST_BUF_SIZE] = TEST_DESTINATION;
size_t r2;
char s2[TEST_BUF_SIZE] = TEST_SOURCE;
char d2[TEST_BUF_SIZE] = TEST_DESTINATION;
printf("initial strings:\n");
dump(s, TEST_SOURCE_LENGHT);
dump(d, TEST_DESTINATION_LENGHT);
printf("strlcpy(d, s, 4):\n");
r1 = strlcpy(d1, s1, 4);
dump(s1, TEST_SOURCE_LENGHT);
dump(d1, TEST_DESTINATION_LENGHT);
printf("ft_strlcpy(d, s, 4:\n");
r2 = ft_strlcpy(d2, s2, 4);
dump(s2, TEST_SOURCE_LENGHT);
dump(d2, TEST_DESTINATION_LENGHT);
printf("buffers comparison: s:%i d:%i\n",
bufcmp(s1, s2, TEST_SOURCE_LENGHT),
bufcmp(d1, d2, TEST_DESTINATION_LENGHT));
printf("return values: orig: %lu ft: %lu\n", r1, r2);
memcpy(d1, d, TEST_BUF_SIZE);
memcpy(s1, s, TEST_BUF_SIZE);
memcpy(d2, d, TEST_BUF_SIZE);
memcpy(s2, s, TEST_BUF_SIZE);
printf("strlcpy(d, s, 20):\n");
r1 = strlcpy(d1, s1, 20);
dump(s1, TEST_SOURCE_LENGHT);
dump(d1, TEST_DESTINATION_LENGHT);
printf("ft_strlcpy(d, s, 20):\n");
r2 = ft_strlcpy(d2, s2, 20);
dump(s2, TEST_SOURCE_LENGHT);
dump(d2, TEST_DESTINATION_LENGHT);
memcpy(d1, d, TEST_BUF_SIZE);
memcpy(s1, s, TEST_BUF_SIZE);
memcpy(d2, d, TEST_BUF_SIZE);
memcpy(s2, s, TEST_BUF_SIZE);
printf("buffers comparison: s:%i d:%i\n",
bufcmp(s1, s2, TEST_SOURCE_LENGHT),
bufcmp(d1, d2, TEST_DESTINATION_LENGHT));
printf("return values: orig: %lu ft: %lu\n", r1, r2);
printf("strlcpy(s, d, 20):\n");
r1 = strlcpy(s1, d1, 20);
dump(s1, TEST_SOURCE_LENGHT);
dump(d1, TEST_DESTINATION_LENGHT);
printf("ft_strlcpy(s, d, 20):\n");
r2 = ft_strlcpy(s2, d2, 20);
dump(s2, TEST_SOURCE_LENGHT);
dump(d2, TEST_DESTINATION_LENGHT);
memcpy(d1, d, TEST_BUF_SIZE);
memcpy(s1, s, TEST_BUF_SIZE);
memcpy(d2, d, TEST_BUF_SIZE);
memcpy(s2, s, TEST_BUF_SIZE);
printf("buffers comparison: s:%i d:%i\n",
bufcmp(s1, s2, TEST_SOURCE_LENGHT),
bufcmp(d1, d2, TEST_DESTINATION_LENGHT));
printf("return values: orig: %lu ft: %lu\n", r1, r2);
}
void setUp(void)
{
}
void tearDown(void)
{
}