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.
This commit is contained in:
Con Kolivas 2010-11-03 13:14:46 +11:00
parent 9c00229ee1
commit c106128d1a
3 changed files with 28 additions and 24 deletions

7
rzip.c
View file

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

14
rzip.h
View file

@ -33,6 +33,8 @@
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <bzlib.h>
#include <zlib.h>
#include <sys/resource.h>
#include <netinet/in.h>
@ -43,11 +45,23 @@
#ifdef __APPLE__
#include <sys/sysctl.h>
#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 <lzo/lzoconf.h>
#include <lzo/lzo1x.h>
/* LZMA C Wrapper */
#include "lzma/C/LzmaLib.h"
#ifdef HAVE_STRING_H
#include <string.h>
#endif

View file

@ -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 <stdio.h>
#include <bzlib.h>
#include <zlib.h>
#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) {