-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnstr_fd.c
30 lines (27 loc) · 1.18 KB
/
ft_putnstr_fd.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ldulling <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/22 19:26:30 by ldulling #+# #+# */
/* Updated: 2023/10/22 19:26:31 by ldulling ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
size_t ft_putnstr_fd(const char *s, size_t n, int fd)
{
size_t len;
ssize_t written;
written = 0;
if (s == NULL || n == 0 || fd < 0)
return (0);
len = ft_strlen(s);
if (len > n)
len = n;
written += write(fd, s, len);
if (written < 0)
written = 0;
return ((size_t) written);
}