-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putstr.c
38 lines (34 loc) · 1.35 KB
/
ft_putstr.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tunsal <tunsal@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/22 14:05:10 by tunsal #+# #+# */
/* Updated: 2023/11/11 20:52:53 by tunsal ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
/*
Print a string to the standard out and return number of characters printed.
Print "(null)" and return 6 if the string is NULL.
Return -1 if write fails or upon any error.
*/
int ft_putstr(char *s)
{
ssize_t ret;
size_t s_len;
if (s == NULL)
{
ret = write(STDOUT_FD, "(null)", 6);
if (ret != 6)
return (-1);
return (ret);
}
s_len = ft_strlen(s);
ret = write(STDOUT_FD, s, s_len);
if (ret != (ssize_t) s_len)
return (-1);
return (ret);
}