Import ealloc.c from ubase

This commit is contained in:
sin 2014-11-14 18:09:48 +00:00
parent 35d467d971
commit 2982d88533
3 changed files with 53 additions and 0 deletions

View File

@ -21,6 +21,7 @@ LIB = \
util/concat.o \ util/concat.o \
util/cp.o \ util/cp.o \
util/crypt.o \ util/crypt.o \
util/ealloc.o \
util/enmasse.o \ util/enmasse.o \
util/eprintf.o \ util/eprintf.o \
util/estrtod.o \ util/estrtod.o \

5
util.h
View File

@ -17,14 +17,19 @@ extern char *argv0;
char *agetcwd(void); char *agetcwd(void);
void apathmax(char **, long *); void apathmax(char **, long *);
void enmasse(int, char **, int (*)(const char *, const char *)); void enmasse(int, char **, int (*)(const char *, const char *));
void *ecalloc(size_t, size_t);
void *emalloc(size_t size);
void *erealloc(void *, size_t);
void eprintf(const char *, ...); void eprintf(const char *, ...);
void enprintf(int, const char *, ...); void enprintf(int, const char *, ...);
char *estrdup(const char *);
double estrtod(const char *); double estrtod(const char *);
long estrtol(const char *, int); long estrtol(const char *, int);
void fnck(const char *, const char *, int (*)(const char *, const char *)); void fnck(const char *, const char *, int (*)(const char *, const char *));
char *humansize(double); char *humansize(double);
void putword(const char *); void putword(const char *);
void recurse(const char *, void (*)(const char *)); void recurse(const char *, void (*)(const char *));
#undef strlcat #undef strlcat
size_t strlcat(char *, const char *, size_t); size_t strlcat(char *, const char *, size_t);
#undef strlcpy #undef strlcpy

47
util/ealloc.c Normal file
View File

@ -0,0 +1,47 @@
/* 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)
{
void *p;
p = calloc(nmemb, size);
if (!p)
eprintf("calloc: out of memory\n");
return p;
}
void *
emalloc(size_t size)
{
void *p;
p = malloc(size);
if (!p)
eprintf("malloc: out of memory\n");
return p;
}
void *
erealloc(void *p, size_t size)
{
p = realloc(p, size);
if (!p)
eprintf("realloc: out of memory\n");
return p;
}
char *
estrdup(const char *s)
{
char *p;
p = strdup(s);
if (!p)
eprintf("strdup: out of memory\n");
return p;
}