/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* get_next_line_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/01 12:31:58 by kcolin #+# #+# */ /* Updated: 2024/11/06 17:37:39 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ #include "get_next_line.h" #include size_t ft_strlen(const char *s) { size_t i; if (s == NULL) return (0); i = 0; while (s[i] != '\0') i++; return (i); } char *ft_strjoin(char *s1, char *s2) { char *out; size_t i; size_t j; if (s1 == NULL) { s1 = malloc(1); s1[0] = '\0'; } out = malloc(ft_strlen(s1) + ft_strlen(s2) + 1); if (out == NULL) return (NULL); i = 0; j = 0; while (s1[i] != '\0') { out[i] = s1[i]; i++; } while (s2[j] != '\0') { out[i] = s2[j]; i++; j++; } return (out); } char *ft_strchr(const char *s, int c) { size_t i; if (s == NULL) return (0); i = 0; while (s[i] != '\0') { if (s[i] == (char)c) return ((char *)s + i); i++; } if ((char)c == '\0') return ((char *)s + i); return (0); } char *ft_substr(char const *s, unsigned int start, size_t len) { char *out; size_t i; i = 0; if (s[i] == '\0' || start > ft_strlen(s) || len == 0) return (NULL); out = malloc((len + 1) * sizeof(char)); if (out == NULL) return (NULL); while (i < len) { out[i] = s[start + i]; i++; } out[i] = '\0'; return (out); }