From 9e3e915426cb9ef8fd6f6689e12affb6288c5a8a Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 18 May 2017 06:46:55 +0100 Subject: Move snew/sfree out into their own header+src. --- Makefile.am | 6 ++++-- fake-lib.c | 17 +---------------- fake-lib.h | 7 ------- fake-msi.c | 1 + fake-winterop.c | 1 + md5.c | 1 + memory.c | 19 +++++++++++++++++++ memory.h | 9 +++++++++ 8 files changed, 36 insertions(+), 25 deletions(-) create mode 100644 memory.c create mode 100644 memory.h diff --git a/Makefile.am b/Makefile.am index 6fb2062..cc11cbd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,9 +4,11 @@ ACLOCAL_AMFLAGS = -I m4 lib_LTLIBRARIES = libwinterop.so.la libmsi.so.la libpreload.la -libwinterop_so_la_SOURCES = fake-winterop.c fake-lib.c fake-lib.h +libwinterop_so_la_SOURCES = fake-winterop.c fake-lib.c fake-lib.h \ +memory.c memory.h -libmsi_so_la_SOURCES = fake-msi.c fake-lib.c fake-lib.h md5.c +libmsi_so_la_SOURCES = fake-msi.c fake-lib.c fake-lib.h md5.c \ +memory.c memory.h libpreload_la_SOURCES = preload.c libpreload_la_LDFLAGS = -ldl diff --git a/fake-lib.c b/fake-lib.c index 011d35d..9862020 100644 --- a/fake-lib.c +++ b/fake-lib.c @@ -11,6 +11,7 @@ #include #include +#include "memory.h" #include "fake-lib.h" char *ascii(const char16_t *wstr, bool translate_slashes) @@ -88,22 +89,6 @@ void c16cpy(char16_t *out, uint32_t *outsize, char *s) *outsize = retlen; } -void *smalloc(size_t size) -{ - void *toret = malloc(size); - if (!toret) - errx(1, "out of memory"); - return toret; -} - -void *srealloc(void *ptr, size_t size) -{ - void *toret = realloc(ptr, size); - if (!toret) - errx(1, "out of memory"); - return toret; -} - char *dupcat(const char *str, ...) { va_list ap; diff --git a/fake-lib.h b/fake-lib.h index 0b7f8f9..8f8774c 100644 --- a/fake-lib.h +++ b/fake-lib.h @@ -5,12 +5,5 @@ char *ascii(const char16_t *wstr, bool translate_slashes); void system_argv(const char *cmd, ...); void system_argv_array(char **args); void c16cpy(char16_t *out, uint32_t *outsize, char *s); -void *smalloc(size_t size); -void *srealloc(void *ptr, size_t size); char *dupcat(const char *str, ...); unsigned le(const unsigned char *buf, size_t len, size_t off, size_t nbytes); - -#define snew(type) ((type *)smalloc(sizeof(type))) -#define snewn(n,type) ((type *)smalloc((n)*sizeof(type))) -#define sresize(ptr,n,type) ((type *)srealloc(ptr,(n)*sizeof(type))) -#define sfree(ptr) free(ptr) diff --git a/fake-msi.c b/fake-msi.c index bf49911..8e8d97d 100644 --- a/fake-msi.c +++ b/fake-msi.c @@ -14,6 +14,7 @@ #include #include +#include "memory.h" #include "fake-lib.h" uint32_t MsiGetFileVersionW(const char16_t *filename, diff --git a/fake-winterop.c b/fake-winterop.c index b16952a..b367831 100644 --- a/fake-winterop.c +++ b/fake-winterop.c @@ -11,6 +11,7 @@ #include #include +#include "memory.h" #include "fake-lib.h" uint32_t HashPublicKeyInfo(void *pCertContext, diff --git a/md5.c b/md5.c index 48c6aec..4074716 100644 --- a/md5.c +++ b/md5.c @@ -19,6 +19,7 @@ #include +#include "memory.h" #include "fake-lib.h" /* ---------------------------------------------------------------------- diff --git a/memory.c b/memory.c new file mode 100644 index 0000000..7d3a746 --- /dev/null +++ b/memory.c @@ -0,0 +1,19 @@ +#include + +#include "memory.h" + +void *smalloc(size_t size) +{ + void *toret = malloc(size); + if (!toret) + errx(1, "out of memory"); + return toret; +} + +void *srealloc(void *ptr, size_t size) +{ + void *toret = realloc(ptr, size); + if (!toret) + errx(1, "out of memory"); + return toret; +} diff --git a/memory.h b/memory.h new file mode 100644 index 0000000..77e153e --- /dev/null +++ b/memory.h @@ -0,0 +1,9 @@ +#include + +void *smalloc(size_t size); +void *srealloc(void *ptr, size_t size); + +#define snew(type) ((type *)smalloc(sizeof(type))) +#define snewn(n,type) ((type *)smalloc((n)*sizeof(type))) +#define sresize(ptr,n,type) ((type *)srealloc(ptr,(n)*sizeof(type))) +#define sfree(ptr) free(ptr) -- cgit v1.2.3-55-g6feb