-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_read_file.c
More file actions
executable file
·38 lines (35 loc) · 1.27 KB
/
ft_read_file.c
File metadata and controls
executable file
·38 lines (35 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: schakor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/06 12:03:43 by schakor #+# #+# */
/* Updated: 2018/02/06 17:30:11 by schakor ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
char *ft_read_file(char *file)
{
int rd;
int fd;
char buf[545];
char *content;
if ((fd = open(file, O_RDONLY)) == -1)
{
ft_putendl_fd("error", 1);
exit(1);
}
rd = read(fd, buf, 545);
if (rd == -1 || rd > 545)
{
ft_putendl_fd("error", 1);
exit(1);
}
buf[rd] = '\0';
content = ft_strdup(buf);
if ((rd + 1) % 21 != 0)
ft_print_err();
return (content);
}