Blame alsamixer/mem.c

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