diff options
Diffstat (limited to 'src/util_rt.c')
-rw-r--r-- | src/util_rt.c | 68 |
1 files changed, 2 insertions, 66 deletions
diff --git a/src/util_rt.c b/src/util_rt.c index d42cc7d..6d44f52 100644 --- a/src/util_rt.c +++ b/src/util_rt.c @@ -1,6 +1,5 @@ #include "util_rt.h" -#include <stdio.h> // TODO: remove dep #include <stdlib.h> #include <string.h> #include <ctype.h> @@ -16,16 +15,6 @@ #include <pthsem.h> -void prne_assert (const bool ret) { - if (!ret) { - volatile const int err = errno; - - if (true || err) { - abort(); - } - } -} - void prne_empty_func (void) {} void prne_close (const int fd) { @@ -104,11 +93,9 @@ size_t prne_getpagesize (void) { long ret; ret = sysconf(_SC_PAGESIZE); - if (ret > 0) { - return ret; - } + prne_massert(ret > 0, "sysconf(_SC_PAGESIZE) failed."); - return 4096; + return (size_t)ret; } bool prne_nstreq (const char *a, const char *b) { @@ -372,57 +359,6 @@ bool prne_dec_base64_mem (const char *str, const size_t str_len, uint8_t **data, return true; } -void prne_init_stdin_base64_rf_ctx (prne_stdin_base64_rf_ctx_t *ctx) { - ctx->line_len = 0; - ctx->out_len = 0; -} - -void prne_free_stdin_base64_rf_ctx (prne_stdin_base64_rf_ctx_t *ctx) { - ctx->line_len = 0; - ctx->out_len = 0; -} - -prne_pack_ret_t prne_stdin_base64_rf (void *in_ctx, const size_t req, uint8_t *out, size_t *out_len) { - prne_stdin_base64_rf_ctx_t *ctx = (prne_stdin_base64_rf_ctx_t*)in_ctx; - size_t rem = req, have; - prne_pack_ret_t ret; - - ret.rc = PRNE_PACK_RC_OK; - ret.err = 0; - *out_len = 0; - - while (true) { - have = prne_op_min(rem, ctx->out_len); - memcpy(out, ctx->out_buf, have); - memmove(ctx->out_buf, ctx->out_buf + have, ctx->out_len - have); - rem -= have; - ctx->out_len -= have; - out += have; - *out_len += have; - - if (rem == 0) { - break; - } - - if (fgets(ctx->line_buf, sizeof(ctx->line_buf), stdin) == NULL) { - if (feof(stdin)) { - break; - } - ret.rc = PRNE_PACK_RC_ERRNO; - ret.err = errno; - break; - } - ctx->line_len = prne_str_shift_spaces(ctx->line_buf, strlen(ctx->line_buf)); - - if ((ret.err = mbedtls_base64_decode(ctx->out_buf, sizeof(ctx->out_buf), &ctx->out_len, (unsigned char*)ctx->line_buf, ctx->line_len)) != 0) { - ret.rc = PRNE_PACK_RC_MBEDTLS_ERR; - break; - } - } - - return ret; -} - bool prne_set_pipe_size (const int fd, const int size) { return #if defined(F_SETPIPE_SZ) |