size_t ft_strlcat(char *dst, const char *src, size_t size) { size_t length_src; size_t length_dst; size_t len; len = ft_strlen(src) + ft_strlen(dst); length_src = ft_strlen(src); length_dst = ft_strlen(dst); if (size > length_dst) { ft_strncat(dst, src, size - length_dst - 1); return (length_src + length_dst); } else { return (len - (length_dst - size)); } }
size_t ft_strlcat(char *dst, const char *src, size_t size) { size_t i; size_t re; re = 0; i = -1; while (src[++i]) ; re = i; i = -1; while (dst[++i] && i < size) ; re += (i < size) ? i : size; if ((int)(size - ft_strlen(dst) - 1) > 0) ft_strncat(dst, src, size - ft_strlen(dst) - 1); size -= i; return (re); }
static char *ft_strnjoin(char const *s1, char const *s2, size_t len_s2) { char *ptr; int i; int len; ptr = NULL; if (!s1) s1 = ""; len = ft_strlen(s1); if (s2 && (ptr = (char *)malloc(sizeof(char) * (len + len_s2 + 1)))) { ft_strcpy(ptr, s1); i = (len == 0) ? 0 : len - 1; ft_strncat(&ptr[i], s2, len_s2); } return (ptr); }
char *cpycat(char *s1, char *s2) { char *tmp; tmp = NULL; if ((s1 && !s2) || (!s1 && s2)) { if (s1) return (s1); else return (s2); } if (!s1 && !s2) return (NULL); tmp = ft_memalloc(ft_strlen(s1) + ft_strlen(s2)); tmp = ft_strcpy(tmp, s1); tmp = ft_strncat(tmp, s2, ft_strlen(s2)); return (tmp); }
char *convertlst(t_dlist **alst) { char path[2048]; t_dlist *drive; ft_bzero((void *)path, 2048); drive = *alst; while (drive) { if (drive->content) { ft_strcat(path, "/"); ft_strncat(path, (char *)drive->content, drive->content_size); } drive = drive->n; } ft_dlstdel(alst, NULL); return (ft_strdup(path)); }
size_t ft_strlcat(char *dest, char *src, size_t destsize) { size_t i; size_t j; char *ddest; char *ssrc; ddest = dest; ssrc = (char *)src; i = ft_strlen(ddest); j = ft_strlen(ssrc); if (i > destsize) return (j + destsize); if (i < destsize) { ft_strncat(dest, ssrc, destsize - 1); dest[destsize - 1] = '\0'; } return (i + j); }
char *ft_strjoin(char const *s1, const char *s2) { size_t len_s1; size_t len_s2; char *str; if (s1 && s2) { len_s1 = ft_strlen(s1); len_s2 = ft_strlen(s2); str = ft_strnew(len_s1 + len_s2); if (str) { str = ft_strcpy(str, s1); str = ft_strncat(str, s2, len_s2); return (str); } } return (0); }
char *list_to_str(t_list *file, int list_size) { t_list *index; char *buff; if (!(buff = (char*)malloc(sizeof(char) * BUFF_SIZE * list_size + 1))) return (NULL); else { buff[0] = '\0'; index = file; while (list_size-- > 0) { ft_strncat(buff, index->data, index->len); index = index->next; } ft_list_foreach(file, &free); ft_list_clear(&file); } return (buff); }
char *ft_strnjoin(char const *s1, char const *s2, size_t n) { char *str; int len_s1; if (!s1 && s2) return (ft_strdup(s1)); if (!s2 && s1) return (ft_strdup(s2)); if (!s1 && !s2) return (NULL); len_s1 = ft_strlen(s1); str = ft_strnew(len_s1 + n + 1); if (!str) return (NULL); if (!ft_strcat(str, s1)) return (NULL); if (!ft_strncat(str, (char *)s2, n)) return (NULL); return (str); }
size_t ft_strlcat(char *dst, const char *src, size_t size) { size_t s_dst; size_t s_src; size_t tmp; if (dst && src) { s_dst = ft_strlen(dst); s_src = ft_strlen(src); if (size <= s_dst) return (s_src + size); else { tmp = size - s_dst - 1; ft_strncat(dst, src, tmp); return (s_dst + s_src); } } return (0); }
int add_buff(char **dst, char *to_add) { int len_dst; int len_to_add; char *tmp; len_dst = ft_strlen(*dst); len_to_add = ft_strlen_chr(to_add, '\n'); if (!(tmp = (char *)malloc(sizeof(char) * (len_dst + 1)))) return (-1); tmp = ft_strcpy(tmp, *dst); if (!(*dst = (char *)malloc(sizeof(char) * (len_dst + len_to_add + 1)))) { free (tmp); return (-1); } *dst = ft_strcpy(*dst, tmp); free (tmp); *dst = ft_strncat(*dst, to_add, len_to_add); if (to_add[len_to_add]) return (to_add[len_to_add + 1]) ? len_to_add + 1: 0; return (0); }
char *ft_add_in(char *buffer, char *toadd, int oct, int i) { int new_len; char *tmp; if (!buffer || buffer == NULL) buffer = (char*)malloc(sizeof(char)); new_len = (ft_strlen(buffer) + ft_strlen(toadd)); if (!(tmp = (char*)malloc(sizeof(char) * (ft_strlen(buffer) + 1)))) return (NULL); while (buffer[i]) { tmp[i] = buffer[i]; i++; } tmp[i] = '\0'; i = 0; if (!(buffer = (char*)malloc(sizeof(char) * (new_len + 1)))) return (NULL); buffer = ft_strcat(buffer, tmp); buffer = ft_strncat(buffer, toadd, oct); free(tmp); return (buffer); }
char *ft_strcat(char *dest, const char *src) { return (ft_strncat(dest, src, ft_strlen(src))); }
static int ft_is_new_line(char **line, char *buf, int i) { ft_strncat(*line, buf, i); ft_strcpy(buf, ft_strsub(buf, i + 1, BUFF_SIZE - i - 1)); return (1); }
char *ft_strcat(char *dst, const char *src) { ft_strncat(dst, src, ft_strlen(src)); return (dst); }
static int ft_is_new_line(char **line, char *buf, int i) { ft_strncat(*line, buf, i); ft_strcpy(buf, buf + i + 1); return (1); }
char *ft_strcat(char *s1, const char *s2) { return (ft_strncat(s1, s2, ft_strlen(s2))); }
int main(int argc, char **argv) { int i; char *str; char *str2; printf("\n-------------------- PART 1 ----------------------------\n"); printf("ft_bzero(str, 2):\n"); str = strdup("coucou"); printf("str avant : %s\n", str); ft_bzero(str, 2); printf("str apres : %s\n", str); printf("\nft_strcat(str1, str2) :\n"); str = malloc(50); ft_bzero(str, 50); ft_strcat(str, "123456789"); printf("str1 : %s\n", str); printf("str2 : coucou \n"); ft_strcat(str, strdup("coucou")); printf("str1 : %s\n", str); printf("\nft_isalpha :\n"); i = ft_isalpha('a'); printf("a : %d\n", i); i = ft_isalpha('^'); printf("^ : %d\n", i); printf("\nft_isdigit :\n"); i = ft_isdigit('2'); printf("2 : %d\n", i); i = ft_isdigit('a'); printf("a : %d\n", i); printf("\nft_isalnum :\n"); i = ft_isalnum('2'); printf("2 : %d\n", i); i = ft_isalnum('a'); printf("a : %d\n", i); i = ft_isalnum(32); printf("' ' : %d\n", i); i = ft_isalnum(59); printf("';' : %d\n", i); i = ft_isalnum(93); printf("']' : %d\n", i); printf("\nft_isascii :\n"); i = ft_isascii('a'); printf("a : %d\n", i); i = ft_isascii(130); printf("%c : %d\n", 130, i); printf("\nft_isprint :\n"); i = ft_isprint(' '); printf("' ' : %d\n", i); i = ft_isprint('\t'); printf("'\t' : %d\n", i); printf("\nft_toupper : \n"); i = ft_toupper('a'); printf("a : %c\n", i); i = ft_toupper('S'); printf("S : %c\n", i); printf("\nft_tolower : \n"); i = ft_tolower('Y'); printf("Y : %c\n", i); i = ft_tolower('b'); printf("b : %c\n", i); printf("\nft_puts : \n"); str = strdup("coucou"); ft_putstr("coucou : "); ft_puts(str); ft_putstr("J'aime bien les chats. : "); str = strdup("J'aime bien les chats."); ft_puts(str); ft_putstr("NULL : "); ft_puts(NULL); printf("\n-------------------- PART 2 ----------------------------\n"); printf("\nft_strlen : \n"); str = strdup("coucou"); i = ft_strlen(str); printf("coucou : %d\n", i); str = strdup("La vie est belle."); i = ft_strlen(str); printf("La vie est belle. : %d\n", i); i = ft_strlen(NULL); printf("NULL : %d\n", i); printf("\nft_memset(str, x, 3) : \n"); str = strdup("coucou"); printf("str avant: %s\n", str); str = ft_memset(str, 'x', 3); printf("str apres: %s\n", str); printf("\nft_memcpy(dest, src, size) :\n"); str = strdup("chatschats chats"); printf("dest : %s\n",str); str2 = strdup("j'aime les frites."); printf("src : %s\n", str2); i = 10; printf("size : %d\n", i); str = ft_memcpy(str, str2, i); printf("dest : %s\n", str); printf("\nft_strdup :\n"); str = ft_strdup("424242"); printf("424242 : %s\n", str); printf("\n-------------------- Bonus ----------------------------\n"); printf("\nft_strndup :\n"); str = ft_strndup("424242", 2); printf("424242, size = 2 : %s\n", str); printf("\nft_isspace :\n"); i = ft_isspace(' '); printf("' ' : %d\n", i); i = ft_isspace('a'); printf("a : %d\n", i); printf("\nft_strncat(str1, str2, size) :\n"); str = malloc(50); ft_bzero(str, 50); ft_strcat(str, "123456789"); printf("str1 : %s\n", str); printf("str2 : coucou \n"); ft_strncat(str, strdup("coucou"), 3); printf("str1 : %s\n", str); printf("\n-------------------- ft_cat(fd) ------------------------\n"); if (argc == 2) i = open(argv[1], O_RDONLY); else i = 0; ft_cat(i); return (0); }
char *ft_strsub(char const *s, unsigned int start, size_t len) { if (s == NULL) return (NULL); return (ft_strncat(ft_strnew(len), start + s, len)); }