-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_io2.c
59 lines (51 loc) · 1.52 KB
/
ft_io2.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_io2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lgillot- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/19 01:31:06 by lgillot- #+# #+# */
/* Updated: 2015/11/19 01:35:32 by lgillot- ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
#include <unistd.h>
#include <ft_io.h>
void ft_putendl_fd(char const *s, int fd)
{
ft_putstr_fd(s, fd);
ft_putchar_fd('\n', fd);
}
void ft_putendl(char const *s)
{
ft_putendl_fd(s, 1);
}
t_err ft_fread(int fd, void *buf, size_t len)
{
size_t done;
ssize_t ret;
done = 0;
while (done < len)
{
ret = read(fd, buf + done, len - done);
if (ret <= 0)
return (ERR);
done += ret;
}
return (OK);
}
t_err ft_fwrite(int fd, const void *buf, size_t len)
{
size_t done;
ssize_t ret;
done = 0;
while (done < len)
{
ret = write(fd, buf + done, len - done);
if (ret <= 0)
return (ERR);
done += ret;
}
return (OK);
}