diff options
| author | Simon Tatham <anakin@pobox.com> | 2017-05-18 06:46:55 +0100 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2017-05-18 06:46:55 +0100 |
| commit | 9e3e915426cb9ef8fd6f6689e12affb6288c5a8a (patch) | |
| tree | 2da97d3419ee15fd0c0089d81d89bf74aeb26961 | |
| parent | ca59ebf60df4ef45a1e4d681980e29e3db853bba (diff) | |
| download | wix-on-linux-9e3e915426cb9ef8fd6f6689e12affb6288c5a8a.tar.gz wix-on-linux-9e3e915426cb9ef8fd6f6689e12affb6288c5a8a.tar.bz2 wix-on-linux-9e3e915426cb9ef8fd6f6689e12affb6288c5a8a.zip | |
Move snew/sfree out into their own header+src.
| -rw-r--r-- | Makefile.am | 6 | ||||
| -rw-r--r-- | fake-lib.c | 17 | ||||
| -rw-r--r-- | fake-lib.h | 7 | ||||
| -rw-r--r-- | fake-msi.c | 1 | ||||
| -rw-r--r-- | fake-winterop.c | 1 | ||||
| -rw-r--r-- | md5.c | 1 | ||||
| -rw-r--r-- | memory.c | 19 | ||||
| -rw-r--r-- | memory.h | 9 |
8 files changed, 36 insertions, 25 deletions
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 | |||
| 4 | 4 | ||
| 5 | lib_LTLIBRARIES = libwinterop.so.la libmsi.so.la libpreload.la | 5 | lib_LTLIBRARIES = libwinterop.so.la libmsi.so.la libpreload.la |
| 6 | 6 | ||
| 7 | libwinterop_so_la_SOURCES = fake-winterop.c fake-lib.c fake-lib.h | 7 | libwinterop_so_la_SOURCES = fake-winterop.c fake-lib.c fake-lib.h \ |
| 8 | memory.c memory.h | ||
| 8 | 9 | ||
| 9 | libmsi_so_la_SOURCES = fake-msi.c fake-lib.c fake-lib.h md5.c | 10 | libmsi_so_la_SOURCES = fake-msi.c fake-lib.c fake-lib.h md5.c \ |
| 11 | memory.c memory.h | ||
| 10 | 12 | ||
| 11 | libpreload_la_SOURCES = preload.c | 13 | libpreload_la_SOURCES = preload.c |
| 12 | libpreload_la_LDFLAGS = -ldl | 14 | libpreload_la_LDFLAGS = -ldl |
| @@ -11,6 +11,7 @@ | |||
| 11 | #include <sys/wait.h> | 11 | #include <sys/wait.h> |
| 12 | #include <unistd.h> | 12 | #include <unistd.h> |
| 13 | 13 | ||
| 14 | #include "memory.h" | ||
| 14 | #include "fake-lib.h" | 15 | #include "fake-lib.h" |
| 15 | 16 | ||
| 16 | char *ascii(const char16_t *wstr, bool translate_slashes) | 17 | char *ascii(const char16_t *wstr, bool translate_slashes) |
| @@ -88,22 +89,6 @@ void c16cpy(char16_t *out, uint32_t *outsize, char *s) | |||
| 88 | *outsize = retlen; | 89 | *outsize = retlen; |
| 89 | } | 90 | } |
| 90 | 91 | ||
| 91 | void *smalloc(size_t size) | ||
| 92 | { | ||
| 93 | void *toret = malloc(size); | ||
| 94 | if (!toret) | ||
| 95 | errx(1, "out of memory"); | ||
| 96 | return toret; | ||
| 97 | } | ||
| 98 | |||
| 99 | void *srealloc(void *ptr, size_t size) | ||
| 100 | { | ||
| 101 | void *toret = realloc(ptr, size); | ||
| 102 | if (!toret) | ||
| 103 | errx(1, "out of memory"); | ||
| 104 | return toret; | ||
| 105 | } | ||
| 106 | |||
| 107 | char *dupcat(const char *str, ...) | 92 | char *dupcat(const char *str, ...) |
| 108 | { | 93 | { |
| 109 | va_list ap; | 94 | va_list ap; |
| @@ -5,12 +5,5 @@ char *ascii(const char16_t *wstr, bool translate_slashes); | |||
| 5 | void system_argv(const char *cmd, ...); | 5 | void system_argv(const char *cmd, ...); |
| 6 | void system_argv_array(char **args); | 6 | void system_argv_array(char **args); |
| 7 | void c16cpy(char16_t *out, uint32_t *outsize, char *s); | 7 | void c16cpy(char16_t *out, uint32_t *outsize, char *s); |
| 8 | void *smalloc(size_t size); | ||
| 9 | void *srealloc(void *ptr, size_t size); | ||
| 10 | char *dupcat(const char *str, ...); | 8 | char *dupcat(const char *str, ...); |
| 11 | unsigned le(const unsigned char *buf, size_t len, size_t off, size_t nbytes); | 9 | unsigned le(const unsigned char *buf, size_t len, size_t off, size_t nbytes); |
| 12 | |||
| 13 | #define snew(type) ((type *)smalloc(sizeof(type))) | ||
| 14 | #define snewn(n,type) ((type *)smalloc((n)*sizeof(type))) | ||
| 15 | #define sresize(ptr,n,type) ((type *)srealloc(ptr,(n)*sizeof(type))) | ||
| 16 | #define sfree(ptr) free(ptr) | ||
| @@ -14,6 +14,7 @@ | |||
| 14 | #include <sys/stat.h> | 14 | #include <sys/stat.h> |
| 15 | #include <unistd.h> | 15 | #include <unistd.h> |
| 16 | 16 | ||
| 17 | #include "memory.h" | ||
| 17 | #include "fake-lib.h" | 18 | #include "fake-lib.h" |
| 18 | 19 | ||
| 19 | uint32_t MsiGetFileVersionW(const char16_t *filename, | 20 | 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 @@ | |||
| 11 | #include <sys/wait.h> | 11 | #include <sys/wait.h> |
| 12 | #include <unistd.h> | 12 | #include <unistd.h> |
| 13 | 13 | ||
| 14 | #include "memory.h" | ||
| 14 | #include "fake-lib.h" | 15 | #include "fake-lib.h" |
| 15 | 16 | ||
| 16 | uint32_t HashPublicKeyInfo(void *pCertContext, | 17 | uint32_t HashPublicKeyInfo(void *pCertContext, |
| @@ -19,6 +19,7 @@ | |||
| 19 | 19 | ||
| 20 | #include <err.h> | 20 | #include <err.h> |
| 21 | 21 | ||
| 22 | #include "memory.h" | ||
| 22 | #include "fake-lib.h" | 23 | #include "fake-lib.h" |
| 23 | 24 | ||
| 24 | /* ---------------------------------------------------------------------- | 25 | /* ---------------------------------------------------------------------- |
diff --git a/memory.c b/memory.c new file mode 100644 index 0000000..7d3a746 --- /dev/null +++ b/memory.c | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | #include <err.h> | ||
| 2 | |||
| 3 | #include "memory.h" | ||
| 4 | |||
| 5 | void *smalloc(size_t size) | ||
| 6 | { | ||
| 7 | void *toret = malloc(size); | ||
| 8 | if (!toret) | ||
| 9 | errx(1, "out of memory"); | ||
| 10 | return toret; | ||
| 11 | } | ||
| 12 | |||
| 13 | void *srealloc(void *ptr, size_t size) | ||
| 14 | { | ||
| 15 | void *toret = realloc(ptr, size); | ||
| 16 | if (!toret) | ||
| 17 | errx(1, "out of memory"); | ||
| 18 | return toret; | ||
| 19 | } | ||
diff --git a/memory.h b/memory.h new file mode 100644 index 0000000..77e153e --- /dev/null +++ b/memory.h | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | void *smalloc(size_t size); | ||
| 4 | void *srealloc(void *ptr, size_t size); | ||
| 5 | |||
| 6 | #define snew(type) ((type *)smalloc(sizeof(type))) | ||
| 7 | #define snewn(n,type) ((type *)smalloc((n)*sizeof(type))) | ||
| 8 | #define sresize(ptr,n,type) ((type *)srealloc(ptr,(n)*sizeof(type))) | ||
| 9 | #define sfree(ptr) free(ptr) | ||
