diff options
| author | Dominik Kaiser | 2024-03-25 14:20:51 +0100 |
|---|---|---|
| committer | Dominik Kaiser | 2024-03-25 14:20:51 +0100 |
| commit | ac2a1018fe004bf158025eacb6bf78c2bd3fce7a (patch) | |
| tree | e0662c38967cc2c7e8716a36a324b7419bcfe524 /get_next_line_utils.c | |
| parent | 33a83031dd615a342e2acf33cc134bb0a2a4acb8 (diff) | |
| download | get_next_line-ac2a1018fe004bf158025eacb6bf78c2bd3fce7a.tar.gz get_next_line-ac2a1018fe004bf158025eacb6bf78c2bd3fce7a.zip | |
Refactor some more
Should be ready for eval now
Diffstat (limited to 'get_next_line_utils.c')
| -rw-r--r-- | get_next_line_utils.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/get_next_line_utils.c b/get_next_line_utils.c index 690be2a..3f25bba 100644 --- a/get_next_line_utils.c +++ b/get_next_line_utils.c @@ -6,7 +6,7 @@ /* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/15 14:14:59 by dkaiser #+# #+# */ -/* Updated: 2024/03/25 11:53:28 by dkaiser ### ########.fr */ +/* Updated: 2024/03/25 14:18:50 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,24 +22,34 @@ int ft_strlen(const char *str) return (len); } -char *str_realloc(char *str, size_t size) +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; - size_t i; + int len; + int i; - result = malloc(size); + if (!old_str) + len = buf_len; + else + len = ft_strlen(old_str) + buf_len; + result = malloc(sizeof(char) * (len + 1)); if (!result) - { - free(str); return (NULL); - } + result[len] = '\0'; i = 0; - while (str[i]) + while (old_str && old_str[i]) { - result[i] = str[i]; + result[i] = old_str[i]; i++; } - while (i < size) - result[i++] = '\0'; + while (i < len) + result[i++] = *(buf++); + free(old_str); return (result); } |
