Add ealloc.c with wrappers for emalloc() and friends
Re-organize util.h as well.
This commit is contained in:
parent
49f1dc0ebe
commit
550b655d98
1
Makefile
1
Makefile
@ -7,6 +7,7 @@ HDR = arg.h config.def.h proc.h reboot.h util.h
|
|||||||
LIB = \
|
LIB = \
|
||||||
util/agetcwd.o \
|
util/agetcwd.o \
|
||||||
util/apathmax.o \
|
util/apathmax.o \
|
||||||
|
util/ealloc.o \
|
||||||
util/eprintf.o \
|
util/eprintf.o \
|
||||||
util/estrtol.o \
|
util/estrtol.o \
|
||||||
util/explicit_bzero.o \
|
util/explicit_bzero.o \
|
||||||
|
30
util.h
30
util.h
@ -4,21 +4,47 @@
|
|||||||
#define UTF8_POINT(c) (((c) & 0xc0) != 0x80)
|
#define UTF8_POINT(c) (((c) & 0xc0) != 0x80)
|
||||||
#define LEN(x) (sizeof (x) / sizeof *(x))
|
#define LEN(x) (sizeof (x) / sizeof *(x))
|
||||||
|
|
||||||
|
/* eprintf.c */
|
||||||
extern char *argv0;
|
extern char *argv0;
|
||||||
|
|
||||||
|
/* agetcwd.c */
|
||||||
char *agetcwd(void);
|
char *agetcwd(void);
|
||||||
|
|
||||||
|
/* apathmax.c */
|
||||||
void apathmax(char **, long *);
|
void apathmax(char **, long *);
|
||||||
void devtotty(int, int *, int *);
|
|
||||||
|
/* eprintf.c */
|
||||||
void enprintf(int, const char *, ...);
|
void enprintf(int, const char *, ...);
|
||||||
void eprintf(const char *, ...);
|
void eprintf(const char *, ...);
|
||||||
|
void weprintf(const char *, ...);
|
||||||
|
|
||||||
|
/* ealloc.c */
|
||||||
|
void *ecalloc(size_t, size_t);
|
||||||
|
void *emalloc(size_t size);
|
||||||
|
void *erealloc(void *, size_t);
|
||||||
|
char *estrdup(const char *);
|
||||||
|
|
||||||
|
/* estrtol.c */
|
||||||
long estrtol(const char *, int);
|
long estrtol(const char *, int);
|
||||||
|
|
||||||
|
/* explicit_bzero.c */
|
||||||
#undef explicit_bzero
|
#undef explicit_bzero
|
||||||
void explicit_bzero(void *, size_t);
|
void explicit_bzero(void *, size_t);
|
||||||
|
|
||||||
|
/* putword.c */
|
||||||
void putword(const char *);
|
void putword(const char *);
|
||||||
|
|
||||||
|
/* recurse.c */
|
||||||
void recurse(const char *, void (*)(const char *));
|
void recurse(const char *, void (*)(const char *));
|
||||||
|
|
||||||
|
/* strlcpy.c */
|
||||||
#undef strlcat
|
#undef strlcat
|
||||||
size_t strlcat(char *, const char *, size_t);
|
size_t strlcat(char *, const char *, size_t);
|
||||||
|
|
||||||
|
/* strlcat.c */
|
||||||
#undef strlcpy
|
#undef strlcpy
|
||||||
size_t strlcpy(char *, const char *, size_t);
|
size_t strlcpy(char *, const char *, size_t);
|
||||||
|
|
||||||
|
/* tty.c */
|
||||||
|
void devtotty(int, int *, int *);
|
||||||
char *ttytostr(int, int);
|
char *ttytostr(int, int);
|
||||||
void weprintf(const char *, ...);
|
|
||||||
|
46
util/ealloc.c
Normal file
46
util/ealloc.c
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/* 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user