2022-12-25 03:58:00 -05:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2022-12-25 05:14:39 -05:00
|
|
|
#include <libclayer.h>
|
2022-12-25 03:58:00 -05:00
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
void exit(const int status)
|
|
|
|
{
|
|
|
|
// Custom implementation
|
2022-12-25 05:14:39 -05:00
|
|
|
libclayer.exit(status);
|
2022-12-25 03:58:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void abort()
|
|
|
|
{
|
|
|
|
// Custom implementation
|
2022-12-25 05:14:39 -05:00
|
|
|
if (libclayer.abort) libclayer.abort();
|
2022-12-25 03:58:00 -05:00
|
|
|
|
|
|
|
// Default implementation
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *calloc(const size_t nmemb, const size_t size)
|
|
|
|
{
|
|
|
|
// Custom implementation
|
2022-12-25 05:14:39 -05:00
|
|
|
if (libclayer.calloc) return libclayer.calloc(nmemb, size);
|
2022-12-25 03:58:00 -05:00
|
|
|
|
|
|
|
// Default implementation
|
|
|
|
const size_t total_size = nmemb * size;
|
|
|
|
if (!total_size) return NULL;
|
|
|
|
if (total_size / nmemb != size) return NULL;
|
|
|
|
void *const ptr = malloc(total_size);
|
|
|
|
if (ptr) memset(ptr, 0, total_size);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free(void *const ptr)
|
|
|
|
{
|
|
|
|
// Custom implementation
|
2022-12-25 05:14:39 -05:00
|
|
|
libclayer.free(ptr);
|
2022-12-25 03:58:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void *malloc(const size_t size)
|
|
|
|
{
|
|
|
|
// Custom implementation
|
2022-12-25 05:14:39 -05:00
|
|
|
return libclayer.malloc(size);
|
2022-12-25 03:58:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void *realloc(void *const ptr, const size_t size)
|
|
|
|
{
|
|
|
|
// Custom implementation
|
2022-12-25 05:14:39 -05:00
|
|
|
return libclayer.realloc(ptr, size);
|
2022-12-25 03:58:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int atoi(const char *str)
|
|
|
|
{
|
|
|
|
while (isspace(*str)) ++str;
|
|
|
|
bool is_negative = false;
|
|
|
|
switch (*str) {
|
|
|
|
case '-': is_negative = true; // fall through
|
|
|
|
case '+': ++str;
|
|
|
|
}
|
|
|
|
int result = 0;
|
|
|
|
while (isdigit(*str)) result = 10 * result - (*str++ - '0');
|
|
|
|
return is_negative ? result : -result;
|
|
|
|
}
|