Create the insides of Makefile.
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 12 Oct 2023 13:50:24 +0000 (15:50 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 12 Oct 2023 13:50:24 +0000 (15:50 +0200)
Repair permissions of files reated in main.
Repair crash on EOF returning NULL to line.

Makefile
src/main.c

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..7ca4730ea88e106410b57df03fcd9d1ced94f910 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -0,0 +1,41 @@
+CC = cc
+CFLAGS = -Wall -Wextra -Werror -g
+
+GNLDIR = ../
+SRCDIR = src/
+OBJDIR = obj/
+
+SRCS = $(shell find $(SRCDIR) -name '*.c' -type f -printf "%f\n")
+GNLSRCS = get_next_line.c get_next_line_utils.c
+OBJS = $(SRCS:%.c=$(OBJDIR)%.o)
+GNLOBJS = $(GNLSRCS:%.c=$(OBJDIR)%.o)
+
+
+NAME = test_ex
+
+all : $(NAME)
+
+$(NAME) : $(OBJS) $(GNLOBJS)
+       $(CC) $(CFLAGS) $^ -o $@
+       
+$(OBJS) : $(OBJDIR)%.o : $(SRCDIR)%.c
+       $(CC) $(CFLAGS) -c $< -o $@ -I$(GNLDIR) -I.
+
+$(GNLOBJS) : $(OBJDIR)%.o : $(GNLDIR)%.c
+ifndef BUFFER_SIZE
+       $(CC) $(CFLAGS) -c $< -o $@ -I$(GNLDIR)
+else
+       $(CC) $(CFLAGS) -c $< -o $@ -I$(GNLDIR) -DBUFFER_SIZE=$(BUFFER_SIZE)
+endif
+
+# GNLSRCS are added as phony for them to compile when BUFFER_SIZE changes
+.PHONY : $(addprefix $(GNLDIR), $(GNLSRCS))
+
+clean :
+       $(RM) $(OBJDIR)*
+
+fclean : clean
+       $(RM) $(NAME)
+
+re : fclean
+       $(MAKE)
index 87de09a5b2b1b124a8584b3946eae73c2f4bad15..94d8d50240ab8020daf764ff5bb3aef0802ae50b 100644 (file)
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   main.c                                             :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/10/12 14:52:24 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/10/12 14:57:56 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
 #ifndef TEST_DIR
 # define TEST_DIR "./test_files/"
 #endif
@@ -43,7 +55,7 @@ int   create_res_file(const char *fname)
 
        path = ft_strdup(RESULT_DIR);
        ft_strncat_alloc(&path, fname, ft_strlen(fname));
-       fd = open(path, O_WRONLY | O_CREAT);
+       fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
        return (fd);
 }
 
@@ -57,8 +69,9 @@ void  test_gnl(int testfd, int resfd)
                ft_putstr_fd(line, resfd);
                free(line);
                line = get_next_line(testfd);
-               if (last_char(line) == '\n')
-                       ft_putstr_fd(SEPARATOR, resfd);
+               if (line)
+                       if (last_char(line) == '\n')
+                               ft_putstr_fd(SEPARATOR, resfd);
        }
        return ;
 }