-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf.c
49 lines (44 loc) · 1.57 KB
/
ft_printf.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jraymond <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/10 13:47:15 by jraymond #+# #+# */
/* Updated: 2018/05/02 19:42:29 by jraymond ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_printf(const char *format, ...)
{
va_list ap;
t_printf elem;
ft_bzero(&elem, sizeof(t_printf));
va_start(ap, format);
if (ft_read_format(format, ap, &elem) == -1)
return (-1);
write(1, elem.buff, elem.i_buff);
elem.ret += elem.i_buff;
va_end(ap);
if (elem.ret == 0)
return (elem.i_buff);
else
return (elem.ret);
}
int ft_dprintf(int fd, const char *format, ...)
{
va_list ap;
t_printf elem;
ft_bzero(&elem, sizeof(t_printf));
va_start(ap, format);
if (ft_read_format(format, ap, &elem) == -1)
return (-1);
write(fd, elem.buff, elem.i_buff);
elem.ret += elem.i_buff;
va_end(ap);
if (elem.ret == 0)
return (elem.i_buff);
else
return (elem.ret);
}