-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line.c
40 lines (37 loc) · 1.55 KB
/
get_next_line.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jeongble <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/06 21:34:05 by jeongble #+# #+# */
/* Updated: 2022/07/22 09:53:38 by jeongble ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
char *get_next_line(int fd)
{
static t_info2 info = {"", 0, BUFFER_SIZE, 0, 0};
char *str;
if (fd_error(fd, &str, &info))
return (0);
while (1)
{
if (info.sol == BUFFER_SIZE)
{
buf_join(&str, info.buf + BUFFER_SIZE - (info.new), &info, 0);
info.success = read(fd, info.buf, BUFFER_SIZE);
if (buf_end(&str, &info))
return (str);
info.sol = 0;
}
if (info.success < BUFFER_SIZE && info.sol == (size_t)info.success)
return (buf_join(&str, info.buf + info.sol - info.new, &info, 1));
if (info.buf[info.sol] == '\n')
return (buf_join(&str, info.buf + info.sol - info.new, &info, 2));
info.sol ++;
info.new ++;
}
return (str);
}