kolibrios/contrib/media/updf/fitz/base_memory.c
Serhii Sakhno cd35d38ad2 updf: restore menuetlibc version
git-svn-id: svn://kolibrios.org@8429 a494cfbc-eb01-0410-851d-a64ba20cac60
2020-12-16 18:41:33 +00:00

78 lines
1.0 KiB
C

#include "fitz.h"
void *
fz_malloc(int size)
{
void *p = malloc(size);
if (!p)
{
fprintf(stderr, "fatal error: out of memory\n");
abort();
}
return p;
}
void *
fz_calloc(int count, int size)
{
void *p;
if (count == 0 || size == 0)
return 0;
if (count < 0 || size < 0 || count > INT_MAX / size)
{
fprintf(stderr, "fatal error: out of memory (integer overflow)\n");
abort();
}
p = malloc(count * size);
if (!p)
{
fprintf(stderr, "fatal error: out of memory\n");
abort();
}
return p;
}
void *
fz_realloc(void *p, int count, int size)
{
void *np;
if (count == 0 || size == 0)
{
fz_free(p);
return 0;
}
if (count < 0 || size < 0 || count > INT_MAX / size)
{
fprintf(stderr, "fatal error: out of memory (integer overflow)\n");
abort();
}
np = realloc(p, count * size);
if (np == NULL)
{
fprintf(stderr, "fatal error: out of memory\n");
abort();
}
return np;
}
void
fz_free(void *p)
{
free(p);
}
char *
fz_strdup(char *s)
{
int len = strlen(s) + 1;
char *ns = fz_malloc(len);
memcpy(ns, s, len);
return ns;
}