Move snew/sfree out into their own header+src.

This commit is contained in:
Simon Tatham 2017-05-18 06:46:55 +01:00
parent ca59ebf60d
commit 9e3e915426
8 changed files with 36 additions and 25 deletions

View file

@ -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

View file

@ -11,6 +11,7 @@
#include <sys/wait.h>
#include <unistd.h>
#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;

View file

@ -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)

View file

@ -14,6 +14,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include "memory.h"
#include "fake-lib.h"
uint32_t MsiGetFileVersionW(const char16_t *filename,

View file

@ -11,6 +11,7 @@
#include <sys/wait.h>
#include <unistd.h>
#include "memory.h"
#include "fake-lib.h"
uint32_t HashPublicKeyInfo(void *pCertContext,

1
md5.c
View file

@ -19,6 +19,7 @@
#include <err.h>
#include "memory.h"
#include "fake-lib.h"
/* ----------------------------------------------------------------------

19
memory.c Normal file
View file

@ -0,0 +1,19 @@
#include <err.h>
#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;
}

9
memory.h Normal file
View file

@ -0,0 +1,9 @@
#include <stdlib.h>
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)