diff options
| author | Dominik Kaiser | 2024-06-24 16:58:46 +0200 |
|---|---|---|
| committer | GitHub | 2024-06-24 16:58:46 +0200 |
| commit | a28e57c6e0277a1d7346bec58cf557c52e337501 (patch) | |
| tree | 8710c1c12dfd9e6c52821944b0676ec15e5e20ae /lib/libft/get_next_line_utils.c | |
| parent | f1349566aef0cb80ef8f4cdcf2795e38631ed820 (diff) | |
| download | minishell-a28e57c6e0277a1d7346bec58cf557c52e337501.tar.gz minishell-a28e57c6e0277a1d7346bec58cf557c52e337501.zip | |
Add libft
Diffstat (limited to 'lib/libft/get_next_line_utils.c')
| -rw-r--r-- | lib/libft/get_next_line_utils.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/libft/get_next_line_utils.c b/lib/libft/get_next_line_utils.c new file mode 100644 index 0000000..61171be --- /dev/null +++ b/lib/libft/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); +} |
