Small code clean-up + improved the Makefile + detect GNU/Hurd operating system.
[slunkcrypt.git] / frontend / src / utils.h
bloba857aa139e426b915fe9aa9146e4d85429514079
1 /******************************************************************************/
2 /* SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de> */
3 /* This work has been released under the CC0 1.0 Universal license! */
4 /******************************************************************************/
6 #ifndef INC_SLUNKAPP_UTILS_H
7 #define INC_SLUNKAPP_UTILS_H
9 #include "platform.h"
10 #include <stdint.h>
12 typedef void (signal_handler_t)(int);
14 void init_terminal(void);
15 void setup_signal_handler(const int signo, signal_handler_t* const handler);
17 uint64_t clock_freq(void);
18 uint64_t clock_read(void);
20 void store_ui64(uint8_t* const dst, const uint64_t value);
21 uint64_t load_ui64(const uint8_t* const src);
22 size_t fwrite_ui64(const uint64_t value, FILE *const stream);
23 size_t fread_ui64(uint64_t *const value, FILE *const stream);
25 char* CHR_to_utf8(const CHR *const input);
27 int same_file(const CHR*const path0, const CHR*const path1);
28 uint64_t get_size(FILE *const file);
29 const CHR *get_file_name(const CHR *path);
31 uint64_t round_down(const uint64_t value, const uint64_t base);
33 #define ARRAY_SIZE(X) (sizeof((X)) / sizeof(*(X)))
34 #define BOUND(MIN,VAL,MAX) (((VAL) < (MIN)) ? (MIN) : (((VAL) > (MAX)) ? (MAX) : (VAL)))
35 #define STARTS_WITH(X,Y) (!STRNICMP((X), (Y), STRLEN((Y))))
36 #define GET_LOWBITS(X) ((X) & 0x07)
37 #define SET_LOWBITS(X,Y) do { X = ((X) & 0xF8) | ((Y) & 0x07); } while(0)
39 #endif