libcdsb/src/extra-memory.c
2022-06-09 14:16:41 +03:00

73 lines
1.2 KiB
C

/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <stdlib.h>
#include "../include/extra/cstring.h"
#include "__internal/include.h"
#undef aligned_alloc
#undef malloc
#undef realloc
#undef calloc
void* libcdsb_aalloc(size_t a, size_t n) {
void* x;
if ((x = aligned_alloc(a, n)))
return x;
abort();
}
void* libcdsb_calloc(size_t n, size_t c) {
void* x;
if ((x = calloc(n, c)))
return x;
abort();
}
void* libcdsb_malloc(size_t n) {
void* x;
if ((x = malloc(n)))
return x;
abort();
}
void* libcdsb_realloc(void* x, size_t n) {
if ((x = realloc(x, n)))
return x;
abort();
}
void* libcdsb_memndup(const void* m, size_t n) {
void* x;
if ((x = malloc(n)))
return memcpy(x, m, n);
abort();
}
char* libcdsb_strdup(const char* s) {
void* x;
size_t n;
if ((x = malloc(n = strlen(s) + 1)))
return memcpy(x, s, n);
abort();
}
char* libcdsb_strndup(const char* s, size_t n) {
void* x;
if ((x = malloc(n + 1))) {
((char*)memcpy(x, s, n))[n] = 0;
return x;
}
abort();
}