-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilereader.c
41 lines (38 loc) · 1.32 KB
/
filereader.c
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
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* filereader.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ymoukhli <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/11 14:46:00 by ymoukhli #+# #+# */
/* Updated: 2019/08/08 23:38:31 by nhamid ### ########.fr */
/* */
/* ************************************************************************** */
#include "rtparse.h"
char *ft_file(char *file)
{
int fd;
int rd;
char buf[BUF_SIZE + 1];
char *str_file;
char *tmp;
fd = open(file, O_RDONLY);
if (fd < 0 || read(fd, buf, 0) < 0)
return (NULL);
str_file = ft_strnew(0);
while ((rd = read(fd, buf, BUF_SIZE)))
{
tmp = str_file;
buf[rd] = '\0';
if (!(str_file = ft_strjoin(str_file, buf)))
{
free(tmp);
close(fd);
return (NULL);
}
free(tmp);
}
close(fd);
return (str_file);
}