From: Lukas Jiriste Date: Thu, 12 Oct 2023 13:50:24 +0000 (+0200) Subject: Create the insides of Makefile. X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=28d3be86bd152df9269ae9ae0a3230d763704f93;p=42%2Fgnl_tester.git Create the insides of Makefile. Repair permissions of files reated in main. Repair crash on EOF returning NULL to line. --- diff --git a/Makefile b/Makefile index e69de29..7ca4730 100644 --- 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) diff --git a/src/main.c b/src/main.c index 87de09a..94d8d50 100644 --- a/src/main.c +++ b/src/main.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 ; }