Remove Libft for it not to collide with get_next_line defintion of linked list.
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 12 Oct 2023 11:14:17 +0000 (13:14 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 12 Oct 2023 11:14:17 +0000 (13:14 +0200)
Move required files from Libft to src/.
Change header file main.h accordingly.

.gitmodules
Libft [deleted submodule]
main.h
src/ft_putstr_fd.c [new file with mode: 0644]
src/ft_strdup.c [new file with mode: 0644]
src/ft_strlcpy.c [new file with mode: 0644]
src/ft_strlen.c [new file with mode: 0644]
src/main.c

index 626d13986af8f8ca608369046104d762d80b11fc..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,3 +0,0 @@
-[submodule "Libft"]
-       path = Libft
-       url = git://ljiriste.work/Libft
diff --git a/Libft b/Libft
deleted file mode 160000 (submodule)
index ddbbb7c..0000000
--- a/Libft
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit ddbbb7c8475d0ea607f847ddfba7e094217d7333
diff --git a/main.h b/main.h
index 270bebefca23f9e2e37dffa7b138ca84739a7ec4..58f78c7415dc36389137e42003800ec7a97d3441 100644 (file)
--- a/main.h
+++ b/main.h
@@ -6,16 +6,18 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/10/11 18:10:37 by ljiriste          #+#    #+#             */
-/*   Updated: 2023/10/11 18:15:50 by ljiriste         ###   ########.fr       */
+/*   Updated: 2023/10/12 13:10:56 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #ifndef MAIN_H
 # define MAIN_H
 
+# include <stddef.h>
+
 char   *ft_strdup(const char *str);
-int            ft_printf(const char *format, ...);
 void   ft_putstr_fd(const char *str, int fd);
-int            ft_strlen(const char *str);
+size_t ft_strlen(const char *str);
+size_t ft_strlcpy(char *dst, const char *src, size_t size);
 
 #endif
diff --git a/src/ft_putstr_fd.c b/src/ft_putstr_fd.c
new file mode 100644 (file)
index 0000000..df5d9d4
--- /dev/null
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_putstr_fd.c                                     :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/15 16:23:36 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/10/12 13:11:05 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <unistd.h>
+#include "main.h"
+
+void   ft_putstr_fd(const char *s, int fd)
+{
+       if (s == NULL)
+               return ;
+       write(fd, s, ft_strlen(s));
+       return ;
+}
diff --git a/src/ft_strdup.c b/src/ft_strdup.c
new file mode 100644 (file)
index 0000000..e4f5c99
--- /dev/null
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strdup.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/17 13:33:49 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/10/12 13:07:19 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stdlib.h>    // For the malloc function
+#include "main.h"
+
+char   *ft_strdup(const char *s)
+{
+       char    *dest;
+       size_t  s_len;
+
+       s_len = ft_strlen(s);
+       dest = malloc((s_len + 1) * sizeof(char));
+       if (dest)
+               ft_strlcpy(dest, s, s_len + 1);
+       return (dest);
+}
diff --git a/src/ft_strlcpy.c b/src/ft_strlcpy.c
new file mode 100644 (file)
index 0000000..2c064c7
--- /dev/null
@@ -0,0 +1,31 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strlcpy.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/11 17:28:43 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/10/12 13:07:24 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "main.h"
+
+size_t ft_strlcpy(char *dst, const char *src, size_t size)
+{
+       size_t  i;
+
+       i = 0;
+       while (src[i] && i + 1 < size)
+       {
+               dst[i] = src[i];
+               ++i;
+       }
+       if (size > 0)
+               dst[i] = '\0';
+       while (src[i])
+               ++i;
+       return (i);
+}
diff --git a/src/ft_strlen.c b/src/ft_strlen.c
new file mode 100644 (file)
index 0000000..2fc7f6c
--- /dev/null
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_strlen.c                                        :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/08/14 13:40:59 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/10/12 13:07:21 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <sys/types.h>
+#include "main.h"
+
+size_t ft_strlen(const char *s)
+{
+       size_t  len;
+
+       len = 0;
+       while (s[len] != '\0')
+               ++len;
+       return (len);
+}
index 6d7aac8211f45d2749f18ee669a98a26ba79f81d..87de09a5b2b1b124a8584b3946eae73c2f4bad15 100644 (file)
@@ -71,7 +71,7 @@ int   main(int argc, char **argv)
 
        if (argc < 2)
        {
-               ft_printf("%s\n", "Error: Not enough arguments.");
+               ft_putstr_fd("Error: Not enough arguments.\n", 2);
                return (-1);
        }
        i = 1;