Start of Ex. 02.
authorLukas Jiriste <ljiriste@student.42prague.com>
Wed, 28 Jun 2023 19:17:10 +0000 (21:17 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Wed, 28 Jun 2023 19:17:10 +0000 (21:17 +0200)
ex02/Makefile [new file with mode: 0644]
ex02/sources/main.c [new file with mode: 0644]
ex02/test [new file with mode: 0644]

diff --git a/ex02/Makefile b/ex02/Makefile
new file mode 100644 (file)
index 0000000..4489f55
--- /dev/null
@@ -0,0 +1,27 @@
+CC = cc
+CFLAGS = -Wall -Wextra -Werror -g
+
+RM = rm -f
+
+SRCDIR = ./sources
+SOURCES = $(shell find $(SRCDIR) -name "*.c")
+OBJECTS = $(SOURCES:.c=.o)
+
+NAME = ft_tail
+
+all : $(NAME)
+
+$(NAME) : $(OBJECTS)
+       $(CC) $(CFLAGS) -o $(NAME) $(OBJECTS)
+
+%.o : %.c
+       $(CC) $(CFLAGS) -c -o $@ $<
+
+clean :
+       $(RM) $(OBJECTS)
+
+fclean : clean 
+       $(RM) $(NAME)
+
+re : fclean
+       $(MAKE) all
diff --git a/ex02/sources/main.c b/ex02/sources/main.c
new file mode 100644 (file)
index 0000000..89c8644
--- /dev/null
@@ -0,0 +1,73 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   main.c                                             :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/06/27 14:05:49 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/06/27 17:28:04 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+
+void   print_error(char *str)
+{
+       while (*str)
+               write(2, str++, 1);
+       return ;
+}
+
+void   std_input_mode(void)
+{
+       char    c;
+
+       while (read(0, &c, 1) > 0)
+               write(1, &c, 1);
+       return ;
+}
+
+void   tail_file(char *file_name, char *proc_name, unsigned int char_count);
+{
+       int                             fd;
+       char                    c;
+       unsigned int    file_length;
+
+       fd = open(file_name, O_RDWR);
+       if (fd < 0)
+       {
+               print_error(proc_name);
+               print_error(": ");
+               print_error(file_name);
+               print_error(": ");
+               print_error(strerror(errno));
+               print_error("\n");
+       }
+       else
+       {
+               file_length = file_length(file_name);
+
+               while (read(fd, &c, 1) > 0)
+                       write(1, &c, 1);
+               close(fd);
+       }
+}
+
+int    main(int argc, char **argv)
+{
+       int             i;
+       char    *str;
+
+       if (argc == 1)
+               std_input_mode_lines(10);
+       else
+       {
+               
+       }
+       return (0);
+}
diff --git a/ex02/test b/ex02/test
new file mode 100644 (file)
index 0000000..ac5187c
--- /dev/null
+++ b/ex02/test
@@ -0,0 +1,23 @@
+sdfawef
+d
+s
+s
+fa
+rg
+a
+bs
+ta
+er
+ar
+bst
+hae
+rg
+arga
+regarg
+a
+rg
+ar
+a
+rva
+r
+aa