aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile24
-rw-r--r--get_next_line/get_next_line.c (renamed from get_next_line.c)36
-rw-r--r--get_next_line/get_next_line.h (renamed from get_next_line.h)8
3 files changed, 35 insertions, 33 deletions
diff --git a/Makefile b/Makefile
index 152e843..de79815 100644
--- a/Makefile
+++ b/Makefile
@@ -6,15 +6,17 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/10/08 15:45:53 by cacharle #+# #+# #
-# Updated: 2019/11/21 03:43:46 by cacharle ### ########.fr #
+# Updated: 2020/01/15 07:34:57 by cacharle ### ########.fr #
# #
# **************************************************************************** #
LIB = ar rcs
RM = rm -f
+GET_NEXT_LINE_DIR = get_next_line
+
CC = gcc
-CCFLAGS = -Wall -Wextra -Werror
+CCFLAGS = -I. -I$(GET_NEXT_LINE_DIR) -Wall -Wextra -Werror
NAME = libft.a
SRC = ft_atoi.c ft_bzero.c ft_isalnum.c ft_isalpha.c ft_isascii.c ft_isdigit.c \
@@ -28,12 +30,15 @@ SRC = ft_atoi.c ft_bzero.c ft_isalnum.c ft_isalpha.c ft_isascii.c ft_isdigit.c \
ft_strncmp.c ft_strncpy.c ft_strnequ.c ft_strnew.c ft_strnstr.c \
ft_strrchr.c ft_split.c ft_strstr.c ft_substr.c ft_strtrim.c \
ft_tolower.c ft_toupper.c ft_strlcpy.c ft_calloc.c ft_strndup.c \
- ft_strjoin_free.c ft_strjoin_free_snd.c get_next_line.c ft_strcount.c \
- ft_printf.c ft_sprintf.c ft_snprintf.c ft_asprintf.c ft_dprintf.c \
- ft_vprintf.c ft_vsprintf.c ft_vsnprintf.c ft_vasprintf.c ft_vdprintf.c
+ ft_strjoin_free.c ft_strjoin_free_snd.c ft_strcount.c
+ # ft_printf.c ft_sprintf.c ft_snprintf.c ft_asprintf.c ft_dprintf.c \
+ # ft_vprintf.c ft_vsprintf.c ft_vsnprintf.c ft_vasprintf.c ft_vdprintf.c
+SRC += $(GET_NEXT_LINE_DIR)/get_next_line.c
+
OBJ = $(SRC:.c=.o)
-INCLUDE = libft.h
+
+HEADER = libft.h
BONUSSRC = ft_lstadd_back_bonus.c ft_lstadd_front_bonus.c ft_lstclear_bonus.c \
ft_lstdelone_bonus.c ft_lstiter_bonus.c ft_lstlast_bonus.c \
ft_lstmap_bonus.c ft_lstnew_bonus.c ft_lstsize_bonus.c ft_lstpop_front_bonus.c
@@ -41,10 +46,10 @@ BONUSOBJ = $(BONUSSRC:.c=.o)
all: $(NAME)
-$(NAME): $(OBJ) $(INCLUDE)
+$(NAME): $(OBJ) $(HEADER)
$(LIB) $(NAME) $(OBJ)
-bonus: $(BONUSOBJ) $(INCLUDE)
+bonus: $(BONUSOBJ) $(HEADER)
$(LIB) $(NAME) $(BONUSOBJ)
%.o: %.c
@@ -59,6 +64,3 @@ fclean: clean
re: fclean all
rebonus: fclean bonus
-
-so: $(OBJ) $(BONUSOBJ) $(INCLUDE)
- $(CC) -shared -fPIC -Wl,-soname,libft.so -o libft.so $(OBJ) $(BONUSOBJ)
diff --git a/get_next_line.c b/get_next_line/get_next_line.c
index 00aca8d..e51f152 100644
--- a/get_next_line.c
+++ b/get_next_line/get_next_line.c
@@ -6,15 +6,15 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/19 09:08:36 by cacharle #+# #+# */
-/* Updated: 2019/11/21 03:39:51 by cacharle ### ########.fr */
+/* Updated: 2020/01/15 07:26:50 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
-#define HAS_NEWLINE(str, split_at) ((split_at = find_newline(str)) != -1)
+#define HAS_NEWLINE(str, split_at) ((split_at = gnl_find_newline(str)) != -1)
-static int find_newline(char *str)
+static int gnl_find_newline(char *str)
{
int i;
@@ -25,7 +25,7 @@ static int find_newline(char *str)
return (-1);
}
-static int free_return(char **ptr, char **ptr2, int ret)
+static int gnl_free_return(char **ptr, char **ptr2, int ret)
{
if (ptr != NULL)
{
@@ -40,14 +40,14 @@ static int free_return(char **ptr, char **ptr2, int ret)
return (ret);
}
-static int read_line(int fd, char **line, char *rest)
+static int gnl_read_line(int fd, char **line, char *rest)
{
int ret;
int split_at;
char *buf;
if ((buf = malloc(sizeof(char) * (BUFFER_SIZE + 1))) == NULL)
- return (free_return(line, NULL, STATUS_ERROR));
+ return (gnl_free_return(line, NULL, GNL_STATUS_ERROR));
while ((ret = read(fd, buf, BUFFER_SIZE)) > 0)
{
buf[ret] = '\0';
@@ -56,15 +56,15 @@ static int read_line(int fd, char **line, char *rest)
ft_strcpy(rest, buf + split_at + 1);
buf[split_at] = '\0';
if ((*line = ft_strjoin_free(*line, buf, 1)) == NULL)
- return (free_return(&buf, NULL, STATUS_ERROR));
- return (free_return(&buf, NULL, STATUS_LINE));
+ return (gnl_free_return(&buf, NULL, GNL_STATUS_ERROR));
+ return (gnl_free_return(&buf, NULL, GNL_STATUS_LINE));
}
if ((*line = ft_strjoin_free(*line, buf, 1)) == NULL)
- return (free_return(&buf, NULL, STATUS_ERROR));
+ return (gnl_free_return(&buf, NULL, GNL_STATUS_ERROR));
}
if (ret == -1)
- return (free_return(&buf, line, STATUS_ERROR));
- return (free_return(&buf, NULL, ret));
+ return (gnl_free_return(&buf, line, GNL_STATUS_ERROR));
+ return (gnl_free_return(&buf, NULL, ret));
}
/*
@@ -91,25 +91,25 @@ int get_next_line(int fd, char **line)
static char rest[OPEN_MAX][BUFFER_SIZE + 1] = {{0}};
if (fd < 0 || fd > OPEN_MAX || line == NULL || BUFFER_SIZE <= 0)
- return (STATUS_ERROR);
+ return (GNL_STATUS_ERROR);
if ((*line = ft_strdup("")) == NULL)
- return (STATUS_ERROR);
+ return (GNL_STATUS_ERROR);
if (rest[fd][0] == '\0')
- return (read_line(fd, line, rest[fd]));
+ return (gnl_read_line(fd, line, rest[fd]));
if (HAS_NEWLINE(rest[fd], split_at))
{
free(*line);
if ((*line = (char*)malloc(sizeof(char) * (split_at + 1))) == NULL)
- return (STATUS_ERROR);
+ return (GNL_STATUS_ERROR);
ft_strncpy(*line, rest[fd], split_at);
(*line)[split_at] = '\0';
ft_strcpy(rest[fd], rest[fd] + split_at + 1);
- return (STATUS_LINE);
+ return (GNL_STATUS_LINE);
}
free(*line);
if (!(*line = (char*)malloc(sizeof(char) * (ft_strlen(rest[fd]) + 1))))
- return (STATUS_ERROR);
+ return (GNL_STATUS_ERROR);
ft_strcpy(*line, rest[fd]);
rest[fd][0] = '\0';
- return (read_line(fd, line, rest[fd]));
+ return (gnl_read_line(fd, line, rest[fd]));
}
diff --git a/get_next_line.h b/get_next_line/get_next_line.h
index 36a5116..9d15202 100644
--- a/get_next_line.h
+++ b/get_next_line/get_next_line.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/09 13:52:59 by cacharle #+# #+# */
-/* Updated: 2019/11/21 02:47:49 by cacharle ### ########.fr */
+/* Updated: 2020/01/15 07:22:07 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,9 +22,9 @@
# define BUFFER_SIZE 32
# endif
-# define STATUS_LINE 1
-# define STATUS_EOF 0
-# define STATUS_ERROR -1
+# define GNL_STATUS_LINE 1
+# define GNL_STATUS_EOF 0
+# define GNL_STATUS_ERROR -1
/*
** get_next_line.c