diff options
author | David Timber <mieabby@gmail.com> | 2020-08-17 18:16:49 +0930 |
---|---|---|
committer | David Timber <mieabby@gmail.com> | 2020-08-17 18:35:31 +0930 |
commit | 7bd3eb3b1ad4209ac4cf4b46f849213d46bc33aa (patch) | |
tree | 0e7a16fb3d36ada8a2a494f8dc063e8b67350d58 /src/util_rt.c | |
parent | d7cc11191dfd3fead5e596fcbc24f40d1317819e (diff) |
Employ pthsem ...
* Use uint8_t array for hardcoded binary data
* Add proone-ipaddr-arr to hardcode DoT servers
* Convert X509 data
* Brought back M68k and ARC archs just in case
* Add CLOCK_REALTIME in prne_mbedtls_entropy_proc_src_f for more entropy
* Remove installation of signal handlers. Use sigwait() instead
* Bugfix: prne_rnd_anum_str() returned null characters
* Add prne_dbgpf() and prne_dbgperr()
* prne_assert(): put errno into a register so it's visible in the core dump
Diffstat (limited to 'src/util_rt.c')
-rw-r--r-- | src/util_rt.c | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/src/util_rt.c b/src/util_rt.c index cdf4526..d42cc7d 100644 --- a/src/util_rt.c +++ b/src/util_rt.c @@ -4,6 +4,7 @@ #include <stdlib.h> #include <string.h> #include <ctype.h> +#include <time.h> #include <errno.h> #include <unistd.h> @@ -12,41 +13,20 @@ #include <sys/socket.h> #include <mbedtls/base64.h> +#include <pthsem.h> -void prne_ok_or_die (const int ret) { - if (ret < 0) { - abort(); - } -} - -void prne_true_or_die (const bool ret) { +void prne_assert (const bool ret) { if (!ret) { - abort(); - } -} + volatile const int err = errno; -void prne_empty_func (void) {} - -bool prne_is_nonblock_errno (void) { - switch (errno) { -#if EAGAIN == EWOULDBLOCK - case EAGAIN: -#else - case EAGAIN: - case EWOULDBLOCK: -#endif - case EINPROGRESS: - return true; + if (true || err) { + abort(); + } } - return false; } -void prne_die_not_nonblock_err (void) { - if (!prne_is_nonblock_errno()) { - abort(); - } -} +void prne_empty_func (void) {} void prne_close (const int fd) { if (fd >= 0) { @@ -146,7 +126,7 @@ size_t prne_nstrlen (const char *s) { } void prne_rnd_anum_str (mbedtls_ctr_drbg_context *rnd, char *str, const size_t len) { - static const char SET[] = "qwertyuiopasdfghjklzxcvbnm0123456789"; + static const char SET[] = { 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; size_t i = 0; uint32_t n; @@ -339,6 +319,12 @@ struct timespec prne_max_timespec (const struct timespec a, const struct timespe return prne_cmp_timespec(a, b) > 0 ? a : b; } +struct timespec prne_gettime (const clockid_t cid) { + struct timespec ret; + prne_assert(clock_gettime(cid, &ret) == 0); + return ret; +} + char *prne_enc_base64_mem (const uint8_t *data, const size_t size) { size_t ret_size; char *ret; |