]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/hexdecoct.h
319b21a17c658d704ac36da111895fa2d01503d5
[thirdparty/systemd.git] / src / basic / hexdecoct.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <stdbool.h>
5 #include <stddef.h>
6 #include <stdio.h>
7 #include <sys/types.h>
8
9 #include "macro.h"
10
11 char octchar(int x) _const_;
12 int unoctchar(char c) _const_;
13
14 char decchar(int x) _const_;
15 int undecchar(char c) _const_;
16
17 char hexchar(int x) _const_;
18 int unhexchar(char c) _const_;
19
20 char *hexmem(const void *p, size_t l);
21 int unhexmem_full(const char *p, size_t l, bool secure, void **mem, size_t *len);
22 static inline int unhexmem(const char *p, size_t l, void **mem, size_t *len) {
23 return unhexmem_full(p, l, false, mem, len);
24 }
25
26 char base32hexchar(int x) _const_;
27 int unbase32hexchar(char c) _const_;
28
29 char base64char(int x) _const_;
30 char urlsafe_base64char(int x) _const_;
31 int unbase64char(char c) _const_;
32
33 char *base32hexmem(const void *p, size_t l, bool padding);
34 int unbase32hexmem(const char *p, size_t l, bool padding, void **mem, size_t *len);
35
36 ssize_t base64mem_full(const void *p, size_t l, size_t line_break, char **ret);
37 static inline ssize_t base64mem(const void *p, size_t l, char **ret) {
38 return base64mem_full(p, l, SIZE_MAX, ret);
39 }
40
41 ssize_t base64_append(
42 char **prefix,
43 size_t plen,
44 const void *p,
45 size_t l,
46 size_t margin,
47 size_t width);
48 int unbase64mem_full(const char *p, size_t l, bool secure, void **mem, size_t *len);
49 static inline int unbase64mem(const char *p, size_t l, void **mem, size_t *len) {
50 return unbase64mem_full(p, l, false, mem, len);
51 }
52
53 void hexdump(FILE *f, const void *p, size_t s);