summaryrefslogtreecommitdiff
path: root/libft/get_next_line_utils.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-05-08 13:14:19 +0200
committerDominik Kaiser2024-05-08 13:14:19 +0200
commit95ccc46ad62c59e648679acad8b44ba5d4465e3d (patch)
treec053e4c692039d151cefa26759bee90d31d8c0a0 /libft/get_next_line_utils.c
parent42289aa55c7dafe8fffbcdfb0e02f089b7b83afb (diff)
downloadpipex-master.tar.gz
pipex-master.zip
Add libft as dirHEADmaster
Diffstat (limited to 'libft/get_next_line_utils.c')
-rw-r--r--libft/get_next_line_utils.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/libft/get_next_line_utils.c b/libft/get_next_line_utils.c
new file mode 100644
index 0000000..61171be
--- /dev/null
+++ b/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);
+}