From aa4d426b4d3527d7e166df1a05058c9a4a0f6683 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Fri, 30 Apr 2021 00:33:56 +0200 Subject: initial/final commit --- misc.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 misc.c (limited to 'misc.c') diff --git a/misc.c b/misc.c new file mode 100644 index 0000000..e73b903 --- /dev/null +++ b/misc.c @@ -0,0 +1,68 @@ +#include +#include + +#include "utilities.h" + +void _finish(bool ok) +{ + puts(ok ? "\nOk. " : "\nBlad. "); + exit(ok ? 0 : -1); +} + +void *dirtyalloc(size_t size) +{ + void *memory = malloc(size); + + if (memory == NULL) + FAIL(MSG_MALLOC_FAIL); + + return memory; +} + +/* Used to suppress stderr output of iniparser library */ +int dummy_errback(const char *fmt, ...) +{ + return 1; +} + +/* + * I had to deal with UTF-16 config files. Since mostly the ASCII characters + * are used anyway, I decided to just pick every second byte of the file and + * got this semi-working... This IS provisional. + */ +int provisional_wide_char_fgetc(FILE *stream) +{ + int c = 128; + + while (c > 127) { + c = getc(stream); + getc(stream); + + if (c == EOF) + return EOF; + } + + return c; +} + +bool is_valid_port_number(int port) +{ + return port >= 0 && port <= 65535; +} + +/* + * Different implementations if validate_config() and perform_work() + * are supplied in pop and push programs. + */ +int main(int argc, const char **argv) +{ + struct config config; + + get_config(argc, argv, &config); + validate_config(&config); + perform_work(&config); + /* actually, this won't be reached, because perform_work exit()s... */ + free_config(&config); + + return 0; +} -- cgit v1.2.3