aboutsummaryrefslogtreecommitdiff
#include <stdlib.h>
#include <stdio.h>

#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;
}