diff options
author | Leo Howell <leo@lwh.jp> | 2009-09-26 11:44:37 +0900 |
---|---|---|
committer | Leo Howell <leo@lwh.jp> | 2009-09-26 13:24:43 +0900 |
commit | 825c45bed29693e9420abecdeb4ebcd03aa3accd (patch) | |
tree | 8e7ae369e845083d815b31c62d9f8a80e32cd890 /lpg/libqr/bitstream.c | |
parent | 69b03a15eb048c05b31a5cc6128c27acc77c1dd5 (diff) | |
download | pdf-simple-sign-825c45bed29693e9420abecdeb4ebcd03aa3accd.tar.gz pdf-simple-sign-825c45bed29693e9420abecdeb4ebcd03aa3accd.tar.xz pdf-simple-sign-825c45bed29693e9420abecdeb4ebcd03aa3accd.zip |
implement bitstream_cat()
Diffstat (limited to 'lpg/libqr/bitstream.c')
-rw-r--r-- | lpg/libqr/bitstream.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lpg/libqr/bitstream.c b/lpg/libqr/bitstream.c index a2b2b58..fd58ea3 100644 --- a/lpg/libqr/bitstream.c +++ b/lpg/libqr/bitstream.c @@ -201,3 +201,32 @@ int bitstream_pack(struct bitstream * stream, return 0; } +int bitstream_cat(struct bitstream * dest, const struct bitstream * src) +{ + size_t count = bitstream_size(src); + size_t srcpos; + + if (ensure_available(dest, count) != 0) + return -1; + + srcpos = bitstream_tell(src); + bitstream_seek((struct bitstream *)src, 0); + + /* uint must be at least 16 bits */ + for (; count >= 16; count -= 16) + bitstream_write( + dest, + bitstream_read((struct bitstream *)src, 16), + 16); + + if (count > 0) + bitstream_write( + dest, + bitstream_read((struct bitstream *)src, count), + count); + + bitstream_seek((struct bitstream *)src, srcpos); + + return 0; +} + |