diff options
Diffstat (limited to 'src/util_rt.c')
-rw-r--r-- | src/util_rt.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/util_rt.c b/src/util_rt.c index 8a1e61b..24e924d 100644 --- a/src/util_rt.c +++ b/src/util_rt.c @@ -29,6 +29,31 @@ void prne_shutdown (const int fd, const int how) { } } +bool prne_sck_fcntl (const int fd) { + fcntl(fd, F_SETFD, FD_CLOEXEC); + return fcntl(fd, F_SETFL, O_NONBLOCK) == 0; +} + +int prne_chfd (const int old, const int ny) { + int ret; + + if (old == ny) { + return old; + } + + ret = dup2(old, ny); + if (ret < 0) { + return ret; + } + close(old); + + return ret; +} + +void prne_memzero(void *addr, const size_t len) { + memset(addr, 0, len); +} + void *prne_malloc (const size_t se, const size_t cnt) { size_t size; @@ -164,6 +189,12 @@ size_t prne_str_shift_spaces (char *str, const size_t len) { return ret; } +void prne_transstr (char *str, int(*trans_f)(int)) { + for (; *str != 0; str += 1) { + *str = (char)trans_f(*str); + } +} + bool prne_hex_fromstr (const char *str, uint_fast8_t *out) { static const uint_fast8_t shift[2] = { 4, 0 }; size_t i; |