tgrekov-fdf
HIVE fdf May 2024
Loading...
Searching...
No Matches
u_print_base.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* u_print_base.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/02/02 02:31:45 by tgrekov #+# #+# */
9/* Updated: 2024/04/26 10:30:07 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#include <unistd.h>
21#include "../../sequence.h"
22#include "../../../utils/utils.h"
23#include "../../../utils/internal_types.h"
24#include "../../../../../../libft.h"
25
35int u_print_base(t_sequence seq, int fd, char *base)
36{
37 int res;
38
39 res = 0;
40 if (seq.subspec.precision > 0
41 && !wrap_err(repeat_str_n("0000000000", seq.subspec.precision
42 - u_len_base(seq.data, ft_strlen(base)), fd), &res))
43 return (-1);
44 if (!seq.subspec.precision && !seq.data)
45 return (0);
46 wrap_err(u_put_base(seq.data, base, fd), &res);
47 return (res);
48}
int u_len_base(t_ubiggest n, int base)
Determine the length of unsigned number n in base base.
Definition u_len_base.c:29
int u_put_base(t_ubiggest n, char *base, int fd)
Write unsigned number n on descriptor fd in base base.
Definition u_put_base.c:49
int wrap_err(int n, int *total)
Wrapper for handling functions that return a positive integer on success and -1 on failure....
Definition wrap_err.c:29
size_t ft_strlen(const char *str)
Get length of str.
Definition ft_strlen.c:28
int repeat_str_n(const char *str, int n, int fd)
Write exactly n characters from str on descriptor fd. Repeats string if ft_strlen(str) is greater tha...
Holds information regarding the current format specifier sequence.
Definition sequence.h:49
t_ubiggest data
Retrieved variable argument.
Definition sequence.h:53
t_subspec subspec
Holds subspecifier options for a format specifier.
Definition sequence.h:51
int precision
Minimum number of digits to be printed, or maximum characters for strings.
Definition subspec.h:71
int u_print_base(t_sequence seq, int fd, char *base)
Writes an unsigned integer in base base on descriptor fd, with respect to the s_subspec::precision.