Add remaining documentation
[libcontrac.git] / include / contrac / utils.h
1 /** \ingroup Utils
2 * @file
3 * @author David Llewellyn-Jones <david@flypig.co.uk>
4 * @version $(VERSION)
5 *
6 * @section LICENSE
7 *
8 * Copyright David Llewellyn-Jones, 2020
9 * Released under the GPLv2.
10 *
11 * @brief Static utility functions
12 * @section DESCRIPTION
13 *
14 * Provides various static utitlity functions. In particular:
15 *
16 * base64 encoding and decoding functionality.
17 * Time conversion: from epoch to day numbers and time interval numbers.
18 *
19 */
20
21 /** \addtogroup Utils
22 * @{
23 */
24
25 #ifndef __UTILS_H
26 #define __UTILS_H
27
28 // Includes
29
30 #include <time.h>
31
32 // Defines
33
34 #define MAX(a,b) \
35 ({ __typeof__ (a) _a = (a); \
36 __typeof__ (b) _b = (b); \
37 _a > _b ? _a : _b; })
38
39 #define MIN(a,b) \
40 ({ __typeof__ (a) _a = (a); \
41 __typeof__ (b) _b = (b); \
42 _a < _b ? _a : _b; })
43
44 // Structures
45
46 // Function prototypes
47
48 size_t base64_encode_size(size_t binary_input);
49 size_t base64_decode_size(size_t base64_input);
50 void base64_encode_binary_to_base64(unsigned char const *input, size_t input_size, unsigned char *output, size_t *output_size);
51 void base64_decode_base64_to_binary(unsigned char const *input, size_t input_size, unsigned char *output, size_t *output_size);
52
53 uint32_t epoch_to_day_number(time_t epoch);
54 uint8_t epoch_to_time_interval_number(time_t epoch);
55
56 // Function definitions
57
58 #endif // __UTILS_H
59
60 /** @} addtogroup Utils */
61