Skip to content

Commit

Permalink
minimize include
Browse files Browse the repository at this point in the history
  • Loading branch information
rask24 committed Mar 30, 2024
1 parent 306ea28 commit 5833a72
Show file tree
Hide file tree
Showing 48 changed files with 112 additions and 107 deletions.
41 changes: 23 additions & 18 deletions ft_file/file_to_lines.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/26 18:22:21 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:36:55 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:37:20 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include "ft_file.h"
#include "ft_string.h"
#include "get_next_line.h"

static int _count_lines(char *file_path)
{
int fd;
int num_lines;
int n;
char *line;

fd = open(file_path, O_RDONLY);
if (fd == -1)
return (ERROR);
num_lines = 0;
n = 0;
errno = 0;
while (true)
{
Expand All @@ -36,12 +41,12 @@ static int _count_lines(char *file_path)
break ;
}
free(line);
num_lines++;
n++;
}
return (num_lines);
return (n);
}

static int _fill_line_array(char **line_array, int num_lines, char *file_path)
static int _fill_lines(char **lines, int n, char *file_path)
{
int fd;
char *line;
Expand All @@ -50,37 +55,37 @@ static int _fill_line_array(char **line_array, int num_lines, char *file_path)
if (fd == -1)
return (ERROR);
errno = 0;
while (num_lines--)
while (n--)
{
line = get_next_line(fd);
if (!line)
{
close(fd);
if (errno != 0)
{
ft_free_strs(line_array);
ft_free_strs(lines);
return (ERROR);
}
break ;
}
*line_array++ = line;
*lines++ = line;
}
*line_array = NULL;
*lines = NULL;
return (OK);
}

char **file_to_lines(char *file_path)
{
int num_lines;
char **line_array;
int n;
char **lines;

num_lines = _count_lines(file_path);
if (num_lines == ERROR)
n = _count_lines(file_path);
if (n == ERROR)
return (NULL);
line_array = malloc(sizeof(char *) * (num_lines + 1));
if (!line_array)
lines = malloc(sizeof(char *) * (n + 1));
if (!lines)
return (NULL);
if (_fill_line_array(line_array, num_lines, file_path) == ERROR)
if (_fill_lines(lines, n, file_path) == ERROR)
return (NULL);
return (line_array);
return (lines);
}
3 changes: 2 additions & 1 deletion ft_list/ft_lstbefore.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/15 16:54:29 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:16:37 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:21:57 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include <stddef.h>
#include "ft_list.h"

t_list *ft_lst_before(t_list *lst, t_list *trg)
Expand Down
3 changes: 2 additions & 1 deletion ft_list/ft_lstclear.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/04 14:21:01 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:16:44 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:22:18 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include <stddef.h>
#include "ft_list.h"

void ft_lstclear(t_list **lst, void (*del)(void *))
Expand Down
3 changes: 2 additions & 1 deletion ft_list/ft_lstdelone.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/04 19:30:04 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:16:48 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:22:27 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include <stdlib.h>
#include "ft_list.h"

void ft_lstdelone(t_list *lst, void (*f)(void *))
Expand Down
3 changes: 2 additions & 1 deletion ft_list/ft_lstlast.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/04 14:19:25 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:16:57 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:22:41 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include <stddef.h>
#include "ft_list.h"

t_list *ft_lstlast(t_list *lst)
Expand Down
3 changes: 2 additions & 1 deletion ft_list/ft_lstmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/04 22:19:08 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:17:01 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:22:50 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include <stddef.h>
#include "ft_list.h"

t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
Expand Down
3 changes: 2 additions & 1 deletion ft_list/ft_lstnew.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/04 13:08:55 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:17:06 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:22:57 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include <stdlib.h>
#include "ft_list.h"

t_list *ft_lstnew(void *content)
Expand Down
4 changes: 2 additions & 2 deletions ft_math/ft_chmax.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/30 19:53:14 by reasuke #+# #+# */
/* Updated: 2024/03/20 22:47:43 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:24:09 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_math.h"
#include <stdbool.h>

bool ft_chmax(int *a, int b)
{
Expand Down
4 changes: 2 additions & 2 deletions ft_math/ft_chmin.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/30 19:54:01 by reasuke #+# #+# */
/* Updated: 2024/03/20 22:47:49 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:24:52 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_math.h"
#include <stdbool.h>

bool ft_chmin(int *a, int b)
{
Expand Down
4 changes: 2 additions & 2 deletions ft_math/ft_fchmax.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/30 19:53:14 by reasuke #+# #+# */
/* Updated: 2024/03/20 22:53:39 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:25:08 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_math.h"
#include <stdbool.h>

bool ft_fchmax(double *a, double b)
{
Expand Down
4 changes: 2 additions & 2 deletions ft_math/ft_fchmin.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/30 19:54:01 by reasuke #+# #+# */
/* Updated: 2024/03/20 22:53:44 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:25:13 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_math.h"
#include <stdbool.h>

bool ft_fchmin(double *a, double b)
{
Expand Down
4 changes: 2 additions & 2 deletions ft_memory/ft_bzero.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/03 00:06:19 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:25:26 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:26:13 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_memory.h"
#include <stddef.h>

void ft_bzero(void *s, size_t n)
{
Expand Down
3 changes: 2 additions & 1 deletion ft_memory/ft_calloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/03 01:17:23 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:25:35 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:27:06 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include <stdlib.h>
#include "ft_memory.h"

void *ft_calloc(size_t count, size_t size)
Expand Down
4 changes: 2 additions & 2 deletions ft_memory/ft_memccpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/03 00:13:40 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:26:22 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:27:24 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_memory.h"
#include <stddef.h>

void *ft_memccpy(void *dst, const void *src, int c, size_t n)
{
Expand Down
4 changes: 2 additions & 2 deletions ft_memory/ft_memchr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/03 00:54:42 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:26:29 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:28:15 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_memory.h"
#include <stddef.h>

void *ft_memchr(const void *s, int c, size_t n)
{
Expand Down
4 changes: 2 additions & 2 deletions ft_memory/ft_memcmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/03 01:01:03 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:26:35 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:28:29 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_memory.h"
#include <stddef.h>

int ft_memcmp(const void *s1, const void *s2, size_t n)
{
Expand Down
4 changes: 2 additions & 2 deletions ft_memory/ft_memcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/03 00:10:11 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:26:41 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:28:35 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_memory.h"
#include <stddef.h>

void *ft_memcpy(void *dst, const void *src, size_t n)
{
Expand Down
4 changes: 2 additions & 2 deletions ft_memory/ft_memmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/03 01:21:14 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:26:47 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:28:45 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_memory.h"
#include <stddef.h>

void *ft_memmove(void *dst, const void *src, size_t len)
{
Expand Down
4 changes: 2 additions & 2 deletions ft_memory/ft_memset.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/03 00:03:40 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:26:52 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:28:50 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_memory.h"
#include <stddef.h>

void *ft_memset(void *b, int c, size_t len)
{
Expand Down
5 changes: 3 additions & 2 deletions ft_memory/ft_xmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/24 01:13:22 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:47:22 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:40:29 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_memory.h"
#include <stdlib.h>
#include <unistd.h>
#include "ft_printf.h"

void *ft_xmalloc(size_t size)
Expand Down
4 changes: 2 additions & 2 deletions ft_output/ft_putchar_fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/03 01:37:36 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:20:33 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:30:06 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_output.h"
#include <unistd.h>

void ft_putchar_fd(char c, int fd)
{
Expand Down
4 changes: 2 additions & 2 deletions ft_output/ft_putstr_fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/03 01:38:08 by reasuke #+# #+# */
/* Updated: 2024/02/24 12:35:45 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:30:51 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "ft_output.h"
#include <unistd.h>
#include "ft_string.h"

void ft_putstr_fd(char *s, int fd)
Expand Down
3 changes: 2 additions & 1 deletion ft_printf/ft_printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
/* By: reasuke <reasuke@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/06 16:59:33 by reasuke #+# #+# */
/* Updated: 2024/02/23 23:23:02 by reasuke ### ########.fr */
/* Updated: 2024/03/30 15:43:07 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include <unistd.h>
#include "ft_printf.h"

int ft_printf(const char *format, ...)
Expand Down
Loading

0 comments on commit 5833a72

Please sign in to comment.