Blame alsamixer/mem.c

Packit 229ac0
/*
Packit 229ac0
 * mem.c - memory allocation checkers
Packit 229ac0
 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
Packit 229ac0
 *
Packit 229ac0
 * This program is free software: you can redistribute it and/or modify
Packit 229ac0
 * it under the terms of the GNU General Public License as published by
Packit 229ac0
 * the Free Software Foundation, either version 2 of the License, or
Packit 229ac0
 * (at your option) any later version.
Packit 229ac0
 *
Packit 229ac0
 * This program is distributed in the hope that it will be useful,
Packit 229ac0
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 229ac0
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 229ac0
 * GNU General Public License for more details.
Packit 229ac0
 *
Packit 229ac0
 * You should have received a copy of the GNU General Public License
Packit 229ac0
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 229ac0
 */
Packit 229ac0
Packit 229ac0
#include "aconfig.h"
Packit 229ac0
#include <stdio.h>
Packit 229ac0
#include <stdlib.h>
Packit 229ac0
#include <stdarg.h>
Packit 229ac0
#include <string.h>
Packit 229ac0
#include <errno.h>
Packit 229ac0
#include "die.h"
Packit 229ac0
#include "mem.h"
Packit 229ac0
Packit 229ac0
static void check(void *p)
Packit 229ac0
{
Packit 229ac0
	if (!p)
Packit 229ac0
		fatal_error("out of memory");
Packit 229ac0
}
Packit 229ac0
Packit 229ac0
void *ccalloc(size_t n, size_t size)
Packit 229ac0
{
Packit 229ac0
	void *mem = calloc(n, size);
Packit 229ac0
	if (n && size)
Packit 229ac0
		check(mem);
Packit 229ac0
	return mem;
Packit 229ac0
}
Packit 229ac0
Packit 229ac0
void *crealloc(void *ptr, size_t new_size)
Packit 229ac0
{
Packit 229ac0
	ptr = realloc(ptr, new_size);
Packit 229ac0
	if (new_size)
Packit 229ac0
		check(ptr);
Packit 229ac0
	return ptr;
Packit 229ac0
}
Packit 229ac0
Packit 229ac0
char *cstrdup(const char *s)
Packit 229ac0
{
Packit 229ac0
	char *str = strdup(s);
Packit 229ac0
	check(str);
Packit 229ac0
	return str;
Packit 229ac0
}
Packit 229ac0
Packit 229ac0
char *casprintf(const char *fmt, ...)
Packit 229ac0
{
Packit 229ac0
	va_list ap;
Packit 229ac0
	char *str;
Packit 229ac0
Packit 229ac0
	va_start(ap, fmt);
Packit 229ac0
	if (vasprintf(&str, fmt, ap) < 0)
Packit 229ac0
		check(NULL);
Packit 229ac0
	va_end(ap);
Packit 229ac0
	return str;
Packit 229ac0
}