swim.git

util.c

espurr
/* swim - window manager
 * Copyright (C) 2022-2023 ArcNyxx
 * see LICENCE file for licensing information */

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "util.h"

void
die(const char *fmt, ...)
{
	va_list list;
	va_start(list, fmt);
	vfprintf(stderr, fmt, list);
	va_end(list);

	if (fmt[strlen(fmt) - 1] != '\n')
		perror(NULL);
	exit(1);
}

void *
srealloc(void *ptr, size_t size)
{
	if ((ptr = realloc(ptr, size)) == NULL)
		die("swim: unable to allocate memory: ");
	return ptr;
}