diff options
author | Martin Pool <mbp@sourcefrog.net> | 2000-03-16 03:51:10 +0000 |
---|---|---|
committer | Martin Pool <mbp@sourcefrog.net> | 2000-03-16 03:51:10 +0000 |
commit | 8a179584c9fe1eb6d844ebf76f2ff87c241ad64a (patch) | |
tree | 8ce4ba22a18bf6024ce1ceb658c647f975eccffc /inbuf.c | |
parent | dc179c9d1d49b52f11e288dbbdee3664f6d5974b (diff) | |
download | librsync-8a179584c9fe1eb6d844ebf76f2ff87c241ad64a.tar.gz |
Clean up encoding implementation.
Add space in the protocol for 64-bit offsets.
Fix a memory leak in encoding.
Add ptrbuf to do abstract IO to a fixed buffer.
When encoding, the new signature block size can be different from the
old block size.
Encode copy commands using the optimal command byte rather than always
using COPY_INT_INT.
Add test-chained to make sure we can swallow our own output.
Add parameter to hsencode to specify the new block size.
Diffstat (limited to 'inbuf.c')
-rw-r--r-- | inbuf.c | 88 |
1 files changed, 39 insertions, 49 deletions
@@ -28,67 +28,57 @@ int -_hs_fill_inbuf (inbuf_t * inbuf, rs_read_fn_t read_fn, void *readprivate) +_hs_fill_inbuf(inbuf_t * inbuf, rs_read_fn_t read_fn, void *readprivate) { - int ret; - - assert (inbuf->amount < inbuf->len && 0 <= inbuf->amount); - ret = read_fn (readprivate, - inbuf->buf + inbuf->amount, inbuf->len - inbuf->amount); - if (ret < 0) - { - _hs_error ( __FILE__ ": error reading into input buffer"); - return ret; - } - else if (ret == 0) - { - _hs_trace ("reached end of input file"); - } - else - { - _hs_trace ("read %d bytes into input buffer" + int ret; + + assert(inbuf->amount < inbuf->len && 0 <= inbuf->amount); + ret = read_fn(readprivate, + inbuf->buf + inbuf->amount, inbuf->len - inbuf->amount); + if (ret < 0) { + _hs_fatal(__FILE__ ": error reading into input buffer"); + return ret; + } else if (ret == 0) { + _hs_trace("reached end of input file"); + } else { + _hs_trace("read %d bytes into input buffer" " at position %d", ret, inbuf->abspos); } - inbuf->amount += ret; - return ret; + inbuf->amount += ret; + return ret; } -int -_hs_alloc_inbuf (inbuf_t * inbuf, int block_len) +int _hs_alloc_inbuf(inbuf_t * inbuf, int block_len) { - bzero (inbuf, sizeof *inbuf); - /* must be at least two blocks; shouldn't be too small. */ - inbuf->len = MAX (block_len * 2, 8192); - inbuf->buf = malloc (inbuf->len); - inbuf->amount = 0; - inbuf->abspos = 0; - - return 0; + bzero(inbuf, sizeof *inbuf); + /* must be at least two blocks; shouldn't be too small. */ + inbuf->len = MAX(block_len * 2, 8192); + inbuf->buf = malloc(inbuf->len); + inbuf->amount = 0; + inbuf->abspos = 0; + + return 0; } -int -_hs_slide_inbuf (inbuf_t *inbuf) +int _hs_slide_inbuf(inbuf_t * inbuf) { - /* Copy the remaining data into the front of - the buffer */ - if (inbuf->cursor != 0) - { - if (inbuf->amount != inbuf->cursor) - { - memcpy (inbuf->buf, - inbuf->buf + inbuf->cursor, inbuf->amount - inbuf->cursor); - _hs_trace (": slide %d bytes down to the start of the buffer", - inbuf->amount - inbuf->cursor); + /* Copy the remaining data into the front of + the buffer */ + if (inbuf->cursor != 0) { + if (inbuf->amount != inbuf->cursor) { + memcpy(inbuf->buf, + inbuf->buf + inbuf->cursor, + inbuf->amount - inbuf->cursor); + _hs_trace(": slide %d bytes down to the start of the buffer", + inbuf->amount - inbuf->cursor); } - - inbuf->amount -= inbuf->cursor; - inbuf->abspos += inbuf->cursor; - } - - return 0; -} + inbuf->amount -= inbuf->cursor; + inbuf->abspos += inbuf->cursor; + } + return 0; +} |