dprintf_ascii.c
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* dprintf_ascii.c :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: ll-hotel <ll-hotel@student.42lyon.fr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2024/02/15 12:51:53 by ll-hotel #+# #+# */ 9 /* Updated: 2024/04/24 16:20:41 by ll-hotel ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #include "dprintf_inner.h" 14 15 int32_t ft_char(t_buffer *buffer, int fd, char c) 16 { 17 if (buffer->length[fd] >= DPRINTF_BUFFERSIZE) 18 ft_buffer_flush(buffer, fd); 19 buffer->string[fd][(buffer->length[fd])++] = c; 20 if (c == '\n') 21 ft_buffer_flush(buffer, fd); 22 return (1); 23 } 24 25 int ft_string(t_buffer *buffer, int fd, char *str) 26 { 27 if (!str) 28 return (ft_buffer_cat(buffer, fd, "(null)")); 29 return (ft_buffer_cat(buffer, fd, str)); 30 } 31 32 int ft_pointer(char *out, t_buffer *buffer, int fd, uint64_t p) 33 { 34 if (!p) 35 return (ft_buffer_cat(buffer, fd, "(nil)")); 36 ft_atoui64(out, (uint64_t)p, "0123456789abcdef", 16); 37 return (ft_buffer_cat(buffer, fd, "0x")); 38 }