-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_reader.c
executable file
·39 lines (36 loc) · 1.35 KB
/
ft_reader.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_reader.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbiliaie <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/11 22:25:07 by mbiliaie #+# #+# */
/* Updated: 2018/01/11 22:25:13 by mbiliaie ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
char *ft_reader(char **ar)
{
size_t tmp;
size_t i;
char *input;
int fd;
char buff;
tmp = 0;
i = 0;
fd = open(ar[1], O_RDONLY);
if (fd < 0)
return (NULL);
while (read(fd, &buff, 1))
tmp++;
if ((input = (char*)malloc(sizeof(char) * tmp + 1)) == NULL)
return (0);
(void)ft_memset((void*)input, '\0', sizeof(char) * tmp + 1);
close(fd);
fd = open(ar[1], O_RDONLY);
while (read(fd, &buff, 1))
*(input + i++) = buff;
close(fd);
return (input);
}