dte test coverage


Directory: ./
File: src/util/numtostr.h
Date: 2025-06-04 06:50:24
Exec Total Coverage
Lines: 4 4 100.0%
Functions: 1 1 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 #ifndef UTIL_NUMTOSTR_H
2 #define UTIL_NUMTOSTR_H
3
4 #include <stddef.h>
5 #include <stdint.h>
6 #include <sys/types.h>
7 #include "macros.h"
8
9 enum {
10 HRSIZE_MAX = DECIMAL_STR_MAX(uintmax_t) + STRLEN(".99 GiB"),
11 FILESIZE_STR_MAX = HRSIZE_MAX + DECIMAL_STR_MAX(uintmax_t) + STRLEN(" ()"),
12 PRECISE_FILESIZE_STR_MAX = DECIMAL_STR_MAX(uintmax_t) + STRLEN("GiB"),
13 };
14
15 extern const char hextab_lower[16];
16 extern const char hextab_upper[16];
17
18 // Encodes a byte of data as 2 hexadecimal digits
19 45 static inline size_t hex_encode_byte(char out[2], uint8_t byte)
20 {
21 45 out[0] = hextab_lower[byte >> 4];
22 45 out[1] = hextab_lower[byte & 0xF];
23 45 return 2;
24 }
25
26 size_t buf_umax_to_str(uintmax_t x, char *buf) NONNULL_ARGS;
27 size_t buf_umax_to_hex_str(uintmax_t x, char *buf, size_t min_digits) NONNULL_ARGS;
28 size_t buf_uint_to_str(unsigned int x, char *buf) NONNULL_ARGS;
29 size_t buf_u8_to_str(uint8_t x, char *buf) NONNULL_ARGS;
30 const char *umax_to_str(uintmax_t x) RETURNS_NONNULL;
31 const char *uint_to_str(unsigned int x) RETURNS_NONNULL;
32 const char *ulong_to_str(unsigned long x) RETURNS_NONNULL;
33 char *file_permissions_to_str(mode_t mode, char buf[10]) NONNULL_ARGS_AND_RETURN;
34 char *human_readable_size(uintmax_t bytes, char buf[HRSIZE_MAX]) NONNULL_ARGS_AND_RETURN;
35 char *filesize_to_str(uintmax_t bytes, char buf[FILESIZE_STR_MAX]) NONNULL_ARGS_AND_RETURN;
36 char *filesize_to_str_precise(uintmax_t bytes, char buf[PRECISE_FILESIZE_STR_MAX]) NONNULL_ARGS_AND_RETURN;
37
38 #endif
39