write_1g always uses control->fd_out so don't pass fd to it.

This commit is contained in:
Con Kolivas 2011-03-14 11:15:35 +11:00
parent 7eabb5e7de
commit b644240152
4 changed files with 9 additions and 9 deletions

View file

@ -135,7 +135,7 @@ static i64 unzip_literal(rzip_control *control, void *ss, i64 len, int fd_out, u
if (unlikely(stream_read == -1 )) if (unlikely(stream_read == -1 ))
fatal("Failed to read_stream in unzip_literal\n"); fatal("Failed to read_stream in unzip_literal\n");
if (unlikely(write_1g(control, fd_out, buf, (size_t)stream_read) != (ssize_t)stream_read)) if (unlikely(write_1g(control, buf, (size_t)stream_read) != (ssize_t)stream_read))
fatal("Failed to write literal buffer of size %lld\n", stream_read); fatal("Failed to write literal buffer of size %lld\n", stream_read);
if (!HAS_MD5) if (!HAS_MD5)
@ -189,7 +189,7 @@ static i64 unzip_match(rzip_control *control, void *ss, i64 len, int fd_out, int
if (unlikely(read_fdhist(control, off_buf, (size_t)n) != (ssize_t)n)) if (unlikely(read_fdhist(control, off_buf, (size_t)n) != (ssize_t)n))
fatal("Failed to read %d bytes in unzip_match\n", n); fatal("Failed to read %d bytes in unzip_match\n", n);
if (unlikely(write_1g(control, fd_out, off_buf, (size_t)n) != (ssize_t)n)) if (unlikely(write_1g(control, off_buf, (size_t)n) != (ssize_t)n))
fatal("Failed to write %d bytes in unzip_match\n", n); fatal("Failed to write %d bytes in unzip_match\n", n);
if (!HAS_MD5) if (!HAS_MD5)

2
rzip.c
View file

@ -975,7 +975,7 @@ retry:
print_output("%02x", md5_resblock[j] & 0xFF); print_output("%02x", md5_resblock[j] & 0xFF);
print_output("\n"); print_output("\n");
} }
if (unlikely(write_1g(control, control->fd_out, md5_resblock, MD5_DIGEST_SIZE) != MD5_DIGEST_SIZE)) if (unlikely(write_1g(control, md5_resblock, MD5_DIGEST_SIZE) != MD5_DIGEST_SIZE))
fatal("Failed to write md5 in rzip_fd\n"); fatal("Failed to write md5 in rzip_fd\n");
if (TMP_OUTBUF) if (TMP_OUTBUF)

View file

@ -635,10 +635,10 @@ out:
const i64 one_g = 1000 * 1024 * 1024; const i64 one_g = 1000 * 1024 * 1024;
ssize_t put_fdout(rzip_control *control, int fd, void *offset_buf, ssize_t ret) ssize_t put_fdout(rzip_control *control, void *offset_buf, ssize_t ret)
{ {
if (!TMP_OUTBUF) if (!TMP_OUTBUF)
return write(fd, offset_buf, (size_t)ret); return write(control->fd_out, offset_buf, (size_t)ret);
if (unlikely(control->out_ofs + ret > control->out_maxlen)) if (unlikely(control->out_ofs + ret > control->out_maxlen))
failure("Tried to write beyond temporary output buffer. Need a larger out_maxlen\n"); failure("Tried to write beyond temporary output buffer. Need a larger out_maxlen\n");
@ -652,7 +652,7 @@ ssize_t put_fdout(rzip_control *control, int fd, void *offset_buf, ssize_t ret)
/* This is a custom version of write() which writes in 1GB chunks to avoid /* This is a custom version of write() which writes in 1GB chunks to avoid
the overflows at the >= 2GB mark thanks to 32bit fuckage. This should help the overflows at the >= 2GB mark thanks to 32bit fuckage. This should help
even on the rare occasion write() fails to write 1GB as well. */ even on the rare occasion write() fails to write 1GB as well. */
ssize_t write_1g(rzip_control *control, int fd, void *buf, i64 len) ssize_t write_1g(rzip_control *control,void *buf, i64 len)
{ {
uchar *offset_buf = buf; uchar *offset_buf = buf;
ssize_t ret; ssize_t ret;
@ -664,7 +664,7 @@ ssize_t write_1g(rzip_control *control, int fd, void *buf, i64 len)
ret = one_g; ret = one_g;
else else
ret = len; ret = len;
ret = put_fdout(control, fd, offset_buf, (size_t)ret); ret = put_fdout(control, offset_buf, (size_t)ret);
if (unlikely(ret <= 0)) if (unlikely(ret <= 0))
return ret; return ret;
len -= ret; len -= ret;
@ -702,7 +702,7 @@ static int write_buf(rzip_control *control, int f, uchar *p, i64 len)
{ {
ssize_t ret; ssize_t ret;
ret = write_1g(control, f, p, (size_t)len); ret = write_1g(control, p, (size_t)len);
if (unlikely(ret == -1)) { if (unlikely(ret == -1)) {
print_err("Write of length %lld failed - %s\n", len, strerror(errno)); print_err("Write of length %lld failed - %s\n", len, strerror(errno));
return -1; return -1;

View file

@ -26,7 +26,7 @@
void create_pthread(pthread_t *thread, pthread_attr_t *attr, void create_pthread(pthread_t *thread, pthread_attr_t *attr,
void * (*start_routine)(void *), void *arg); void * (*start_routine)(void *), void *arg);
void join_pthread(pthread_t th, void **thread_return); void join_pthread(pthread_t th, void **thread_return);
ssize_t write_1g(rzip_control *control, int fd, void *buf, i64 len); ssize_t write_1g(rzip_control *control, void *buf, i64 len);
ssize_t read_1g(int fd, void *buf, i64 len); ssize_t read_1g(int fd, void *buf, i64 len);
void prepare_streamout_threads(rzip_control *control); void prepare_streamout_threads(rzip_control *control);
void close_streamout_threads(rzip_control *control); void close_streamout_threads(rzip_control *control);