-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.nfs.20051027.39b1
51 lines (48 loc) · 1.66 KB
/
.nfs.20051027.39b1
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
42
43
44
45
46
47
48
49
50
51
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ssalaues <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/23 16:32:08 by ssalaues #+# #+# */
/* Updated: 2017/01/10 10:04:41 by ssalaues ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
static char *ft_strndup(const char *s1, size_t n)
{
char *dup;
dup = (char *)malloc(sizeof(char) * (n + 1));
if (!dup)
return (NULL);
else
ft_strncpy(dup, s1, n);
return (dup);
}
int get_next_line(const int fd, char **line)
{
char t1[BUFF_SIZE + 1];
size_t bs = 0;
int ct = 0;
static t_list *rdin;
ft_bzero(t1, BUFF_SIZE + 1);
while((bs = read(fd, t1, BUFF_SIZE)))
{
if (ct == 0)
rdin = ft_lstnew((char*)t1, bs + 1);
else
{
free(rdin->content);
rdin = ft_lstnew(ft_strncat(rdin->content, t1, ft_wordlen(t1, '\n')), ft_strlen(rdin->content) + ft_wordlen(t1, '\n'));
}
if (ft_strchr(t1, '\n'))
{
*line = ft_strndup(rdin->content, ft_wordlen(rdin->content, '\n'));
free(rdin->content);
return (1);
}
ct++;
}
return (0);
}