aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am6
-rw-r--r--fake-lib.c17
-rw-r--r--fake-lib.h7
-rw-r--r--fake-msi.c1
-rw-r--r--fake-winterop.c1
-rw-r--r--md5.c1
-rw-r--r--memory.c19
-rw-r--r--memory.h9
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
5lib_LTLIBRARIES = libwinterop.so.la libmsi.so.la libpreload.la 5lib_LTLIBRARIES = libwinterop.so.la libmsi.so.la libpreload.la
6 6
7libwinterop_so_la_SOURCES = fake-winterop.c fake-lib.c fake-lib.h 7libwinterop_so_la_SOURCES = fake-winterop.c fake-lib.c fake-lib.h \
8memory.c memory.h
8 9
9libmsi_so_la_SOURCES = fake-msi.c fake-lib.c fake-lib.h md5.c 10libmsi_so_la_SOURCES = fake-msi.c fake-lib.c fake-lib.h md5.c \
11memory.c memory.h
10 12
11libpreload_la_SOURCES = preload.c 13libpreload_la_SOURCES = preload.c
12libpreload_la_LDFLAGS = -ldl 14libpreload_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 @@
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
16char *ascii(const char16_t *wstr, bool translate_slashes) 17char *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
91void *smalloc(size_t size)
92{
93 void *toret = malloc(size);
94 if (!toret)
95 errx(1, "out of memory");
96 return toret;
97}
98
99void *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
107char *dupcat(const char *str, ...) 92char *dupcat(const char *str, ...)
108{ 93{
109 va_list ap; 94 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);
5void system_argv(const char *cmd, ...); 5void system_argv(const char *cmd, ...);
6void system_argv_array(char **args); 6void system_argv_array(char **args);
7void c16cpy(char16_t *out, uint32_t *outsize, char *s); 7void c16cpy(char16_t *out, uint32_t *outsize, char *s);
8void *smalloc(size_t size);
9void *srealloc(void *ptr, size_t size);
10char *dupcat(const char *str, ...); 8char *dupcat(const char *str, ...);
11unsigned le(const unsigned char *buf, size_t len, size_t off, size_t nbytes); 9unsigned 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)
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 @@
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
19uint32_t MsiGetFileVersionW(const char16_t *filename, 20uint32_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
16uint32_t HashPublicKeyInfo(void *pCertContext, 17uint32_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 @@
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
5void *smalloc(size_t size)
6{
7 void *toret = malloc(size);
8 if (!toret)
9 errx(1, "out of memory");
10 return toret;
11}
12
13void *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
3void *smalloc(size_t size);
4void *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)