From c106128d1af4611b243563f897b837ca8b7235b1 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 3 Nov 2010 13:14:46 +1100 Subject: [PATCH] Fix darwin build and clean up ifdef and incorrect ordered includes at the same time. All builds were using fakememopen due to incorrect ifdef usage, so make GNU builds actually use memopen again. --- rzip.c | 7 +++++++ rzip.h | 14 ++++++++++++++ stream.c | 31 +++++++------------------------ 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/rzip.c b/rzip.c index 7a6a8e1..9b0e810 100644 --- a/rzip.c +++ b/rzip.c @@ -522,6 +522,13 @@ static void init_hash_indexes(struct rzip_state *st) extern const i64 one_g; +static inline void *fake_mremap(void *old_address, size_t old_size, size_t new_size, int flags) +{ + flags = 0; + munmap(old_address, old_size); + return mmap(old_address, new_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); +} + /* stdin is not file backed so we have to emulate the mmap by mapping * anonymous ram and reading stdin into it. It means the maximum ram * we can use will be less but we will already have determined this in diff --git a/rzip.h b/rzip.h index 5452c39..9e60ef8 100644 --- a/rzip.h +++ b/rzip.h @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include #include @@ -43,11 +45,23 @@ #ifdef __APPLE__ #include +#define fmemopen fake_fmemopen +#define open_memstream fake_open_memstream +#define memstream_update_buffer fake_open_memstream_update_buffer +#define mremap fake_mremap +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS MAP_ANON +#endif +#else /* __APPLE__ */ +#define memstream_update_buffer(A, B, C) (0) #endif #include #include +/* LZMA C Wrapper */ +#include "lzma/C/LzmaLib.h" + #ifdef HAVE_STRING_H #include #endif diff --git a/stream.c b/stream.c index 2875369..93e34d8 100644 --- a/stream.c +++ b/stream.c @@ -19,13 +19,7 @@ /* multiplex N streams into a file - the streams are passed through different compressors */ -/* Need a definitition for FILE for old bzlib.h */ -#include -#include -#include #include "rzip.h" -/* LZMA C Wrapper */ -#include "lzma/C/LzmaLib.h" #define STREAM_BUFSIZE (1024 * 1024 * 10) @@ -52,12 +46,7 @@ struct stream_info { static int lzo_compresses(struct stream *s); -#ifndef HAS_MEMSTREAM -#define fmemopen fake_fmemopen -#define open_memstream fake_open_memstream -#define memstream_update_buffer fake_open_memstream_update_buffer - -static FILE *fake_fmemopen(void *buf, size_t buflen, char *mode) +static inline FILE *fake_fmemopen(void *buf, size_t buflen, char *mode) { FILE *in; @@ -72,7 +61,7 @@ static FILE *fake_fmemopen(void *buf, size_t buflen, char *mode) return in; } -static FILE *fake_open_memstream(char **buf, size_t *length) +static inline FILE *fake_open_memstream(char **buf, size_t *length) { FILE *out; @@ -84,7 +73,7 @@ static FILE *fake_open_memstream(char **buf, size_t *length) return out; } -static int fake_open_memstream_update_buffer(FILE *fp, uchar **buf, size_t *length) +static inline int fake_open_memstream_update_buffer(FILE *fp, uchar **buf, size_t *length) { long original_pos = ftell(fp); @@ -101,12 +90,6 @@ static int fake_open_memstream_update_buffer(FILE *fp, uchar **buf, size_t *leng return -1; return 0; } -#else -static int memstream_update_buffer(FILE *fp, uchar **buf, size_t *length) -{ - return 0; -} -#endif /* ***** COMPRESSION FUNCTIONS ***** @@ -120,9 +103,9 @@ static int memstream_update_buffer(FILE *fp, uchar **buf, size_t *length) static void zpaq_compress_buf(struct stream *s, int *c_type, i64 *c_len) { + uchar *c_buf = NULL; + size_t dlen = 0; FILE *in, *out; - uchar *c_buf; - size_t dlen; if (!lzo_compresses(s)) return; @@ -316,9 +299,9 @@ out_free: static int zpaq_decompress_buf(struct stream *s) { + uchar *c_buf = NULL; + size_t dlen = 0; FILE *in, *out; - uchar *c_buf; - size_t dlen; in = fmemopen(s->buf, s->buflen, "r"); if (!in) {