diff options
| author | Dominik Kaiser | 2024-04-12 16:55:57 +0200 |
|---|---|---|
| committer | Dominik Kaiser | 2024-04-12 16:55:57 +0200 |
| commit | 358e300bc148d2a223e1cfa2a3c49da6c0ba968c (patch) | |
| tree | f79772df1f0d5590b71c3ca1e70370ec86540aab /get_next_line_utils.c | |
| parent | 0560de9d3932735737ac9118c626a7ced0eedfd2 (diff) | |
| download | libft-358e300bc148d2a223e1cfa2a3c49da6c0ba968c.tar.gz libft-358e300bc148d2a223e1cfa2a3c49da6c0ba968c.zip | |
Add get_next_line to libft
Diffstat (limited to 'get_next_line_utils.c')
| -rw-r--r-- | get_next_line_utils.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/get_next_line_utils.c b/get_next_line_utils.c new file mode 100644 index 0000000..61171be --- /dev/null +++ b/get_next_line_utils.c @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/15 14:14:59 by dkaiser #+# #+# */ +/* Updated: 2024/03/26 10:49:08 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "get_next_line.h" + +int ft_strlen(const char *str) +{ + int len; + + if (!str) + return (0); + len = 0; + while (str[len]) + len++; + return (len); +} + +void clear_buffer(char *buf, int start) +{ + while (start < BUFFER_SIZE) + buf[start++] = '\0'; +} + +char *str_add_buffer(char *old_str, char *buf, int buf_len) +{ + char *result; + int len; + int i; + + if (!old_str) + len = buf_len; + else + len = ft_strlen(old_str) + buf_len; + result = malloc(sizeof(char) * (len + 1)); + if (!result) + { + free(old_str); + return (NULL); + } + result[len] = '\0'; + i = 0; + while (old_str && old_str[i]) + { + result[i] = old_str[i]; + i++; + } + while (i < len) + result[i++] = *(buf++); + free(old_str); + return (result); +} |
