2014-11-14 18:09:48 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "../util.h"
|
|
|
|
|
|
|
|
void *
|
|
|
|
ecalloc(size_t nmemb, size_t size)
|
2015-02-11 00:40:52 +00:00
|
|
|
{
|
|
|
|
return encalloc(1, nmemb, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
emalloc(size_t size)
|
|
|
|
{
|
|
|
|
return enmalloc(1, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
erealloc(void *p, size_t size)
|
|
|
|
{
|
|
|
|
return enrealloc(1, p, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
estrdup(const char *s)
|
|
|
|
{
|
|
|
|
return enstrdup(1, s);
|
|
|
|
}
|
|
|
|
|
2015-02-11 00:59:04 +00:00
|
|
|
char *
|
|
|
|
estrndup(const char *s, size_t n)
|
|
|
|
{
|
|
|
|
return enstrndup(1, s, n);
|
|
|
|
}
|
|
|
|
|
2015-02-11 00:40:52 +00:00
|
|
|
void *
|
|
|
|
encalloc(int status, size_t nmemb, size_t size)
|
2014-11-14 18:09:48 +00:00
|
|
|
{
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
p = calloc(nmemb, size);
|
|
|
|
if (!p)
|
2015-02-11 00:40:52 +00:00
|
|
|
enprintf(status, "calloc: out of memory\n");
|
2014-11-14 18:09:48 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2015-02-11 00:40:52 +00:00
|
|
|
enmalloc(int status, size_t size)
|
2014-11-14 18:09:48 +00:00
|
|
|
{
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
p = malloc(size);
|
|
|
|
if (!p)
|
2015-02-11 00:40:52 +00:00
|
|
|
enprintf(status, "malloc: out of memory\n");
|
2014-11-14 18:09:48 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2015-02-11 00:40:52 +00:00
|
|
|
enrealloc(int status, void *p, size_t size)
|
2014-11-14 18:09:48 +00:00
|
|
|
{
|
|
|
|
p = realloc(p, size);
|
|
|
|
if (!p)
|
2015-02-11 00:40:52 +00:00
|
|
|
enprintf(status, "realloc: out of memory\n");
|
2014-11-14 18:09:48 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2015-02-11 00:40:52 +00:00
|
|
|
enstrdup(int status, const char *s)
|
2014-11-14 18:09:48 +00:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
p = strdup(s);
|
|
|
|
if (!p)
|
2015-02-11 00:40:52 +00:00
|
|
|
enprintf(status, "strdup: out of memory\n");
|
2014-11-14 18:09:48 +00:00
|
|
|
return p;
|
|
|
|
}
|
2015-02-11 00:59:04 +00:00
|
|
|
|
|
|
|
char *
|
|
|
|
enstrndup(int status, const char *s, size_t n)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
p = strndup(s, n);
|
|
|
|
if (!p)
|
|
|
|
enprintf(status, "strndup: out of memory\n");
|
|
|
|
return p;
|
|
|
|
}
|