You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
// Copyright (c) Vitaliy Filippov, 2019+
|
|
|
|
// License: VNPL-1.0 or GNU GPL-2.0+ (see README.md for details)
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
inline void* memalign_or_die(size_t alignment, size_t size)
|
|
|
|
{
|
|
|
|
void *buf = memalign(alignment, size);
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
printf("Failed to allocate %lu bytes\n", size);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void* malloc_or_die(size_t size)
|
|
|
|
{
|
|
|
|
void *buf = malloc(size);
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
printf("Failed to allocate %lu bytes\n", size);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void* realloc_or_die(void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
void *buf = realloc(ptr, size);
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
printf("Failed to allocate %lu bytes\n", size);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void* calloc_or_die(size_t nmemb, size_t size)
|
|
|
|
{
|
|
|
|
void *buf = calloc(nmemb, size);
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
printf("Failed to allocate %lu bytes\n", size * nmemb);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|