Create a flag to know when the temporary output buffer is in use, in preparation for when we use it on decompression.

This commit is contained in:
Con Kolivas 2011-03-13 08:34:06 +11:00
parent 2f87f62696
commit 6ac74aa9f0
6 changed files with 11 additions and 6 deletions

View file

@ -46,6 +46,7 @@
#define CHECK_FILE (control->flags & FLAG_CHECK)
#define KEEP_BROKEN (control->flags & FLAG_KEEP_BROKEN)
#define LZO_TEST (control->flags & FLAG_THRESHOLD)
#define TMP_OUTBUF (control->flags & FLAG_TMP_OUTBUF)
#define print_output(format, args...) do {\
fprintf(control->msgout, format, ##args); \

View file

@ -738,8 +738,8 @@ next_chunk:
* a pseudo-temporary file */
static void open_tmpoutbuf(rzip_control *control)
{
control->flags |= FLAG_TMP_OUTBUF;
control->out_maxlen = control->maxram + control->page_size;
control->tmp_outbuf = malloc(control->out_maxlen);
if (unlikely(!control->tmp_outbuf))
fatal("Failed to malloc tmp_outbuf in open_tmpoutbuf\n");
@ -838,6 +838,8 @@ void compress_file(rzip_control *control)
fatal("Failed to close fd_in\n");
if (unlikely(!STDOUT && close(fd_out)))
fatal("Failed to close fd_out\n");
if (TMP_OUTBUF)
free(control->tmp_outbuf);
if (!KEEP_FILES) {
if (unlikely(unlink(control->infile)))

View file

@ -120,6 +120,7 @@ typedef struct md5_ctx md5_ctx;
#define FLAG_CHECK (1 << 18)
#define FLAG_KEEP_BROKEN (1 << 19)
#define FLAG_THRESHOLD (1 << 20)
#define FLAG_TMP_OUTBUF (1 << 21)
#define NO_MD5 (!(HASH_CHECK) && !(HAS_MD5))

1
main.c
View file

@ -75,6 +75,7 @@
#define CHECK_FILE (control.flags & FLAG_CHECK)
#define KEEP_BROKEN (control.flags & FLAG_KEEP_BROKEN)
#define LZO_TEST (control.flags & FLAG_THRESHOLD)
#define TMP_OUTBUF (control.flags & FLAG_TMP_OUTBUF)
#define print_output(format, args...) do {\
fprintf(control.msgout, format, ##args); \

2
rzip.c
View file

@ -980,7 +980,7 @@ retry:
if (unlikely(write_1g(control, control->fd_out, md5_resblock, MD5_DIGEST_SIZE) != MD5_DIGEST_SIZE))
fatal("Failed to write md5 in rzip_fd\n");
if (STDOUT)
if (TMP_OUTBUF)
flush_stdout(control);
gettimeofday(&current, NULL);

View file

@ -637,7 +637,7 @@ const i64 one_g = 1000 * 1024 * 1024;
ssize_t put_fdout(rzip_control *control, int fd, void *offset_buf, ssize_t ret)
{
if (!STDOUT || DECOMPRESS || TEST_ONLY)
if (!TMP_OUTBUF)
return write(fd, offset_buf, (size_t)ret);
if (unlikely(control->out_ofs + ret > control->out_maxlen))
@ -769,7 +769,7 @@ static int seekto(rzip_control *control, struct stream_info *sinfo, i64 pos)
{
i64 spos = pos + sinfo->initial_pos;
if (!(DECOMPRESS || TEST_ONLY) && STDOUT) {
if (TMP_OUTBUF) {
spos -= control->rel_ofs;
control->out_ofs = spos;
if (unlikely(spos > control->out_len || spos < 0)) {
@ -790,7 +790,7 @@ static i64 get_seek(rzip_control *control, int fd)
{
i64 ret;
if (!(DECOMPRESS || TEST_ONLY) && STDOUT)
if (TMP_OUTBUF)
return control->rel_ofs + control->out_ofs;
ret = lseek(fd, 0, SEEK_CUR);
if (unlikely(ret == -1))
@ -1107,7 +1107,7 @@ retry:
if (!ctis->chunks++) {
int j;
if (STDOUT) {
if (TMP_OUTBUF) {
if (!control->magic_written)
write_stdout_header(control);
flush_stdout(control);