aboutsummaryrefslogtreecommitdiff
path: root/src/util_rt.h
blob: 3320566c2462ad786e0d0c571f6ca6982c664e4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include "pack.h"

#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include <time.h>

#include <mbedtls/ctr_drbg.h>


struct prne_stdin_base64_rf_ctx;
typedef struct prne_stdin_base64_rf_ctx prne_stdin_base64_rf_ctx_t;

struct prne_stdin_base64_rf_ctx {
	size_t line_len;
	size_t out_len;
	char line_buf[78];
	uint8_t out_buf[58];
};


#if 0
bool prne_strendsw (const char *str, const char *w) {
	const size_t len_str = strlen(str);
	const size_t len_w = strlen(w);

	if (len_str < len_w) {
		return false;
	}
	return strcmp(str + (len_str - len_w), w) == 0;
}
#endif

void prne_ok_or_die (const int ret);
void prne_true_or_die (const bool ret);
void prne_empty_func (void);
bool prne_is_nonblock_errno (void);
void prne_die_not_nonblock_err (void);
void prne_close (const int fd);
void prne_shutdown (const int fd, const int how);

void *prne_malloc (const size_t se, const size_t cnt);
void *prne_realloc (void *ptr, const size_t se, const size_t cnt);
void *prne_calloc (const size_t se, const size_t cnt);
void prne_free (void *ptr);
size_t prne_getpagesize (void);

void prne_rnd_anum_str (mbedtls_ctr_drbg_context *rnd, char *str, const size_t len);
char *prne_strnchr (const char *p, const char c, const size_t n);
size_t prne_str_shift_spaces (char *str, const size_t len);

struct timespec prne_sub_timespec (const struct timespec a, const struct timespec b);
double prne_real_timespec (const struct timespec ts);
int prne_cmp_timespec (const struct timespec a, const struct timespec b);
struct timespec prne_min_timespec (const struct timespec a, const struct timespec b);
struct timespec prne_max_timespec (const struct timespec a, const struct timespec b);

char *prne_enc_base64_mem (const uint8_t *data, const size_t size);
bool prne_dec_base64_mem (const char *str, const size_t str_len, uint8_t **data, size_t *size);
void prne_init_stdin_base64_rf_ctx (prne_stdin_base64_rf_ctx_t *ctx);
void prne_free_stdin_base64_rf_ctx (prne_stdin_base64_rf_ctx_t *ctx);
prne_pack_ret_t prne_stdin_base64_rf (void *ctx, const size_t req, uint8_t *out, size_t *out_len);

bool prne_set_pipe_size (const int fd, const int size);