Ripples 1.0
High Performant Software Architecture For Transaction Processing
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1
31#ifndef UTILS_H
32#define UTILS_H
33
34#include <arpa/inet.h>
35#include <assert.h>
36#include <ctype.h>
37#include <stdbool.h>
38#include <stddef.h>
39#include <stdlib.h>
40#include <stdint.h>
41#include <string.h>
42#include <string.h>
43#include <sys/socket.h>
44#include <time.h>
45
46#ifdef DEBUG
50#define DEBUG_TEST 1
51#else
55#define DEBUG_TEST 0
56#endif
57
59#define TIME_RFC3339_STRLEN 31
60
64#define debug() \
65 do { if (DEBUG_TEST) fprintf(stderr, "%s:%d:%s(): \n", __FILE__, \
66 __LINE__, __func__); } while (0)
67
74#define debug_print(str) \
75 do { if (DEBUG_TEST) fprintf(stderr, "%s:%d:%s(): " str "\n", __FILE__, \
76 __LINE__, __func__); } while (0)
77
88#define debug_printf(fmt, ...) \
89 do { if (DEBUG_TEST) fprintf(stderr, "%s:%d:%s(): " fmt "\n", __FILE__, \
90 __LINE__, __func__, __VA_ARGS__); } while (0)
91
93#define ARRAY_COUNT(a) sizeof(a) / sizeof(a[0])
94
98#define CHECK_MALLOC(a) do { \
99 if((a) == NULL) { \
100 assert(0); \
101 } } while (0)
102
104#define INCREMENT(a) a += 1
105
107#define DECREMENT(a) a -= 1
108
109
110int utl_ip_port_from_ss(char *ip, size_t ip_len, uint16_t *port, struct sockaddr_storage *ss);
111
112double utl_diff_timespec_as_double(const struct timespec *t1, const struct timespec *t2);
113void utl_diff_timespec(struct timespec *dst, const struct timespec *t1, const struct timespec *t2);
114
115void char_to_lc(char *c);
116void str_to_lc(uint8_t *str, size_t str_len);
117
118bool str_is_numeric(uint8_t *str, size_t str_len);
119
120int str_to_unsigned_long(unsigned long *dst, char *str);
121
122int str_to_bool(bool *dst, char *str);
123
124int parse_csv_to_ul_array(size_t *ul_array, size_t ul_array_len, char *str);
125
126int sockaddr_storage_to_string(char *buf, size_t buf_len, struct sockaddr_storage *ss);
127
128int utl_readall(int fd, size_t size, void **buf, char *err, size_t err_len);
129int utl_writeall(int fd, void *buf, size_t buf_len, char *err, size_t err_len);
130
131int utl_timespec_to_rfc3339nano(struct timespec *ts, char *buf);
132
133void utl_clock_gettime_rt_fatal(struct timespec *tp);
134
135#endif /* UTILS_H */
136
int sockaddr_storage_to_string(char *buf, size_t buf_len, struct sockaddr_storage *ss)
Definition utils.c:288
void utl_clock_gettime_rt_fatal(struct timespec *tp)
Definition utils.c:446
int utl_writeall(int fd, void *buf, size_t buf_len, char *err, size_t err_len)
Definition utils.c:388
int utl_ip_port_from_ss(char *ip, size_t ip_len, uint16_t *port, struct sockaddr_storage *ss)
Definition utils.c:47
int parse_csv_to_ul_array(size_t *ul_array, size_t ul_array_len, char *str)
Definition utils.c:237
int utl_timespec_to_rfc3339nano(struct timespec *ts, char *buf)
Definition utils.c:429
int utl_readall(int fd, size_t size, void **buf, char *err, size_t err_len)
Definition utils.c:333
bool str_is_numeric(uint8_t *str, size_t str_len)
Definition utils.c:147
void utl_diff_timespec(struct timespec *dst, const struct timespec *t1, const struct timespec *t2)
Definition utils.c:85
void str_to_lc(uint8_t *str, size_t str_len)
Definition utils.c:133
int str_to_unsigned_long(unsigned long *dst, char *str)
Definition utils.c:167
double utl_diff_timespec_as_double(const struct timespec *t1, const struct timespec *t2)
Definition utils.c:107
void char_to_lc(char *c)
Definition utils.c:119
int str_to_bool(bool *dst, char *str)
Definition utils.c:199