minishell
ft_printf.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* ft_printf.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: kfujita <kfujita@student.42tokyo.jp> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2022/04/22 21:58:25 by kfujita #+# #+# */
9 /* Updated: 2023/02/09 00:16:18 by kfujita ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include <unistd.h>
14 #include <stdlib.h>
15 #include "ft_printf.h"
16 #include "ft_printf_local.h"
17 
18 int ft_printf(const char *format, ...)
19 {
20  va_list args;
21  int written_count;
22 
23  va_start(args, format);
24  written_count = ft_vprintf(format, &args);
25  va_end(args);
26  return (written_count);
27 }
28 
29 int ft_dprintf(int fd, const char *format, ...)
30 {
31  va_list args;
32  int written_count;
33 
34  va_start(args, format);
35  written_count = ft_vdprintf(fd, format, &args);
36  va_end(args);
37  return (written_count);
38 }
39 
40 int ft_vprintf(const char *format, va_list *args)
41 {
42  return (ft_vdprintf(STDOUT_FILENO, format, args));
43 }
44 
45 int ft_vdprintf(int fd, const char *format, va_list *args)
46 {
47  t_list *list;
48  int written_count;
49 
50  if (*format == '\0')
51  return (0);
52  else if (format[0] != '%' && format[1] == '\0')
53  return (write(fd, format, 1));
54  list = parse_format(format, args);
55  if (list == NULL)
56  return (-1);
57  written_count = print_all(fd, list);
58  ft_lstclear(&list, free);
59  return (written_count);
60 }
void ft_lstclear(t_list **lst, void(*del)(void *))
Definition: ft_lstclear.c:16
int ft_printf(const char *format,...)
Definition: ft_printf.c:18
int ft_vprintf(const char *format, va_list *args)
Definition: ft_printf.c:40
int ft_dprintf(int fd, const char *format,...)
Definition: ft_printf.c:29
int ft_vdprintf(int fd, const char *format, va_list *args)
Definition: ft_printf.c:45
int print_all(int fd, t_list *list)
Definition: print_all.c:106
t_list * parse_format(const char *fmt, va_list *args)
Definition: parse_format.c:18
Definition: ft_lst.h:18