static void unittest2(t_test *test) { char buf[10]; bzero(buf, 10); mt_assert(ft_strlcat(buf, "abc", 10) == 3); mt_assert(ft_strlcat(buf, "def", 10) == 6); }
static void unittest1(t_test *test) { char buf[10]; bzero(buf, 10); strcpy(buf, "abc"); ft_strlcat(buf, "abcdefghijklmnop", 10); mt_assert(strcmp(buf, "abcabcdef") == 0); mt_assert(ft_strlcat(buf, "abcd", 2) == 6); }
int main(void) { /* strcat */ ft_putendl("--- strcat ? --- "); ft_putendl("Real strcat test : "); char s1[]= "sea \0 "; char s2[]= "turtle"; ft_putendl(strcat(s1, s2)); ft_putendl("My strcat test : "); char s3[]= "sea \0 "; ft_putendl(ft_strcat(s3, s2)); /* strncat */ ft_putendl("--- strncat ? --- "); ft_putendl("Real strncat test : "); char s4[]= "sea \0 "; ft_putendl(strncat(s4, s2, 4)); ft_putendl("My strncat test : "); char s5[]= "sea \0 "; ft_putendl(ft_strncat(s5, s2, 4)); /* strlcat */ ft_putendl("--- strlcat ? --- "); ft_putendl("Real strlcat test : "); char s6[]= "sea \0 "; ft_putnbr(strlcat(s6, s2, 1)); ft_putchar('\n'); ft_putendl("My strlcat test : "); char s7[]= "sea \0 "; ft_putnbr(ft_strlcat(s7, s2, 1)); return (0); }
static void unittest3(t_test *test) { char buf[10]; bzero(buf, 10); memset(buf, 'a', 10); mt_assert(ft_strlcat(buf, "ccc", 10) == 13); }
void test_strlcat(void) { char *src = " partie deux"; char true_dst1[23] = {'p', 'a', 'r', 't', 'i', 'e', ' ', 'u', 'n' ,'\0'}; char test_dst1[23] = {'p', 'a', 'r', 't', 'i', 'e', ' ', 'u', 'n' ,'\0'}; char true_dst2[30] = {'p', 'a', 'r', 't', 'i', 'e', ' ', 'u', 'n' ,'\0'}; char test_dst2[30] = {'p', 'a', 'r', 't', 'i', 'e', ' ', 'u', 'n' ,'\0'}; size_t true_ret1; size_t true_ret2; size_t test_ret1; size_t test_ret2; printf("\nTesting strlcat\n"); true_ret1 = strlcat(true_dst1, src, 4); test_ret1 = ft_strlcat(test_dst1, src, 4); true_ret2 = strlcat(true_dst2, src, 25); test_ret2 = ft_strlcat(test_dst2, src, 25); printf("%-20s %-30s %-10lu %-30s %-10lu\n%-20s %-30s %-10lu %-30s %-10lu\n", "Expected result:", true_dst1, true_ret1, true_dst2, true_ret2, "Actual result:", test_dst1, test_ret1, true_dst2, test_ret2); }
char *ft_strjoin(const char *s1, const char *s2) { char *str; size_t i; int j; i = ft_strlen(s1) + ft_strlen(s2); str = (char *)malloc(sizeof(char) * i + 1); if (str == NULL) return (NULL); ft_strcpy(str, s1); j = ft_strlcat(str, s2, i + 1); return (str); }
char *ft_strjoin(char const *s1, char const *s2) { char *result; if (s1 == NULL || s2 == NULL) return (NULL); result = (char*)malloc(sizeof(*result) * (ft_strlen(s1) + ft_strlen(s2) + 1)); if (result == NULL) return (NULL); ft_strcpy(result, s1); ft_strlcat(result, s2, (ft_strlen(s1) + ft_strlen(s2) + 1)); return (result); }
int main(void) { const char src1[10] = "ab"; char dest1[10] = "123"; char src[10] = "ab"; char dest[10] = "123"; size_t nb = 2; unsigned int nb2 = 2; //strcat(src, dest); printf("Str: %ld \n", strlcat(dest1, src1, nb)); printf("Str: %u", ft_strlcat(dest, src, nb2)); return (0); }
static void transform_size_into_str(off_t size, long divider, char *str, int i) { static char unit[5] = {'T', 'G', 'M', 'K', 'B'}; char *buf; buf = divider > 1 ? ft_itoa(size / divider) : ft_itoa_ll(size, 10); ft_strcpy(str, buf); ft_strdel(&buf); if (divider > 1 && ft_strlen(str) == 1) { ft_strlcat(str, ".", 100); buf = ft_itoa(get_first_rounded_digit((long)size, divider)); ft_strncat(str, buf, 1); ft_strdel(&buf); } ft_strncat(str, &unit[i], 1); }
char *ft_list_to_string(t_node *list, char delimiter) { int len; char *str; t_node *current; t_strl *converted; t_strl *temp; current = list; converted = ft_strl(current->data); while (current->next != NULL) { current = current->next; converted = ft_strlpush(converted, delimiter); temp = ft_strl(current->data); converted = ft_strlcat(converted, temp); free(temp); } str = ft_strl_to_string(converted); return (str); }
static int home_cat(const char *src, const char *home, char buf[PATH_MAX + 1]) { size_t nhome; size_t nuid; *buf = '\0'; nhome = ft_strlen(home); while (nhome > 0 && home[nhome - 1] == '/') nhome--; while (nhome > 0 && home[nhome - 1] != '/') nhome--; if (nhome == 0) { ft_strcpy(buf, "/"); nhome = 1; } if (nhome + ft_strlen(src + 1) > PATH_MAX) return (ENAMETOOLONG); nuid = ft_strcharlen(src + 1, '/'); ft_strlcpy(buf, home, nhome + 1); ft_strlcat(buf, src + 1, nhome + nuid + 1); return (0); }
static void unittest7(t_test *test) { mt_assert(ft_strlcat(strdup("abc\0\0\0"), "ccc", 10) == strlcat(strdup("abc\0\0\0"), "ccc", 10)); }