├── .gitignore ├── CHANGES ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── Makefile-libbz2_so ├── README ├── README.COMPILATION.PROBLEMS ├── README.XML.STUFF ├── README.md ├── blocksort.c ├── bz-common.xsl ├── bz-fo.xsl ├── bz-html.xsl ├── bz2-driver-capnp.cc ├── bz2-driver-dbus.c ├── bz2-driver-grpc.cc ├── bz2-driver-libnv.c ├── bz2-stub-capnp.cc ├── bz2-stub-dbus.c ├── bz2-stub-grpc.cc ├── bz2-stub-libnv.c ├── bzdiff ├── bzdiff.1 ├── bzgrep ├── bzgrep.1 ├── bzip.css ├── bzip2.1 ├── bzip2.1.preformatted ├── bzip2.c ├── bzip2.txt ├── bzip2recover.c ├── bzlib.c ├── bzlib.capnp ├── bzlib.h ├── bzlib.proto ├── bzlib_private.h ├── bzmore ├── bzmore.1 ├── compress.c ├── crctable.c ├── decompress.c ├── dlltest.c ├── dlltest.dsp ├── entities.xml ├── format.pl ├── huffman.c ├── idolize.h ├── libbz2.def ├── libbz2.dsp ├── makefile.msc ├── manual.html ├── manual.pdf ├── manual.ps ├── manual.xml ├── mk251.c ├── randtable.c ├── rpc-invoke.png ├── rpc-setup.png ├── rpc-util.c ├── rpc-util.h ├── sample1.bz2 ├── sample1.ref ├── sample2.bz2 ├── sample2.ref ├── sample3.bz2 ├── sample3.ref ├── spewG.c ├── stream.c ├── test-run.sh ├── third_party └── libnv │ ├── LICENSE │ ├── README.google │ ├── common_impl.h │ ├── dnv.h │ ├── dnvlist.c │ ├── local.h │ ├── msgio.c │ ├── msgio.h │ ├── nv.9 │ ├── nv.h │ ├── nv_impl.h │ ├── nvlist.c │ ├── nvlist_impl.h │ ├── nvpair.c │ ├── nvpair_impl.h │ └── sys_endian.h ├── unzcrash.c ├── words0 ├── words1 ├── words2 ├── words3 └── xmlproc.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | bzip2 4 | bzip2recover 5 | sample[123].rb2 6 | sample[123].tst 7 | bzip2-shared 8 | libbz2.so.* 9 | bzip2-1.0* 10 | bzip2-1.0*.tar.gz 11 | bz2-driver-libnv 12 | bzip2-libnv 13 | bz2-driver-dbus 14 | bzip2-dbus 15 | bz2-driver-grpc 16 | bzip2-grpc 17 | bzlib.grpc.pb.cc 18 | bzlib.grpc.pb.h 19 | bzlib.pb.cc 20 | bzlib.pb.h 21 | bz2-driver-capnp 22 | bzip2-capnp 23 | bzlib.capnp.c++ 24 | bzlib.capnp.h 25 | README.html 26 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing guidelines 2 | ======================= 3 | 4 | Want to contribute? Great! First, read this page (including the small print at the end). 5 | 6 | Before you contribute 7 | --------------------- 8 | 9 | Before we can use your code, you must sign the 10 | [Google Individual Contributor License Agreement] 11 | (https://cla.developers.google.com/about/google-individual) 12 | (CLA), which you can do online. The CLA is necessary mainly because you own the 13 | copyright to your changes, even after your contribution becomes part of our 14 | codebase, so we need your permission to use and distribute your code. We also 15 | need to be sure of various other things—for instance that you'll tell us if you 16 | know that your code infringes on other people's patents. You don't have to sign 17 | the CLA until after you've submitted your code for review and a member has 18 | approved it, but you must do it before we can put your code into our codebase. 19 | Before you start working on a larger contribution, you should get in touch with 20 | us first through the issue tracker with your idea so that we can help out and 21 | possibly guide you. Coordinating up front makes it much easier to avoid 22 | frustration later on. 23 | 24 | Code reviews 25 | ------------ 26 | 27 | All submissions, including submissions by project members, require review. We 28 | use Github pull requests for this purpose. 29 | 30 | The small print 31 | --------------- 32 | 33 | Contributions made by corporations are covered by a different agreement than 34 | the one above, the 35 | [Software Grant and Corporate Contributor License Agreement] 36 | (https://cla.developers.google.com/about/google-corporate). 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------- 3 | 4 | This program, "bzip2", the associated library "libbzip2", and all 5 | documentation, are copyright (C) 1996-2010 Julian R Seward. All 6 | rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | 15 | 2. The origin of this software must not be misrepresented; you must 16 | not claim that you wrote the original software. If you use this 17 | software in a product, an acknowledgment in the product 18 | documentation would be appreciated but is not required. 19 | 20 | 3. Altered source versions must be plainly marked as such, and must 21 | not be misrepresented as being the original software. 22 | 23 | 4. The name of the author may not be used to endorse or promote 24 | products derived from this software without specific prior written 25 | permission. 26 | 27 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 28 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 29 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 31 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 33 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 35 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | 39 | Julian Seward, jseward@bzip.org 40 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 41 | 42 | -------------------------------------------------------------------------- 43 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------ 2 | # This file is part of bzip2/libbzip2, a program and library for 3 | # lossless, block-sorting data compression. 4 | # 5 | # bzip2/libbzip2 version 1.0.6 of 6 September 2010 6 | # Copyright (C) 1996-2010 Julian Seward 7 | # 8 | # Please read the WARNING, DISCLAIMER and PATENTS sections in the 9 | # README file. 10 | # 11 | # This program is released under the terms of the license contained 12 | # in the file LICENSE. 13 | # ------------------------------------------------------------------ 14 | 15 | SHELL=/bin/sh 16 | 17 | # To assist in cross-compiling 18 | CC=gcc 19 | AR=ar 20 | RANLIB=ranlib 21 | LDFLAGS=-L/usr/local/lib 22 | 23 | BIGFILES=-D_FILE_OFFSET_BITS=64 24 | CFLAGS=-Wall -Winline -O2 -g $(BIGFILES) -Ithird_party/libnv -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include 25 | CXXFLAGS=$(CFLAGS) -I/usr/local/include -std=c++11 26 | GRPC_CPP_PLUGIN = grpc_cpp_plugin 27 | GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)` 28 | 29 | # Where you want it installed when you do 'make install' 30 | PREFIX=/usr/local 31 | 32 | 33 | OBJS= blocksort.o \ 34 | huffman.o \ 35 | crctable.o \ 36 | randtable.o \ 37 | compress.o \ 38 | decompress.o \ 39 | stream.o \ 40 | bzlib.o 41 | 42 | NVOBJS= dnvlist.o \ 43 | nvlist.o \ 44 | nvpair.o \ 45 | msgio.o 46 | 47 | GRPC_SRC = bzlib.grpc.pb.cc bzlib.pb.cc 48 | GRPC_OBJS = bzlib.grpc.pb.o bzlib.pb.o 49 | 50 | PROGS = bzip2 bzip2recover bzip2-libnv bzip2-dbus bzip2-grpc bzip2-capnp 51 | DRIVERS = bz2-driver-libnv bz2-driver-dbus bz2-driver-grpc bz2-driver-capnp 52 | LIBS = libbz2.a libnv.a libbz2-libnv.a libbz2-dbus.a libbz2-grpc.a libbz2-capnp.a 53 | 54 | all: $(LIBS) $(PROGS) $(DRIVERS) 55 | 56 | bzip2: libbz2.a bzip2.o 57 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ bzip2.o -L. -lbz2 58 | 59 | bzip2-libnv: libbz2-libnv.a libnv.a bzip2.o 60 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ bzip2.o -L. -lbz2-libnv -lnv 61 | 62 | bzip2-dbus: libbz2-dbus.a bzip2.o 63 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ bzip2.o -L. -lbz2-dbus -ldbus-1 64 | 65 | bzip2-grpc: libbz2-grpc.a bzip2.o 66 | $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ bzip2.o -L. -lbz2-grpc -lgrpc++_unsecure -lgrpc -lprotobuf -lpthread -ldl 67 | 68 | bzip2-capnp: libbz2-capnp.a bzip2.o 69 | $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ bzip2.o -L. -lbz2-capnp -lcapnp-rpc -lcapnp -lkj-async -lkj 70 | 71 | bzip2recover: bzip2recover.o 72 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ bzip2recover.o 73 | 74 | bz2-driver-libnv: libbz2.a libnv.a bz2-driver-libnv.o rpc-util.o 75 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ bz2-driver-libnv.o rpc-util.o -L. -lbz2 -lnv 76 | 77 | bz2-driver-dbus: libbz2.a bz2-driver-dbus.o rpc-util.o 78 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ bz2-driver-dbus.o rpc-util.o -L. -lbz2 -ldbus-1 79 | 80 | bz2-driver-grpc: libbz2.a bz2-driver-grpc.o rpc-util.o $(GRPC_OBJS) 81 | $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ bz2-driver-grpc.o rpc-util.o $(GRPC_OBJS) -L. -lbz2 -lgrpc++_unsecure -lgrpc -lprotobuf -lpthread -ldl 82 | 83 | bz2-driver-capnp: libbz2.a bz2-driver-capnp.o bzlib.capnp.o rpc-util.o 84 | $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ bz2-driver-capnp.o bzlib.capnp.o rpc-util.o -L. -lbz2 -lcapnp-rpc -lcapnp -lkj-async -lkj 85 | 86 | libbz2-libnv.a: bz2-stub-libnv.o rpc-util.o 87 | rm -f $@ 88 | $(AR) cq $@ $^ 89 | 90 | libbz2-dbus.a: bz2-stub-dbus.o rpc-util.o 91 | rm -f $@ 92 | $(AR) cq $@ $^ 93 | 94 | libbz2-grpc.a: bz2-stub-grpc.o rpc-util.o $(GRPC_OBJS) 95 | rm -f $@ 96 | $(AR) cq $@ $^ 97 | 98 | libbz2-capnp.a: bz2-stub-capnp.o rpc-util.o bzlib.capnp.o 99 | rm -f $@ 100 | $(AR) cq $@ $^ 101 | 102 | libbz2.a: $(OBJS) 103 | rm -f $@ 104 | $(AR) cq $@ $(OBJS) 105 | @if ( test -f $(RANLIB) -o -f /usr/bin/ranlib -o \ 106 | -f /bin/ranlib -o -f /usr/ccs/bin/ranlib ) ; then \ 107 | $(RANLIB) $@ ; \ 108 | fi 109 | 110 | libnv.a: $(NVOBJS) 111 | rm -f libnv.a 112 | $(AR) cq libnv.a $(NVOBJS) 113 | 114 | check: test 115 | test: test-direct test-libnv test-dbus test-grpc test-capnp 116 | test-direct: bzip2 117 | ./test-run.sh ./bzip2 118 | test-libnv: bzip2-libnv bz2-driver-libnv 119 | ./test-run.sh ./bzip2-libnv 120 | test-dbus: bzip2-dbus bz2-driver-dbus 121 | ./test-run.sh ./bzip2-dbus 122 | test-grpc: bzip2-grpc bz2-driver-grpc 123 | ./test-run.sh ./bzip2-grpc 124 | test-capnp: bzip2-capnp bz2-driver-capnp 125 | ./test-run.sh ./bzip2-capnp 126 | 127 | install: bzip2 bzip2recover 128 | if ( test ! -d $(PREFIX)/bin ) ; then mkdir -p $(PREFIX)/bin ; fi 129 | if ( test ! -d $(PREFIX)/lib ) ; then mkdir -p $(PREFIX)/lib ; fi 130 | if ( test ! -d $(PREFIX)/man ) ; then mkdir -p $(PREFIX)/man ; fi 131 | if ( test ! -d $(PREFIX)/man/man1 ) ; then mkdir -p $(PREFIX)/man/man1 ; fi 132 | if ( test ! -d $(PREFIX)/include ) ; then mkdir -p $(PREFIX)/include ; fi 133 | cp -f bzip2 $(PREFIX)/bin/bzip2 134 | cp -f bzip2 $(PREFIX)/bin/bunzip2 135 | cp -f bzip2 $(PREFIX)/bin/bzcat 136 | cp -f bzip2recover $(PREFIX)/bin/bzip2recover 137 | chmod a+x $(PREFIX)/bin/bzip2 138 | chmod a+x $(PREFIX)/bin/bunzip2 139 | chmod a+x $(PREFIX)/bin/bzcat 140 | chmod a+x $(PREFIX)/bin/bzip2recover 141 | cp -f bzip2.1 $(PREFIX)/man/man1 142 | chmod a+r $(PREFIX)/man/man1/bzip2.1 143 | cp -f bzlib.h $(PREFIX)/include 144 | chmod a+r $(PREFIX)/include/bzlib.h 145 | cp -f libbz2.a $(PREFIX)/lib 146 | chmod a+r $(PREFIX)/lib/libbz2.a 147 | cp -f bzgrep $(PREFIX)/bin/bzgrep 148 | ln -s -f $(PREFIX)/bin/bzgrep $(PREFIX)/bin/bzegrep 149 | ln -s -f $(PREFIX)/bin/bzgrep $(PREFIX)/bin/bzfgrep 150 | chmod a+x $(PREFIX)/bin/bzgrep 151 | cp -f bzmore $(PREFIX)/bin/bzmore 152 | ln -s -f $(PREFIX)/bin/bzmore $(PREFIX)/bin/bzless 153 | chmod a+x $(PREFIX)/bin/bzmore 154 | cp -f bzdiff $(PREFIX)/bin/bzdiff 155 | ln -s -f $(PREFIX)/bin/bzdiff $(PREFIX)/bin/bzcmp 156 | chmod a+x $(PREFIX)/bin/bzdiff 157 | cp -f bzgrep.1 bzmore.1 bzdiff.1 $(PREFIX)/man/man1 158 | chmod a+r $(PREFIX)/man/man1/bzgrep.1 159 | chmod a+r $(PREFIX)/man/man1/bzmore.1 160 | chmod a+r $(PREFIX)/man/man1/bzdiff.1 161 | echo ".so man1/bzgrep.1" > $(PREFIX)/man/man1/bzegrep.1 162 | echo ".so man1/bzgrep.1" > $(PREFIX)/man/man1/bzfgrep.1 163 | echo ".so man1/bzmore.1" > $(PREFIX)/man/man1/bzless.1 164 | echo ".so man1/bzdiff.1" > $(PREFIX)/man/man1/bzcmp.1 165 | 166 | clean: 167 | rm -f *.o libbz2.a libnv.a bzip2 bzip2recover \ 168 | sample1.rb2 sample2.rb2 sample3.rb2 \ 169 | sample1.tst sample2.tst sample3.tst \ 170 | libbz2-libnv.a bz2-driver-libnv bzip2-libnv \ 171 | libbz2-dbus.a bz2-driver-dbus bzip2-dbus 172 | 173 | %.o: %.c 174 | $(CC) $(CFLAGS) -c $< -o $@ 175 | %.o: third_party/libnv/%.c 176 | $(CC) $(CFLAGS) -c $< -o $@ 177 | %.o: %.cc 178 | $(CXX) $(CXXFLAGS) -c $< -o $@ 179 | %.o: %.c++ 180 | $(CXX) $(CXXFLAGS) -c $< -o $@ 181 | bzlib.pb.cc: bzlib.proto 182 | protoc --cpp_out=. $< 183 | bzlib.grpc.pb.cc: bzlib.proto 184 | protoc --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $< 185 | bz2-stub-grpc.o : bzlib.grpc.pb.cc bzlib.pb.cc 186 | bzlib.capnp.c++: bzlib.capnp 187 | capnp compile -oc++ $< 188 | %.capnp: # disable implicit rule 189 | 190 | bz2-stub-capnp.o : bzlib.capnp.c++ 191 | 192 | distclean: clean 193 | rm -f manual.ps manual.html manual.pdf 194 | 195 | DISTNAME=bzip2-1.0.6 196 | dist: check manual 197 | rm -f $(DISTNAME) 198 | ln -s -f . $(DISTNAME) 199 | tar cvf $(DISTNAME).tar \ 200 | $(DISTNAME)/blocksort.c \ 201 | $(DISTNAME)/huffman.c \ 202 | $(DISTNAME)/crctable.c \ 203 | $(DISTNAME)/randtable.c \ 204 | $(DISTNAME)/compress.c \ 205 | $(DISTNAME)/decompress.c \ 206 | $(DISTNAME)/stream.c \ 207 | $(DISTNAME)/bzlib.c \ 208 | $(DISTNAME)/bzip2.c \ 209 | $(DISTNAME)/bzip2recover.c \ 210 | $(DISTNAME)/bzlib.h \ 211 | $(DISTNAME)/bzlib_private.h \ 212 | $(DISTNAME)/Makefile \ 213 | $(DISTNAME)/LICENSE \ 214 | $(DISTNAME)/bzip2.1 \ 215 | $(DISTNAME)/bzip2.1.preformatted \ 216 | $(DISTNAME)/bzip2.txt \ 217 | $(DISTNAME)/words0 \ 218 | $(DISTNAME)/words1 \ 219 | $(DISTNAME)/words2 \ 220 | $(DISTNAME)/words3 \ 221 | $(DISTNAME)/sample1.ref \ 222 | $(DISTNAME)/sample2.ref \ 223 | $(DISTNAME)/sample3.ref \ 224 | $(DISTNAME)/sample1.bz2 \ 225 | $(DISTNAME)/sample2.bz2 \ 226 | $(DISTNAME)/sample3.bz2 \ 227 | $(DISTNAME)/dlltest.c \ 228 | $(DISTNAME)/manual.html \ 229 | $(DISTNAME)/manual.pdf \ 230 | $(DISTNAME)/manual.ps \ 231 | $(DISTNAME)/README \ 232 | $(DISTNAME)/README.COMPILATION.PROBLEMS \ 233 | $(DISTNAME)/README.XML.STUFF \ 234 | $(DISTNAME)/CHANGES \ 235 | $(DISTNAME)/libbz2.def \ 236 | $(DISTNAME)/libbz2.dsp \ 237 | $(DISTNAME)/dlltest.dsp \ 238 | $(DISTNAME)/makefile.msc \ 239 | $(DISTNAME)/unzcrash.c \ 240 | $(DISTNAME)/spewG.c \ 241 | $(DISTNAME)/mk251.c \ 242 | $(DISTNAME)/bzdiff \ 243 | $(DISTNAME)/bzdiff.1 \ 244 | $(DISTNAME)/bzmore \ 245 | $(DISTNAME)/bzmore.1 \ 246 | $(DISTNAME)/bzgrep \ 247 | $(DISTNAME)/bzgrep.1 \ 248 | $(DISTNAME)/Makefile-libbz2_so \ 249 | $(DISTNAME)/bz-common.xsl \ 250 | $(DISTNAME)/bz-fo.xsl \ 251 | $(DISTNAME)/bz-html.xsl \ 252 | $(DISTNAME)/bzip.css \ 253 | $(DISTNAME)/entities.xml \ 254 | $(DISTNAME)/manual.xml \ 255 | $(DISTNAME)/format.pl \ 256 | $(DISTNAME)/xmlproc.sh 257 | gzip -v $(DISTNAME).tar 258 | 259 | # For rebuilding the manual from sources on my SuSE 9.1 box 260 | 261 | MANUAL_SRCS= bz-common.xsl bz-fo.xsl bz-html.xsl bzip.css \ 262 | entities.xml manual.xml 263 | 264 | manual: manual.html manual.ps manual.pdf 265 | 266 | manual.ps: $(MANUAL_SRCS) 267 | ./xmlproc.sh -ps manual.xml 268 | 269 | manual.pdf: $(MANUAL_SRCS) 270 | ./xmlproc.sh -pdf manual.xml 271 | 272 | manual.html: $(MANUAL_SRCS) 273 | ./xmlproc.sh -html manual.xml 274 | -------------------------------------------------------------------------------- /Makefile-libbz2_so: -------------------------------------------------------------------------------- 1 | 2 | # This Makefile builds a shared version of the library, 3 | # libbz2.so.1.0.6, with soname libbz2.so.1.0, 4 | # at least on x86-Linux (RedHat 7.2), 5 | # with gcc-2.96 20000731 (Red Hat Linux 7.1 2.96-98). 6 | # Please see the README file for some important info 7 | # about building the library like this. 8 | 9 | # ------------------------------------------------------------------ 10 | # This file is part of bzip2/libbzip2, a program and library for 11 | # lossless, block-sorting data compression. 12 | # 13 | # bzip2/libbzip2 version 1.0.6 of 6 September 2010 14 | # Copyright (C) 1996-2010 Julian Seward 15 | # 16 | # Please read the WARNING, DISCLAIMER and PATENTS sections in the 17 | # README file. 18 | # 19 | # This program is released under the terms of the license contained 20 | # in the file LICENSE. 21 | # ------------------------------------------------------------------ 22 | 23 | 24 | SHELL=/bin/sh 25 | CC=gcc 26 | BIGFILES=-D_FILE_OFFSET_BITS=64 27 | CFLAGS=-fpic -fPIC -Wall -Winline -O2 -g $(BIGFILES) 28 | 29 | OBJS= blocksort.o \ 30 | huffman.o \ 31 | crctable.o \ 32 | randtable.o \ 33 | compress.o \ 34 | decompress.o \ 35 | bzlib.o 36 | 37 | all: $(OBJS) 38 | $(CC) -shared -Wl,-soname -Wl,libbz2.so.1.0 -o libbz2.so.1.0.6 $(OBJS) 39 | $(CC) $(CFLAGS) -o bzip2-shared bzip2.c libbz2.so.1.0.6 40 | rm -f libbz2.so.1.0 41 | ln -s libbz2.so.1.0.6 libbz2.so.1.0 42 | 43 | clean: 44 | rm -f $(OBJS) bzip2.o libbz2.so.1.0.6 libbz2.so.1.0 bzip2-shared 45 | 46 | blocksort.o: blocksort.c 47 | $(CC) $(CFLAGS) -c blocksort.c 48 | huffman.o: huffman.c 49 | $(CC) $(CFLAGS) -c huffman.c 50 | crctable.o: crctable.c 51 | $(CC) $(CFLAGS) -c crctable.c 52 | randtable.o: randtable.c 53 | $(CC) $(CFLAGS) -c randtable.c 54 | compress.o: compress.c 55 | $(CC) $(CFLAGS) -c compress.c 56 | decompress.o: decompress.c 57 | $(CC) $(CFLAGS) -c decompress.c 58 | bzlib.o: bzlib.c 59 | $(CC) $(CFLAGS) -c bzlib.c 60 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | This is the README for bzip2/libzip2. 3 | This version is fully compatible with the previous public releases. 4 | 5 | ------------------------------------------------------------------ 6 | This file is part of bzip2/libbzip2, a program and library for 7 | lossless, block-sorting data compression. 8 | 9 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 10 | Copyright (C) 1996-2010 Julian Seward 11 | 12 | Please read the WARNING, DISCLAIMER and PATENTS sections in this file. 13 | 14 | This program is released under the terms of the license contained 15 | in the file LICENSE. 16 | ------------------------------------------------------------------ 17 | 18 | Complete documentation is available in Postscript form (manual.ps), 19 | PDF (manual.pdf) or html (manual.html). A plain-text version of the 20 | manual page is available as bzip2.txt. 21 | 22 | 23 | HOW TO BUILD -- UNIX 24 | 25 | Type 'make'. This builds the library libbz2.a and then the programs 26 | bzip2 and bzip2recover. Six self-tests are run. If the self-tests 27 | complete ok, carry on to installation: 28 | 29 | To install in /usr/local/bin, /usr/local/lib, /usr/local/man and 30 | /usr/local/include, type 31 | 32 | make install 33 | 34 | To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type 35 | 36 | make install PREFIX=/xxx/yyy 37 | 38 | If you are (justifiably) paranoid and want to see what 'make install' 39 | is going to do, you can first do 40 | 41 | make -n install or 42 | make -n install PREFIX=/xxx/yyy respectively. 43 | 44 | The -n instructs make to show the commands it would execute, but not 45 | actually execute them. 46 | 47 | 48 | HOW TO BUILD -- UNIX, shared library libbz2.so. 49 | 50 | Do 'make -f Makefile-libbz2_so'. This Makefile seems to work for 51 | Linux-ELF (RedHat 7.2 on an x86 box), with gcc. I make no claims 52 | that it works for any other platform, though I suspect it probably 53 | will work for most platforms employing both ELF and gcc. 54 | 55 | bzip2-shared, a client of the shared library, is also built, but not 56 | self-tested. So I suggest you also build using the normal Makefile, 57 | since that conducts a self-test. A second reason to prefer the 58 | version statically linked to the library is that, on x86 platforms, 59 | building shared objects makes a valuable register (%ebx) unavailable 60 | to gcc, resulting in a slowdown of 10%-20%, at least for bzip2. 61 | 62 | Important note for people upgrading .so's from 0.9.0/0.9.5 to version 63 | 1.0.X. All the functions in the library have been renamed, from (eg) 64 | bzCompress to BZ2_bzCompress, to avoid namespace pollution. 65 | Unfortunately this means that the libbz2.so created by 66 | Makefile-libbz2_so will not work with any program which used an older 67 | version of the library. I do encourage library clients to make the 68 | effort to upgrade to use version 1.0, since it is both faster and more 69 | robust than previous versions. 70 | 71 | 72 | HOW TO BUILD -- Windows 95, NT, DOS, Mac, etc. 73 | 74 | It's difficult for me to support compilation on all these platforms. 75 | My approach is to collect binaries for these platforms, and put them 76 | on the master web site (http://www.bzip.org). Look there. However 77 | (FWIW), bzip2-1.0.X is very standard ANSI C and should compile 78 | unmodified with MS Visual C. If you have difficulties building, you 79 | might want to read README.COMPILATION.PROBLEMS. 80 | 81 | At least using MS Visual C++ 6, you can build from the unmodified 82 | sources by issuing, in a command shell: 83 | 84 | nmake -f makefile.msc 85 | 86 | (you may need to first run the MSVC-provided script VCVARS32.BAT 87 | so as to set up paths to the MSVC tools correctly). 88 | 89 | 90 | VALIDATION 91 | 92 | Correct operation, in the sense that a compressed file can always be 93 | decompressed to reproduce the original, is obviously of paramount 94 | importance. To validate bzip2, I used a modified version of Mark 95 | Nelson's churn program. Churn is an automated test driver which 96 | recursively traverses a directory structure, using bzip2 to compress 97 | and then decompress each file it encounters, and checking that the 98 | decompressed data is the same as the original. 99 | 100 | 101 | 102 | Please read and be aware of the following: 103 | 104 | WARNING: 105 | 106 | This program and library (attempts to) compress data by 107 | performing several non-trivial transformations on it. 108 | Unless you are 100% familiar with *all* the algorithms 109 | contained herein, and with the consequences of modifying them, 110 | you should NOT meddle with the compression or decompression 111 | machinery. Incorrect changes can and very likely *will* 112 | lead to disastrous loss of data. 113 | 114 | 115 | DISCLAIMER: 116 | 117 | I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE 118 | USE OF THIS PROGRAM/LIBRARY, HOWSOEVER CAUSED. 119 | 120 | Every compression of a file implies an assumption that the 121 | compressed file can be decompressed to reproduce the original. 122 | Great efforts in design, coding and testing have been made to 123 | ensure that this program works correctly. However, the complexity 124 | of the algorithms, and, in particular, the presence of various 125 | special cases in the code which occur with very low but non-zero 126 | probability make it impossible to rule out the possibility of bugs 127 | remaining in the program. DO NOT COMPRESS ANY DATA WITH THIS 128 | PROGRAM UNLESS YOU ARE PREPARED TO ACCEPT THE POSSIBILITY, HOWEVER 129 | SMALL, THAT THE DATA WILL NOT BE RECOVERABLE. 130 | 131 | That is not to say this program is inherently unreliable. 132 | Indeed, I very much hope the opposite is true. bzip2/libbzip2 133 | has been carefully constructed and extensively tested. 134 | 135 | 136 | PATENTS: 137 | 138 | To the best of my knowledge, bzip2/libbzip2 does not use any 139 | patented algorithms. However, I do not have the resources 140 | to carry out a patent search. Therefore I cannot give any 141 | guarantee of the above statement. 142 | 143 | 144 | 145 | WHAT'S NEW IN 0.9.0 (as compared to 0.1pl2) ? 146 | 147 | * Approx 10% faster compression, 30% faster decompression 148 | * -t (test mode) is a lot quicker 149 | * Can decompress concatenated compressed files 150 | * Programming interface, so programs can directly read/write .bz2 files 151 | * Less restrictive (BSD-style) licensing 152 | * Flag handling more compatible with GNU gzip 153 | * Much more documentation, i.e., a proper user manual 154 | * Hopefully, improved portability (at least of the library) 155 | 156 | WHAT'S NEW IN 0.9.5 ? 157 | 158 | * Compression speed is much less sensitive to the input 159 | data than in previous versions. Specifically, the very 160 | slow performance caused by repetitive data is fixed. 161 | * Many small improvements in file and flag handling. 162 | * A Y2K statement. 163 | 164 | WHAT'S NEW IN 1.0.0 ? 165 | 166 | See the CHANGES file. 167 | 168 | WHAT'S NEW IN 1.0.2 ? 169 | 170 | See the CHANGES file. 171 | 172 | WHAT'S NEW IN 1.0.3 ? 173 | 174 | See the CHANGES file. 175 | 176 | WHAT'S NEW IN 1.0.4 ? 177 | 178 | See the CHANGES file. 179 | 180 | WHAT'S NEW IN 1.0.5 ? 181 | 182 | See the CHANGES file. 183 | 184 | WHAT'S NEW IN 1.0.6 ? 185 | 186 | See the CHANGES file. 187 | 188 | 189 | I hope you find bzip2 useful. Feel free to contact me at 190 | jseward@bzip.org 191 | if you have any suggestions or queries. Many people mailed me with 192 | comments, suggestions and patches after the releases of bzip-0.15, 193 | bzip-0.21, and bzip2 versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1, 194 | 1.0.2 and 1.0.3, and the changes in bzip2 are largely a result of this 195 | feedback. I thank you for your comments. 196 | 197 | bzip2's "home" is http://www.bzip.org/ 198 | 199 | Julian Seward 200 | jseward@bzip.org 201 | Cambridge, UK. 202 | 203 | 18 July 1996 (version 0.15) 204 | 25 August 1996 (version 0.21) 205 | 7 August 1997 (bzip2, version 0.1) 206 | 29 August 1997 (bzip2, version 0.1pl2) 207 | 23 August 1998 (bzip2, version 0.9.0) 208 | 8 June 1999 (bzip2, version 0.9.5) 209 | 4 Sept 1999 (bzip2, version 0.9.5d) 210 | 5 May 2000 (bzip2, version 1.0pre8) 211 | 30 December 2001 (bzip2, version 1.0.2pre1) 212 | 15 February 2005 (bzip2, version 1.0.3) 213 | 20 December 2006 (bzip2, version 1.0.4) 214 | 10 December 2007 (bzip2, version 1.0.5) 215 | 6 Sept 2010 (bzip2, version 1.0.6) 216 | -------------------------------------------------------------------------------- /README.COMPILATION.PROBLEMS: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------ 2 | This file is part of bzip2/libbzip2, a program and library for 3 | lossless, block-sorting data compression. 4 | 5 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 6 | Copyright (C) 1996-2010 Julian Seward 7 | 8 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 9 | README file. 10 | 11 | This program is released under the terms of the license contained 12 | in the file LICENSE. 13 | ------------------------------------------------------------------ 14 | 15 | bzip2-1.0.6 should compile without problems on the vast majority of 16 | platforms. Using the supplied Makefile, I've built and tested it 17 | myself for x86-linux and amd64-linux. With makefile.msc, Visual C++ 18 | 6.0 and nmake, you can build a native Win32 version too. Large file 19 | support seems to work correctly on at least on amd64-linux. 20 | 21 | When I say "large file" I mean a file of size 2,147,483,648 (2^31) 22 | bytes or above. Many older OSs can't handle files above this size, 23 | but many newer ones can. Large files are pretty huge -- most files 24 | you'll encounter are not Large Files. 25 | 26 | Early versions of bzip2 (0.1, 0.9.0, 0.9.5) compiled on a wide variety 27 | of platforms without difficulty, and I hope this version will continue 28 | in that tradition. However, in order to support large files, I've had 29 | to include the define -D_FILE_OFFSET_BITS=64 in the Makefile. This 30 | can cause problems. 31 | 32 | The technique of adding -D_FILE_OFFSET_BITS=64 to get large file 33 | support is, as far as I know, the Recommended Way to get correct large 34 | file support. For more details, see the Large File Support 35 | Specification, published by the Large File Summit, at 36 | 37 | http://ftp.sas.com/standards/large.file 38 | 39 | As a general comment, if you get compilation errors which you think 40 | are related to large file support, try removing the above define from 41 | the Makefile, ie, delete the line 42 | 43 | BIGFILES=-D_FILE_OFFSET_BITS=64 44 | 45 | from the Makefile, and do 'make clean ; make'. This will give you a 46 | version of bzip2 without large file support, which, for most 47 | applications, is probably not a problem. 48 | 49 | Alternatively, try some of the platform-specific hints listed below. 50 | 51 | You can use the spewG.c program to generate huge files to test bzip2's 52 | large file support, if you are feeling paranoid. Be aware though that 53 | any compilation problems which affect bzip2 will also affect spewG.c, 54 | alas. 55 | 56 | AIX: I have reports that for large file support, you need to specify 57 | -D_LARGE_FILES rather than -D_FILE_OFFSET_BITS=64. I have not tested 58 | this myself. 59 | -------------------------------------------------------------------------------- /README.XML.STUFF: -------------------------------------------------------------------------------- 1 | ---------------------------------------------------------------- 2 | This file is part of bzip2/libbzip2, a program and library for 3 | lossless, block-sorting data compression. 4 | 5 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 6 | Copyright (C) 1996-2010 Julian Seward 7 | 8 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 9 | README file. 10 | 11 | This program is released under the terms of the license contained 12 | in the file LICENSE. 13 | ---------------------------------------------------------------- 14 | 15 | The script xmlproc.sh takes an xml file as input, 16 | and processes it to create .pdf, .html or .ps output. 17 | It uses format.pl, a perl script to format
 blocks nicely,
18 |  and add CDATA tags so writers do not have to use eg. < 
19 | 
20 | The file "entities.xml" must be edited to reflect current
21 | version, year, etc.
22 | 
23 | 
24 | Usage:
25 | 
26 |   ./xmlproc.sh -v manual.xml
27 |   Validates an xml file to ensure no dtd-compliance errors
28 | 
29 |   ./xmlproc.sh -html manual.xml
30 |   Output: manual.html
31 | 
32 |   ./xmlproc.sh -pdf manual.xml
33 |   Output: manual.pdf
34 | 
35 |   ./xmlproc.sh -ps manual.xml
36 |   Output: manual.ps
37 | 
38 | 
39 | Notum bene: 
40 | - pdfxmltex barfs if given a filename with an underscore in it
41 | 
42 | - xmltex won't work yet - there's a bug in passivetex
43 |     which we are all waiting for Sebastian to fix.
44 |   So we are going the xml -> pdf -> ps route for the time being,
45 |     using pdfxmltex.
46 | 


--------------------------------------------------------------------------------
/bz-common.xsl:
--------------------------------------------------------------------------------
 1 |  
 2 | 
 4 | 
 5 | 
 6 |  
 7 | 
 8 | 
 9 | 
10 |  
11 |  
12 |    
13 |     
14 |       
15 |      
16 |   
17 | 
18 | 
19 | 
20 | 
21 | set       toc,title
22 | book      toc,title,figure,table,example,equation
23 | chapter   toc,title
24 | section   toc
25 | sect1     toc
26 | sect2     toc
27 | sect3     toc
28 | sect4     nop
29 | sect5     nop
30 | qandaset  toc
31 | qandadiv  nop
32 | appendix  toc,title
33 | article/appendix  nop
34 | article   toc,title
35 | preface   toc,title
36 | reference toc,title
37 | 
38 | 
39 | 
40 | 


--------------------------------------------------------------------------------
/bz-fo.xsl:
--------------------------------------------------------------------------------
  1 |  
  2 | 
  4 | 
  5 | 
  6 | 
  7 | 
  8 | 
  9 | 
 10 | 
 11 | 
 12 | 
 13 | 
 14 | 
 15 |       
 16 |      
 17 |    
 18 | 
 19 | 
 20 | 
 21 | 
 22 |  
 23 | 
 24 | 
 25 | 
 26 | 
 27 | 
 28 | 
 29 |   
 30 | 
 31 | 
 32 | 
 33 | 
 34 |   blue
 35 | 
 36 | 
 37 | 
 38 | 
 39 |   
 44 |     
 45 |   
 46 | 
 47 | 
 48 | 
 49 |   
 54 |     
 55 |   
 56 | 
 57 | 
 58 | 
 59 | 
 60 |   
 61 |   
 62 |   
 63 |     
 64 |       
 65 |     
 66 |   
 67 |   
 68 |     
 69 |       
 70 |         
 71 |           
 72 |           
 73 |           
 74 |         
 75 |       
 76 |     
 77 |     
 78 |           
 79 |     
 80 |   
 81 |   
 82 |     
 83 |       
 85 |         
 86 |       
 87 |     
 88 |     
 89 |       
 90 |         
 91 |       
 92 |     
 93 |   
 94 | 
 95 | 
 96 | 
 97 | 
 98 |   
 99 |   
100 |   
101 |     
102 |       
103 |         
104 |       
105 |     
106 |     
107 |           
108 |     
109 |   
110 |   
111 |     
112 |       
114 |         
115 |       
116 |     
117 |     
118 |       
119 |         
120 |       
121 |     
122 |   
123 | 
124 | 
125 | 
126 | 
127 | 
128 |   
129 |     
130 |   
133 |     
134 |   
135 |   
139 |     
140 |       
141 |     
142 |   
143 | 
144 | 
145 | 
146 | 
147 | 
148 |   
149 |   
150 |   
151 |   
152 |     
153 |       0pt
154 |     
155 |   
156 |   
157 |     
158 |       
159 |       
160 |       
161 |         
162 |           
163 |             baseline
164 |              
165 |                
166 |             
167 |           
168 |           
169 |             baseline
170 |             
171 |               
172 |                 
173 |                 
174 |                 
175 |                 
176 |               
177 |             
178 |           
179 |         
180 |       
181 |     
182 |   
183 |   
184 |   
185 |     
187 |       
188 |     
189 |     
190 |       
191 |     
192 |     
193 |       
194 |     
195 |   
196 | 
197 | 
198 | 
199 | 
200 | 
201 |   
202 |   
203 |   
204 |   
205 |     
206 |       0pt
207 |     
208 |   
209 |   
210 |     
211 |       
212 |         
213 |         
214 |         
215 |       
216 |       
217 |       
218 |       
219 |         
220 |           
221 |             baseline
222 |             
223 |                
224 |             
225 |           
226 |           
227 |             baseline
228 |             
229 |               
230 |                 
231 |                 
232 |                 
233 |                 
234 |               
235 |             
236 |           
237 |         
238 |       
239 |     
240 |   
241 |   
242 |   
243 |     
245 |       
246 |     
247 |     
248 |       
249 |     
250 |     
251 |       
252 |     
253 |   
254 | 
255 | 
256 | 
257 | 
258 | 
259 | 
260 |   always
261 |   
262 |     
263 |   
264 |   
265 |     
266 |     pt
267 |   
268 |   
269 |     
270 |     pt
271 |   
272 |   false
273 | 
274 | 
275 | 
276 | 
277 | 


--------------------------------------------------------------------------------
/bz-html.xsl:
--------------------------------------------------------------------------------
 1 |  
 2 |  ]>
 3 | 
 4 | 
 6 | 
 7 | 
 8 | 
 9 | 
10 | 
11 | 
12 | 
13 | 
14 |   
15 |   
18 | 
19 | 
20 | 
21 | 


--------------------------------------------------------------------------------
/bz2-driver-capnp.cc:
--------------------------------------------------------------------------------
  1 | // Copyright 2016 Google Inc. All Rights Reserved.
  2 | //
  3 | // Use of this source code is governed by the bzip2
  4 | // license that can be found in the LICENSE file.
  5 | 
  6 | #include 
  7 | #include 
  8 | #include 
  9 | #include 
 10 | #include 
 11 | #include 
 12 | #include 
 13 | #include 
 14 | #include 
 15 | #include 
 16 | #include 
 17 | #include 
 18 | #include 
 19 | #include 
 20 | #include 
 21 | #include 
 22 | 
 23 | #include "rpc-util.h"
 24 | 
 25 | #include 
 26 | #include 
 27 | 
 28 | #include "bzlib.capnp.h"
 29 | 
 30 | #include "bzlib.h"
 31 | 
 32 | int _rpc_verbose = 4;
 33 | int _rpc_indent = 4;
 34 | 
 35 | namespace bz2 {
 36 | 
 37 | class Bz2Impl final : public Bz2::Server {
 38 | public:
 39 |   Bz2Impl(int sock_fd) : Bz2::Server(), sock_fd_(sock_fd) {}
 40 |   kj::Promise compressStream(CompressStreamContext context) override {
 41 |     static const char *method = "BZ2_bzCompressStream";
 42 |     auto msg = context.getParams();
 43 |     int ifd_nonce = msg.getIfd();
 44 |     int ifd = GetTransferredFd(sock_fd_, ifd_nonce);
 45 |     int ofd_nonce = msg.getOfd();
 46 |     int ofd = GetTransferredFd(sock_fd_, ofd_nonce);
 47 |     int blockSize100k = msg.getBlockSize100k();
 48 |     int verbosity = msg.getVerbosity();
 49 |     int workFactor = msg.getWorkFactor();
 50 |     api_("=> %s(%d, %d, %d, %d, %d)", method, ifd, ofd, blockSize100k, verbosity, workFactor);
 51 |     int retval = BZ2_bzCompressStream(ifd, ofd, blockSize100k, verbosity, workFactor);
 52 |     api_("=> %s(%d, %d, %d, %d, %d) return %d", method, ifd, ofd, blockSize100k, verbosity, workFactor, retval);
 53 |     auto rsp = context.getResults();
 54 |     rsp.setResult(retval);
 55 |     close(ifd);
 56 |     close(ofd);
 57 |     return kj::READY_NOW;
 58 |   }
 59 |   kj::Promise decompressStream(DecompressStreamContext context) override {
 60 |     static const char *method = "BZ2_bzDecompressStream";
 61 |     auto msg = context.getParams();
 62 |     int ifd_nonce = msg.getIfd();
 63 |     int ifd = GetTransferredFd(sock_fd_, ifd_nonce);
 64 |     int ofd_nonce = msg.getOfd();
 65 |     int ofd = GetTransferredFd(sock_fd_, ofd_nonce);
 66 |     int verbosity = msg.getVerbosity();
 67 |     int small = msg.getSmall();
 68 |     api_("=> %s(%d, %d, %d, %d)", method, ifd, ofd, verbosity, small);
 69 |     int retval = BZ2_bzDecompressStream(ifd, ofd, verbosity, small);
 70 |     api_("=> %s(%d, %d, %d, %d) return %d", method, ifd, ofd, verbosity, small, retval);
 71 |     auto rsp = context.getResults();
 72 |     rsp.setResult(retval);
 73 |     close(ifd);
 74 |     close(ofd);
 75 |     return kj::READY_NOW;
 76 |   }
 77 |   kj::Promise testStream(TestStreamContext context) override {
 78 |     static const char *method = "BZ2_bzTestStream";
 79 |     auto msg = context.getParams();
 80 |     int ifd_nonce = msg.getIfd();
 81 |     int ifd = GetTransferredFd(sock_fd_, ifd_nonce);
 82 |     int verbosity = msg.getVerbosity();
 83 |     int small = msg.getSmall();
 84 |     api_("=> %s(%d, %d, %d)", method, ifd, verbosity, small);
 85 |     int retval = BZ2_bzTestStream(ifd, verbosity, small);
 86 |     api_("=> %s(%d, %d, %d) return %d", method, ifd, verbosity, small, retval);
 87 |     auto rsp = context.getResults();
 88 |     rsp.setResult(retval);
 89 |     close(ifd);
 90 |     return kj::READY_NOW;
 91 |   }
 92 |   kj::Promise libVersion(LibVersionContext context) override {
 93 |     static const char *method = "BZ2_bzlibVersion";
 94 |     api_("=> %s()", method);
 95 |     const char * retval = BZ2_bzlibVersion();
 96 |     api_("<= %s() return '%s'", method, retval);
 97 |     auto rsp = context.getResults();
 98 |     rsp.setVersion(retval);
 99 |     return kj::READY_NOW;
100 |   }
101 | 
102 | private:
103 |   int sock_fd_;
104 | };
105 | 
106 | }  // namespace bz2
107 | 
108 | int main(int argc, char *argv[]) {
109 |   signal(SIGSEGV, CrashHandler);
110 |   signal(SIGABRT, CrashHandler);
111 |   const char *fd_str = getenv("API_NONCE_FD");
112 |   assert (fd_str != NULL);
113 |   int sock_fd = atoi(fd_str);
114 |   api_("'%s' program start, parent socket %d", argv[0], sock_fd);
115 | 
116 |   // Build the address of a UNIX socket for the service.
117 |   const char *sockfile = tempnam(nullptr, "gsck");
118 |   std::string server_address = "unix:";
119 |   server_address += sockfile;
120 |   log_("listening on %s", server_address.c_str());
121 |   capnp::EzRpcServer server(kj::heap(sock_fd), server_address);
122 | 
123 |   // Tell the parent the address we're listening on.
124 |   uint32_t len = server_address.size() + 1;
125 |   int rc;
126 |   rc = write(sock_fd, &len, sizeof(len));
127 |   assert (rc == sizeof(len));
128 |   rc = write(sock_fd, server_address.c_str(), len);
129 |   assert ((uint32_t)rc == len);
130 | 
131 |   // Main loop
132 |   auto& waitScope = server.getWaitScope();
133 |   kj::NEVER_DONE.wait(waitScope);  // Run forever
134 |   api_("'%s' program stop", argv[0]);
135 |   return 0;
136 | }
137 | 


--------------------------------------------------------------------------------
/bz2-driver-grpc.cc:
--------------------------------------------------------------------------------
  1 | // Copyright 2016 Google Inc. All Rights Reserved.
  2 | //
  3 | // Use of this source code is governed by the bzip2
  4 | // license that can be found in the LICENSE file.
  5 | 
  6 | #include 
  7 | #include 
  8 | #include 
  9 | #include 
 10 | #include 
 11 | #include 
 12 | #include 
 13 | #include 
 14 | #include 
 15 | #include 
 16 | #include 
 17 | #include 
 18 | #include 
 19 | #include 
 20 | #include 
 21 | #include 
 22 | 
 23 | #include "rpc-util.h"
 24 | 
 25 | #include 
 26 | #include 
 27 | 
 28 | #include "bzlib.grpc.pb.h"
 29 | #include "bzlib.h"
 30 | 
 31 | int _rpc_verbose = 4;
 32 | int _rpc_indent = 4;
 33 | 
 34 | namespace bz2 {
 35 | 
 36 | class Bz2ServiceImpl final : public Bz2::Service {
 37 | public:
 38 |   Bz2ServiceImpl(int sock_fd) : Service(), sock_fd_(sock_fd) {}
 39 |   grpc::Status CompressStream(grpc::ServerContext* context,
 40 |                               const CompressStreamRequest* msg,
 41 |                               CompressStreamReply* rsp) {
 42 |     static const char *method = "BZ2_bzCompressStream";
 43 |     int ifd_nonce = msg->ifd();
 44 |     int ifd = GetTransferredFd(sock_fd_, ifd_nonce);
 45 |     int ofd_nonce = msg->ofd();
 46 |     int ofd = GetTransferredFd(sock_fd_, ofd_nonce);
 47 |     int blockSize100k = msg->blocksize100k();
 48 |     int verbosity = msg->verbosity();
 49 |     int workFactor = msg->workfactor();
 50 |     api_("=> %s(%d, %d, %d, %d, %d)", method, ifd, ofd, blockSize100k, verbosity, workFactor);
 51 |     int retval = BZ2_bzCompressStream(ifd, ofd, blockSize100k, verbosity, workFactor);
 52 |     api_("=> %s(%d, %d, %d, %d, %d) return %d", method, ifd, ofd, blockSize100k, verbosity, workFactor, retval);
 53 |     rsp->set_result(retval);
 54 |     close(ifd);
 55 |     close(ofd);
 56 |     return grpc::Status::OK;
 57 |   }
 58 |   grpc::Status DecompressStream(grpc::ServerContext* context,
 59 |                                 const DecompressStreamRequest* msg,
 60 |                                 DecompressStreamReply* rsp) {
 61 |     static const char *method = "BZ2_bzDecompressStream";
 62 |     int ifd_nonce = msg->ifd();
 63 |     int ifd = GetTransferredFd(sock_fd_, ifd_nonce);
 64 |     int ofd_nonce = msg->ofd();
 65 |     int ofd = GetTransferredFd(sock_fd_, ofd_nonce);
 66 |     int verbosity = msg->verbosity();
 67 |     int small = msg->small();
 68 |     api_("=> %s(%d, %d, %d, %d)", method, ifd, ofd, verbosity, small);
 69 |     int retval = BZ2_bzDecompressStream(ifd, ofd, verbosity, small);
 70 |     api_("=> %s(%d, %d, %d, %d) return %d", method, ifd, ofd, verbosity, small, retval);
 71 |     rsp->set_result(retval);
 72 |     close(ifd);
 73 |     close(ofd);
 74 |     return grpc::Status::OK;
 75 |   }
 76 |   grpc::Status TestStream(grpc::ServerContext* context,
 77 |                           const TestStreamRequest* msg,
 78 |                           TestStreamReply* rsp) {
 79 |     static const char *method = "BZ2_bzTestStream";
 80 |     int ifd_nonce = msg->ifd();
 81 |     int ifd = GetTransferredFd(sock_fd_, ifd_nonce);
 82 |     int verbosity = msg->verbosity();
 83 |     int small = msg->small();
 84 |     api_("=> %s(%d, %d, %d)", method, ifd, verbosity, small);
 85 |     int retval = BZ2_bzTestStream(ifd, verbosity, small);
 86 |     api_("=> %s(%d, %d, %d) return %d", method, ifd, verbosity, small, retval);
 87 |     rsp->set_result(retval);
 88 |     close(ifd);
 89 |     return grpc::Status::OK;
 90 |   }
 91 |   grpc::Status LibVersion(grpc::ServerContext* context,
 92 |                           const LibVersionRequest* msg,
 93 |                           LibVersionReply* rsp) {
 94 |     static const char *method = "BZ2_bzlibVersion";
 95 |     api_("=> %s()", method);
 96 |     const char * retval = BZ2_bzlibVersion();
 97 |     rsp->set_version(retval);
 98 |     api_("<= %s() return '%s'", method, retval);
 99 |     return grpc::Status::OK;
100 |   }
101 | 
102 | private:
103 |   int sock_fd_;
104 | };
105 | 
106 | }  // namespace bz2
107 | 
108 | int main(int argc, char *argv[]) {
109 |   signal(SIGSEGV, CrashHandler);
110 |   signal(SIGABRT, CrashHandler);
111 |   const char *fd_str = getenv("API_NONCE_FD");
112 |   assert (fd_str != NULL);
113 |   int sock_fd = atoi(fd_str);
114 |   api_("'%s' program start, parent socket %d", argv[0], sock_fd);
115 | 
116 |   // Build the address of a UNIX socket for the service.
117 |   const char *sockfile = tempnam(nullptr, "gsck");
118 |   std::string server_address = "unix:";
119 |   server_address += sockfile;
120 |   log_("listening on %s", server_address.c_str());
121 | 
122 |   grpc::ServerBuilder builder;
123 |   // Listen on the given address without any authentication mechanism.
124 |   builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
125 |   bz2::Bz2ServiceImpl service(sock_fd);
126 |   builder.RegisterService(&service);
127 |   std::unique_ptr server(builder.BuildAndStart());
128 | 
129 |   // Tell the parent the address we're listening on.
130 |   uint32_t len = server_address.size() + 1;
131 |   int rc;
132 |   rc = write(sock_fd, &len, sizeof(len));
133 |   assert (rc == sizeof(len));
134 |   rc = write(sock_fd, server_address.c_str(), len);
135 |   assert ((uint32_t)rc == len);
136 | 
137 |   // Main loop
138 |   server->Wait();
139 | 
140 |   api_("'%s' program stop", argv[0]);
141 |   return 0;
142 | }
143 | 


--------------------------------------------------------------------------------
/bz2-driver-libnv.c:
--------------------------------------------------------------------------------
  1 | /* Copyright 2016 Google Inc. All Rights Reserved.
  2 |  *
  3 |  * Use of this source code is governed by the bzip2
  4 |  * license that can be found in the LICENSE file. */
  5 | 
  6 | #include 
  7 | #include 
  8 | #include 
  9 | #include 
 10 | #include 
 11 | #include 
 12 | #include 
 13 | #include 
 14 | #include 
 15 | #include 
 16 | #include 
 17 | #include 
 18 | #include 
 19 | #include 
 20 | 
 21 | #include 
 22 | 
 23 | #include "rpc-util.h"
 24 | #include "bzlib.h"
 25 | 
 26 | int _rpc_verbose = 4;
 27 | int _rpc_indent = 4;
 28 | 
 29 | /* API-specfic message handler prototype */
 30 | nvlist_t *APIMessageHandler(const nvlist_t *msg);
 31 | 
 32 | static void MainLoop(int sock_fd) {
 33 |   while (1) {
 34 |     verbose_("blocking read from fd %d...", sock_fd);
 35 |     nvlist_t *msg = nvlist_recv(sock_fd, 0);
 36 |     verbose_("handle incoming request on fd %d...", sock_fd);
 37 |     nvlist_t *rsp = APIMessageHandler(msg);
 38 |     nvlist_destroy(msg);
 39 |     if (rsp) {
 40 |       verbose_("send response on fd %d", sock_fd);
 41 |       int rc = nvlist_send(sock_fd, rsp);
 42 |       if (rc != 0) {
 43 |         error_("failed to send response, %d", errno);
 44 |       }
 45 |       nvlist_destroy(rsp);
 46 |     }
 47 |   }
 48 | }
 49 | 
 50 | int main(int argc, char *argv[]) {
 51 |   signal(SIGSEGV, CrashHandler);
 52 |   signal(SIGABRT, CrashHandler);
 53 |   const char *fd_str = getenv("API_NONCE_FD");
 54 |   assert (fd_str != NULL);
 55 |   int sock_fd = atoi(fd_str);
 56 |   api_("'%s' program start, parent socket %d", argv[0], sock_fd);
 57 | 
 58 |   MainLoop(sock_fd);
 59 | 
 60 |   api_("'%s' program stop", argv[0]);
 61 |   return 0;
 62 | }
 63 | 
 64 | 
 65 | /*****************************************************************************/
 66 | /* Everything above here is generic, and would be useful for any remoted API */
 67 | /*****************************************************************************/
 68 | 
 69 | static int proxied_BZ2_bzCompressStream(const nvlist_t *msg, nvlist_t *rsp) {
 70 |   static const char *method = "BZ2_bzCompressStream";
 71 |   int ifd = nvlist_get_descriptor(msg, "ifd");
 72 |   int ofd = nvlist_get_descriptor(msg, "ofd");
 73 |   int blockSize100k = nvlist_get_number(msg, "blockSize100k");
 74 |   int verbosity = nvlist_get_number(msg, "verbosity");
 75 |   int workFactor = nvlist_get_number(msg, "workFactor");
 76 | 
 77 |   api_("=> %s(%d, %d, %d, %d, %d)", method, ifd, ofd, blockSize100k, verbosity, workFactor);
 78 |   int retval = BZ2_bzCompressStream(ifd, ofd, blockSize100k, verbosity, workFactor);
 79 | 
 80 |   api_("=> %s(%d, %d, %d, %d, %d) return %d", method, ifd, ofd, blockSize100k, verbosity, workFactor, retval);
 81 |   nvlist_add_number(rsp, "retval", retval);
 82 |   return 0;
 83 | }
 84 | 
 85 | static int proxied_BZ2_bzDecompressStream(const nvlist_t *msg, nvlist_t *rsp) {
 86 |   static const char *method = "BZ2_bzDecompressStream";
 87 |   int ifd = nvlist_get_descriptor(msg, "ifd");
 88 |   int ofd = nvlist_get_descriptor(msg, "ofd");
 89 |   int verbosity = nvlist_get_number(msg, "verbosity");
 90 |   int small = nvlist_get_number(msg, "small");
 91 | 
 92 |   api_("=> %s(%d, %d, %d, %d)", method, ifd, ofd, verbosity, small);
 93 |   int retval = BZ2_bzDecompressStream(ifd, ofd, verbosity, small);
 94 | 
 95 |   api_("=> %s(%d, %d, %d, %d) return %d", method, ifd, ofd, verbosity, small, retval);
 96 |   nvlist_add_number(rsp, "retval", retval);
 97 |   return 0;
 98 | }
 99 | 
100 | static int proxied_BZ2_bzTestStream(const nvlist_t *msg, nvlist_t *rsp) {
101 |   static const char *method = "BZ2_bzTestStream";
102 |   int ifd = nvlist_get_descriptor(msg, "ifd");
103 |   int verbosity = nvlist_get_number(msg, "verbosity");
104 |   int small = nvlist_get_number(msg, "small");
105 | 
106 |   api_("=> %s(%d, %d, %d)", method, ifd, verbosity, small);
107 |   int retval = BZ2_bzTestStream(ifd, verbosity, small);
108 | 
109 |   api_("=> %s(%d, %d, %d) return %d", method, ifd, verbosity, small, retval);
110 |   nvlist_add_number(rsp, "retval", retval);
111 |   return 0;
112 | }
113 | 
114 | static int proxied_BZ2_bzlibVersion(const nvlist_t *msg, nvlist_t *rsp) {
115 |   static const char *method = "BZ2_bzlibVersion";
116 |   api_("=> %s()", method);
117 |   const char * retval = BZ2_bzlibVersion();
118 |   api_("=> %s()", method);
119 |   nvlist_add_string(rsp, "retval", retval);
120 |   return 0;
121 | }
122 | 
123 | /* This is the general entrypoint for this specific API */
124 | nvlist_t *APIMessageHandler(const nvlist_t *msg) {
125 |   nvlist_t *rsp = nvlist_create(0);
126 |   const char *cmd = nvlist_get_string(msg, "cmd");
127 |   int rc;
128 | 
129 |   if (strcmp(cmd, "BZ2_bzCompressStream") == 0) {
130 |     rc = proxied_BZ2_bzCompressStream(msg, rsp);
131 |   } else if (strcmp(cmd, "BZ2_bzDecompressStream") == 0) {
132 |     rc = proxied_BZ2_bzDecompressStream(msg, rsp);
133 |   } else if (strcmp(cmd, "BZ2_bzTestStream") == 0) {
134 |     rc = proxied_BZ2_bzTestStream(msg, rsp);
135 |   } else if (strcmp(cmd, "BZ2_bzlibVersion") == 0) {
136 |     rc = proxied_BZ2_bzlibVersion(msg, rsp);
137 |   } else {
138 |     rc = -1;
139 |   }
140 |   if (rc != 0) {
141 |     nvlist_destroy(rsp);
142 |     rsp = NULL;
143 |   }
144 |   return rsp;
145 | }
146 | 


--------------------------------------------------------------------------------
/bz2-stub-capnp.cc:
--------------------------------------------------------------------------------
  1 | // Copyright 2016 Google Inc. All Rights Reserved.
  2 | //
  3 | // Use of this source code is governed by the bzip2
  4 | // license that can be found in the LICENSE file.
  5 | 
  6 | #include 
  7 | #include 
  8 | #include 
  9 | #include 
 10 | #include 
 11 | #include 
 12 | #include 
 13 | #include 
 14 | #include 
 15 | #include 
 16 | #include 
 17 | #include 
 18 | 
 19 | #include "rpc-util.h"
 20 | 
 21 | #include 
 22 | #include 
 23 | 
 24 | #include "bzlib.capnp.h"
 25 | 
 26 | int _rpc_verbose = 4;  // smaller number => more verbose
 27 | int _rpc_indent = 0;
 28 | 
 29 | static const char *g_exe_file = "./bz2-driver-capnp";
 30 | static int g_exe_fd = -1;  // File descriptor to driver executable
 31 | /* Before main(), get an FD for the driver program, so that it is still
 32 |    accessible even if the application enters a sandbox. */
 33 | void __attribute__((constructor)) _stub_construct(void) {
 34 |   g_exe_fd = OpenDriver(g_exe_file);
 35 | }
 36 | 
 37 | class DriverConnection {
 38 | public:
 39 |   DriverConnection() : pid_(-1), server_address_(nullptr) {
 40 |     // Create socket for bootstrap communication with child.
 41 |     int socket_fds[2] = {-1, -1};
 42 |     int rc = socketpair(AF_UNIX, SOCK_STREAM, 0, socket_fds);
 43 |     if (rc < 0) {
 44 |       fatal_("failed to open sockets, errno=%d (%s)", errno, strerror(errno));
 45 |     }
 46 |     api_("DriverConnection(g_exe_fd=%d, '%s')", g_exe_fd, g_exe_file);
 47 | 
 48 |     pid_ = fork();
 49 |     if (pid_ < 0) {
 50 |       fatal_("failed to fork, errno=%d (%s)", errno, strerror(errno));
 51 |     }
 52 | 
 53 |     if (pid_ == 0) {
 54 |       // Child process: run the driver
 55 |       close(socket_fds[0]);
 56 |       RunDriver(g_exe_fd, g_exe_file, socket_fds[1]);
 57 |     }
 58 |     sock_fd_ = socket_fds[0];
 59 |     close(socket_fds[1]);
 60 | 
 61 |     // Read bootstrap information back from the child:
 62 |     // uint32_t len, char server_addr[len]
 63 |     uint32_t len;
 64 |     rc = read(sock_fd_, &len, sizeof(len));
 65 |     assert (rc == sizeof(len));
 66 |     server_address_ = (char *)malloc(len);
 67 |     rc = read(sock_fd_, server_address_, len);
 68 |     assert (len == (uint32_t)rc);
 69 | 
 70 |     client_.reset(new capnp::EzRpcClient(server_address_));
 71 |   }
 72 | 
 73 |   ~DriverConnection() {
 74 |     api_("~DriverConnection({pid=%d})", pid_);
 75 |     close(sock_fd_);
 76 |     if (pid_ > 0) {
 77 |       TerminateChild(pid_);
 78 |       pid_ = 0;
 79 |     }
 80 |     if (server_address_) {
 81 |       char *filename = server_address_;
 82 |       if (strncmp(filename, "unix:", 5) == 0) filename += 5;
 83 |       log_("remove socket file '%s'", filename);
 84 |       unlink(filename);
 85 |       free(server_address_);
 86 |     }
 87 |   }
 88 | 
 89 |   capnp::EzRpcClient* client() {return client_.get();}
 90 |   bz2::Bz2::Client cap() {return client_->getMain();}
 91 |   int sock_fd() {return sock_fd_;}
 92 | 
 93 | private:
 94 |   pid_t pid_;  // Child process ID.
 95 |   int sock_fd_;
 96 |   char* server_address_;
 97 |   std::unique_ptr client_;
 98 | };
 99 | 
100 | //***************************************************************************
101 | //* Everything above here is generic, and would be useful for any remoted API
102 | //***************************************************************************
103 | 
104 | 
105 | 
106 | // RPC-Forwarding versions of libbz2 entrypoints
107 | 
108 | extern "C"
109 | int BZ2_bzCompressStream(int ifd, int ofd, int blockSize100k, int verbosity, int workFactor) {
110 |   static const char *method = "BZ2_bzCompressStream";
111 |   DriverConnection conn;
112 |   auto& waitScope = conn.client()->getWaitScope();
113 |   bz2::Bz2::Client cap = conn.cap();
114 |   auto msg = cap.compressStreamRequest();
115 |   int ifd_nonce = TransferFd(conn.sock_fd(), ifd);
116 |   msg.setIfd(ifd_nonce);
117 |   int ofd_nonce = TransferFd(conn.sock_fd(), ofd);
118 |   msg.setOfd(ofd_nonce);
119 |   msg.setBlockSize100k(blockSize100k);
120 |   msg.setVerbosity(verbosity);
121 |   msg.setWorkFactor(workFactor);
122 |   api_("%s(%d, %d, %d, %d, %d) =>", method, ifd, ofd, blockSize100k, verbosity, workFactor);
123 |   auto promise = msg.send();
124 |   auto rsp = promise.wait(waitScope);  // blocks till reply arrives
125 |   int retval = rsp.getResult();
126 |   api_("%s(%d, %d, %d, %d, %d) return %d <=", method, ifd, ofd, blockSize100k, verbosity, workFactor, retval);
127 |   return retval;
128 | }
129 | 
130 | extern "C"
131 | int BZ2_bzDecompressStream(int ifd, int ofd, int verbosity, int small) {
132 |   static const char *method = "BZ2_bzDecompressStream";
133 |   DriverConnection conn;
134 |   auto& waitScope = conn.client()->getWaitScope();
135 |   bz2::Bz2::Client cap = conn.cap();
136 |   auto msg = cap.decompressStreamRequest();
137 |   int ifd_nonce = TransferFd(conn.sock_fd(), ifd);
138 |   msg.setIfd(ifd_nonce);
139 |   int ofd_nonce = TransferFd(conn.sock_fd(), ofd);
140 |   msg.setOfd(ofd_nonce);
141 |   msg.setVerbosity(verbosity);
142 |   msg.setSmall(small);
143 |   api_("%s(%d, %d, %d, %d) =>", method, ifd, ofd, verbosity, small);
144 |   auto promise = msg.send();
145 |   auto rsp = promise.wait(waitScope);  // blocks till reply arrives
146 |   int retval = rsp.getResult();
147 |   api_("%s(%d, %d, %d, %d) return %d <=", method, ifd, ofd, verbosity, small, retval);
148 |   return retval;
149 | }
150 | 
151 | extern "C"
152 | int BZ2_bzTestStream(int ifd, int verbosity, int small) {
153 |   static const char *method = "BZ2_bzTestStream";
154 |   DriverConnection conn;
155 |   auto& waitScope = conn.client()->getWaitScope();
156 |   bz2::Bz2::Client cap = conn.cap();
157 |   auto msg = cap.testStreamRequest();
158 |   int ifd_nonce = TransferFd(conn.sock_fd(), ifd);
159 |   msg.setIfd(ifd_nonce);
160 |   msg.setVerbosity(verbosity);
161 |   msg.setSmall(small);
162 |   api_("%s(%d, %d, %d) =>", method, ifd, verbosity, small);
163 |   auto promise = msg.send();
164 |   auto rsp = promise.wait(waitScope);  // blocks till reply arrives
165 |   int retval = rsp.getResult();
166 |   api_("%s(%d, %d, %d) return %d <=", method, ifd, verbosity, small, retval);
167 |   return retval;
168 | }
169 | 
170 | extern "C"
171 | const char *BZ2_bzlibVersion(void) {
172 |   static const char *method = "BZ2_bzlibVersion";
173 |   static const char *saved_version = NULL;
174 |   if (saved_version) {
175 |     api_("%s() return '%s' <= (saved)", method, saved_version);
176 |     return saved_version;
177 |   }
178 |   DriverConnection conn;
179 |   auto& waitScope = conn.client()->getWaitScope();
180 |   bz2::Bz2::Client cap = conn.cap();
181 |   auto msg = cap.libVersionRequest();
182 |   api_("%s() =>", method);
183 |   auto promise = msg.send();
184 |   auto rsp = promise.wait(waitScope);  // blocks till reply arrives
185 |   std::string version = rsp.getVersion();
186 |   api_("%s() return '%s' <=", method, version.c_str());
187 |   saved_version = strdup(version.c_str());
188 |   return saved_version;
189 | }
190 | 


--------------------------------------------------------------------------------
/bz2-stub-dbus.c:
--------------------------------------------------------------------------------
  1 | /* Copyright 2016 Google Inc. All Rights Reserved.
  2 |  *
  3 |  * Use of this source code is governed by the bzip2
  4 |  * license that can be found in the LICENSE file. */
  5 | 
  6 | #include 
  7 | #include 
  8 | #include 
  9 | #include 
 10 | #include 
 11 | #include 
 12 | #include 
 13 | #include 
 14 | #include 
 15 | #include 
 16 | 
 17 | #include 
 18 | 
 19 | #include "rpc-util.h"
 20 | 
 21 | int _rpc_verbose = 4;  /* smaller number => more verbose */
 22 | int _rpc_indent = 0;
 23 | 
 24 | static const char *g_exe_file = "./bz2-driver-dbus";
 25 | static int g_exe_fd = -1;  /* File descriptor to driver executable */
 26 | /* Before main(), get an FD for the driver program, so that it is still
 27 |    accessible even if the application enters a sandbox. */
 28 | void __attribute__((constructor)) _stub_construct(void) {
 29 |   g_exe_fd = OpenDriver(g_exe_file);
 30 | }
 31 | 
 32 | #define DRIVER_OBJECT_PATH_PATTERN "/nonce/xxxxxxxxxxx"
 33 | #define DRIVER_OBJECT_PATH_LEN     20
 34 | struct DriverConnection {
 35 |   /* Child process ID for the driver process */
 36 |   pid_t pid;
 37 |   /* DBus connection to driver process */
 38 |   DBusConnection *dbus;
 39 |   /* DBus object path '/nonce/xxxxxxxxxxx' */
 40 |   char objpath[DRIVER_OBJECT_PATH_LEN];
 41 | } g_conn;
 42 | 
 43 | 
 44 | static DBusMessage *ConnectionNewRequest(struct DriverConnection *conn, const char *method) {
 45 |   return dbus_message_new_method_call(NULL, conn->objpath, NULL, method);
 46 | }
 47 | 
 48 | static DBusMessage *ConnectionBlockingSendReply(struct DriverConnection *conn,
 49 |                                                 DBusMessage *req, DBusError *err) {
 50 |   DBusMessage *rsp = NULL;
 51 |   if (!(rsp = dbus_connection_send_with_reply_and_block(conn->dbus, req, -1, err))) {
 52 |     error_("!!! send_with_reply_and_block failed: %s: %s", err->name, err->message);
 53 |     return NULL;
 54 |   }
 55 |   dbus_message_unref(req);
 56 |   return rsp;
 57 | }
 58 | 
 59 | static void DestroyConnection(struct DriverConnection *conn) {
 60 |   api_("DestroyConnection(conn=%p {pid=%d dbus_conn=%p objpath='%s'})",
 61 |        conn, conn->pid, conn->dbus, conn->objpath);
 62 | 
 63 |   if (conn->dbus) {
 64 |     verbose_("close and unref DBus conn=%p", conn->dbus);
 65 |     dbus_connection_close(conn->dbus);
 66 |     dbus_connection_unref(conn->dbus);
 67 |     conn->dbus = NULL;
 68 |   }
 69 |   if (conn->pid > 0) {
 70 |     TerminateChild(conn->pid);
 71 |     conn->pid = 0;
 72 |   }
 73 | }
 74 | 
 75 | static struct DriverConnection *CreateConnection(void) {
 76 |   struct DriverConnection *conn = &g_conn;
 77 |   /* Create socket for bootstrap communication with child */
 78 |   int socket_fds[2] = {-1, -1};
 79 |   int rc = socketpair(AF_UNIX, SOCK_STREAM, 0, socket_fds);
 80 |   if (rc < 0) {
 81 |     error_("failed to open sockets, errno=%d (%s)", errno, strerror(errno));
 82 |     return NULL;
 83 |   }
 84 | 
 85 |   api_("CreateConnection(g_exe_fd=%d, '%s')", g_exe_fd, g_exe_file);
 86 | 
 87 |   conn->pid = fork();
 88 |   if (conn->pid < 0) {
 89 |     error_("failed to fork, errno=%d (%s)", errno, strerror(errno));
 90 |     return NULL;
 91 |   }
 92 | 
 93 |   if (conn->pid == 0) {
 94 |     /* Child process: run the driver */
 95 |     close(socket_fds[0]);
 96 |     RunDriver(g_exe_fd, g_exe_file, socket_fds[1]);
 97 |   }
 98 | 
 99 |   /* Read bootstrap information back from the child */
100 |   /* First: uint32_t len, char server_add[len] */
101 |   uint32_t len;
102 |   rc = read(socket_fds[0], &len, sizeof(len));
103 |   assert (rc == sizeof(len));
104 |   char *server_address = (char *)malloc(len);
105 |   rc = read(socket_fds[0], server_address, len);
106 |   assert (rc == len);
107 |   /* Second: uint64_t nonce (used to confirm that the D-Bus connection we set up
108 |    * later is indeed to the child process */
109 |   uint64_t nonce;
110 |   rc = read(socket_fds[0], &nonce, sizeof(nonce));
111 |   assert (rc == sizeof(nonce));
112 |   verbose_("started child process %d, read socket name '%s', nonce %ld",
113 |            conn->pid, server_address, nonce);
114 |   close(socket_fds[0]);
115 |   close(socket_fds[1]);
116 |   snprintf(conn->objpath, 20, "/nonce/%ld", nonce);
117 | 
118 |   /* Initialize D-Bus private connection; use the nonce as the object address */
119 |   DBusError err;
120 |   dbus_error_init(&err);
121 |   conn->dbus = dbus_connection_open_private(server_address, &err);
122 |   if (!conn->dbus) {
123 |     error_("!!! dbus_connection_open_private failed: %s: %s\n", err.name, err.message);
124 |     free(server_address);
125 |     DestroyConnection(conn);
126 |     return NULL;
127 |   }
128 |   log_("got connection %p to private bus '%s' with {pid=%d dbus_conn=%p objpath='%s'})",
129 |        conn, server_address, conn->pid, conn->dbus, conn->objpath);
130 |   free(server_address);
131 | 
132 |   /* Send a no-op message to work around a D-Bus problem (if the first message sent
133 |      includes a file descriptor, it fails). */
134 |   DBusMessage *req = ConnectionNewRequest(conn, "__noop");
135 |   DBusMessage *rsp = ConnectionBlockingSendReply(conn, req, &err);
136 |   if (rsp == NULL) {
137 |     DestroyConnection(conn);
138 |     return NULL;
139 |   }
140 |   dbus_message_unref(rsp);
141 | 
142 |   return conn;
143 | }
144 | 
145 | 
146 | /*****************************************************************************/
147 | /* Everything above here is generic, and would be useful for any remoted API */
148 | /*****************************************************************************/
149 | 
150 | 
151 | 
152 | /* RPC-Forwarding versions of libbz2 entrypoints */
153 | 
154 | int BZ2_bzCompressStream(int ifd, int ofd, int blockSize100k, int verbosity, int workFactor) {
155 |   static const char *method = "BZ2_bzCompressStream";
156 |   struct DriverConnection *conn = CreateConnection();
157 |   DBusMessage *msg = ConnectionNewRequest(conn, method);
158 | 
159 |   DBusMessageIter msg_it;
160 |   dbus_message_iter_init_append(msg, &msg_it);
161 |   dbus_int32_t vx;
162 |   vx = ifd;
163 |   dbus_message_iter_append_basic(&msg_it, DBUS_TYPE_UNIX_FD, &vx);
164 |   vx = ofd;
165 |   dbus_message_iter_append_basic(&msg_it, DBUS_TYPE_UNIX_FD, &vx);
166 |   vx = blockSize100k;
167 |   dbus_message_iter_append_basic(&msg_it, DBUS_TYPE_INT32, &vx);
168 |   vx = verbosity;
169 |   dbus_message_iter_append_basic(&msg_it, DBUS_TYPE_INT32, &vx);
170 |   vx = workFactor;
171 |   dbus_message_iter_append_basic(&msg_it, DBUS_TYPE_INT32, &vx);
172 | 
173 |   DBusError err;
174 |   dbus_error_init(&err);
175 |   api_("%s(%d, %d, %d, %d, %d) =>", method, ifd, ofd, blockSize100k, verbosity, workFactor);
176 |   DBusMessage *rsp = ConnectionBlockingSendReply(conn, msg, &err);
177 |   assert (rsp != NULL);
178 | 
179 |   DBusMessageIter rsp_it;
180 |   dbus_message_iter_init(rsp, &rsp_it);
181 |   assert (dbus_message_iter_get_arg_type(&rsp_it) == DBUS_TYPE_INT32);
182 |   dbus_message_iter_get_basic(&rsp_it, &vx);
183 |   dbus_message_iter_next(&rsp_it);
184 |   int retval = vx;
185 |   api_("%s(%d, %d, %d, %d, %d) return %d <=", method, ifd, ofd, blockSize100k, verbosity, workFactor, retval);
186 |   dbus_message_unref(rsp);
187 |   DestroyConnection(conn);
188 |   return retval;
189 | }
190 | 
191 | int BZ2_bzDecompressStream(int ifd, int ofd, int verbosity, int small) {
192 |   static const char *method = "BZ2_bzDecompressStream";
193 |   struct DriverConnection *conn = CreateConnection();
194 |   DBusMessage *msg = ConnectionNewRequest(conn, method);
195 | 
196 |   DBusMessageIter msg_it;
197 |   dbus_message_iter_init_append(msg, &msg_it);
198 |   dbus_int32_t vx;
199 |   vx = ifd;
200 |   dbus_message_iter_append_basic(&msg_it, DBUS_TYPE_UNIX_FD, &vx);
201 |   vx = ofd;
202 |   dbus_message_iter_append_basic(&msg_it, DBUS_TYPE_UNIX_FD, &vx);
203 |   vx = verbosity;
204 |   dbus_message_iter_append_basic(&msg_it, DBUS_TYPE_INT32, &vx);
205 |   vx = small;
206 |   dbus_message_iter_append_basic(&msg_it, DBUS_TYPE_INT32, &vx);
207 | 
208 |   DBusError err;
209 |   dbus_error_init(&err);
210 |   api_("%s(%d, %d, %d, %d) =>", method, ifd, ofd, verbosity, small);
211 |   DBusMessage *rsp = ConnectionBlockingSendReply(conn, msg, &err);
212 |   assert (rsp != NULL);
213 | 
214 |   DBusMessageIter rsp_it;
215 |   dbus_message_iter_init(rsp, &rsp_it);
216 |   assert (dbus_message_iter_get_arg_type(&rsp_it) == DBUS_TYPE_INT32);
217 |   dbus_message_iter_get_basic(&rsp_it, &vx);
218 |   dbus_message_iter_next(&rsp_it);
219 |   int retval = vx;
220 |   api_("%s(%d, %d, %d, %d) return %d <=", method, ifd, ofd, verbosity, small, retval);
221 |   dbus_message_unref(rsp);
222 |   DestroyConnection(conn);
223 |   return retval;
224 | }
225 | 
226 | int BZ2_bzTestStream(int ifd, int verbosity, int small) {
227 |   static const char *method = "BZ2_bzTestStream";
228 |   struct DriverConnection *conn = CreateConnection();
229 |   DBusMessage *msg = ConnectionNewRequest(conn, method);
230 | 
231 |   DBusMessageIter msg_it;
232 |   dbus_message_iter_init_append(msg, &msg_it);
233 |   dbus_int32_t vx;
234 |   vx = ifd;
235 |   dbus_message_iter_append_basic(&msg_it, DBUS_TYPE_UNIX_FD, &vx);
236 |   vx = verbosity;
237 |   dbus_message_iter_append_basic(&msg_it, DBUS_TYPE_INT32, &vx);
238 |   vx = small;
239 |   dbus_message_iter_append_basic(&msg_it, DBUS_TYPE_INT32, &vx);
240 | 
241 |   DBusError err;
242 |   dbus_error_init(&err);
243 |   api_("%s(%d, %d, %d) =>", method, ifd, verbosity, small);
244 |   DBusMessage *rsp = ConnectionBlockingSendReply(conn, msg, &err);
245 |   assert (rsp != NULL);
246 | 
247 |   DBusMessageIter rsp_it;
248 |   dbus_message_iter_init(rsp, &rsp_it);
249 |   assert (dbus_message_iter_get_arg_type(&rsp_it) == DBUS_TYPE_INT32);
250 |   dbus_message_iter_get_basic(&rsp_it, &vx);
251 |   dbus_message_iter_next(&rsp_it);
252 |   int retval = vx;
253 |   api_("%s(%d, %d, %d) return %d <=", method, ifd, verbosity, small, retval);
254 |   dbus_message_unref(rsp);
255 |   DestroyConnection(conn);
256 |   return retval;
257 | }
258 | 
259 | const char *BZ2_bzlibVersion(void) {
260 |   static const char *method = "BZ2_bzlibVersion";
261 |   static const char *saved_version = NULL;
262 |   if (saved_version) {
263 |     api_("%s() return '%s' <= (saved)", method, saved_version);
264 |     return saved_version;
265 |   }
266 | 
267 |   struct DriverConnection *conn = CreateConnection();
268 |   DBusMessage *msg = ConnectionNewRequest(conn, method);
269 | 
270 |   DBusError err;
271 |   dbus_error_init(&err);
272 |   api_("%s() =>", method);
273 |   DBusMessage *rsp = ConnectionBlockingSendReply(conn, msg, &err);
274 |   assert (rsp != NULL);
275 | 
276 |   DBusMessageIter rsp_it;
277 |   dbus_message_iter_init(rsp, &rsp_it);
278 |   assert (dbus_message_iter_get_arg_type(&rsp_it) == DBUS_TYPE_STRING);
279 |   const char *retval;
280 |   dbus_message_iter_get_basic(&rsp_it, &retval);
281 |   dbus_message_iter_next(&rsp_it);
282 |   api_("%s() return '%s' <=", method, retval);
283 |   saved_version = strdup(retval);
284 |   dbus_message_unref(rsp);
285 |   DestroyConnection(conn);
286 |   return saved_version;
287 | }
288 | 


--------------------------------------------------------------------------------
/bz2-stub-grpc.cc:
--------------------------------------------------------------------------------
  1 | // Copyright 2016 Google Inc. All Rights Reserved.
  2 | //
  3 | // Use of this source code is governed by the bzip2
  4 | // license that can be found in the LICENSE file.
  5 | 
  6 | #include 
  7 | #include 
  8 | #include 
  9 | #include 
 10 | #include 
 11 | #include 
 12 | #include 
 13 | #include 
 14 | #include 
 15 | #include 
 16 | #include 
 17 | #include 
 18 | 
 19 | #include "rpc-util.h"
 20 | 
 21 | #include 
 22 | #include 
 23 | 
 24 | #include "bzlib.grpc.pb.h"
 25 | 
 26 | int _rpc_verbose = 4;  // smaller number => more verbose
 27 | int _rpc_indent = 0;
 28 | 
 29 | static const char *g_exe_file = "./bz2-driver-grpc";
 30 | static int g_exe_fd = -1;  // File descriptor to driver executable
 31 | /* Before main(), get an FD for the driver program, so that it is still
 32 |    accessible even if the application enters a sandbox. */
 33 | void __attribute__((constructor)) _stub_construct(void) {
 34 |   g_exe_fd = OpenDriver(g_exe_file);
 35 | }
 36 | 
 37 | class DriverConnection {
 38 | public:
 39 |   DriverConnection() : pid_(-1), server_address_(nullptr), stub_() {
 40 |     // Create socket for bootstrap communication with child.
 41 |     int socket_fds[2] = {-1, -1};
 42 |     int rc = socketpair(AF_UNIX, SOCK_STREAM, 0, socket_fds);
 43 |     if (rc < 0) {
 44 |       fatal_("failed to open sockets, errno=%d (%s)", errno, strerror(errno));
 45 |     }
 46 |     api_("DriverConnection(g_exe_fd=%d, '%s')", g_exe_fd, g_exe_file);
 47 | 
 48 |     pid_ = fork();
 49 |     if (pid_ < 0) {
 50 |       fatal_("failed to fork, errno=%d (%s)", errno, strerror(errno));
 51 |     }
 52 | 
 53 |     if (pid_ == 0) {
 54 |       close(socket_fds[0]);
 55 |       // Child process: run the driver
 56 |       RunDriver(g_exe_fd, g_exe_file, socket_fds[1]);
 57 |     }
 58 |     sock_fd_ = socket_fds[0];
 59 |     close(socket_fds[1]);
 60 | 
 61 |     // Read bootstrap information back from the child:
 62 |     // uint32_t len, char server_addr[len]
 63 |     uint32_t len;
 64 |     rc = read(sock_fd_, &len, sizeof(len));
 65 |     assert (rc == sizeof(len));
 66 |     server_address_ = (char *)malloc(len);
 67 |     rc = read(sock_fd_, server_address_, len);
 68 |     assert (len == (uint32_t)rc);
 69 | 
 70 |     std::shared_ptr channel = grpc::CreateChannel(
 71 |       server_address_, grpc::InsecureChannelCredentials());
 72 |     stub_ = bz2::Bz2::NewStub(channel);
 73 |   }
 74 | 
 75 |   ~DriverConnection() {
 76 |     api_("~DriverConnection({pid=%d})", pid_);
 77 |     close(sock_fd_);
 78 |     if (pid_ > 0) {
 79 |       TerminateChild(pid_);
 80 |       pid_ = 0;
 81 |     }
 82 |     if (server_address_) {
 83 |       char *filename = server_address_;
 84 |       if (strncmp(filename, "unix:", 5) == 0) filename += 5;
 85 |       log_("remove socket file '%s'", filename);
 86 |       unlink(filename);
 87 |       free(server_address_);
 88 |     }
 89 |   }
 90 | 
 91 |   bz2::Bz2::Stub *stub() {return stub_.get();}
 92 |   int sock_fd() {return sock_fd_;}
 93 | 
 94 | private:
 95 |   pid_t pid_;  // Child process ID.
 96 |   int sock_fd_;
 97 |   char* server_address_;
 98 |   std::unique_ptr stub_;
 99 | };
100 | 
101 | //***************************************************************************
102 | //* Everything above here is generic, and would be useful for any remoted API
103 | //***************************************************************************
104 | 
105 | 
106 | 
107 | // RPC-Forwarding versions of libbz2 entrypoints
108 | 
109 | extern "C"
110 | int BZ2_bzCompressStream(int ifd, int ofd, int blockSize100k, int verbosity, int workFactor) {
111 |   static const char *method = "BZ2_bzCompressStream";
112 |   DriverConnection conn;
113 |   bz2::CompressStreamRequest msg;
114 |   bz2::CompressStreamReply rsp;
115 |   grpc::ClientContext context;
116 |   int ifd_nonce = TransferFd(conn.sock_fd(), ifd);
117 |   msg.set_ifd(ifd_nonce);
118 |   int ofd_nonce = TransferFd(conn.sock_fd(), ofd);
119 |   msg.set_ofd(ofd_nonce);
120 |   msg.set_blocksize100k(blockSize100k);
121 |   msg.set_verbosity(verbosity);
122 |   msg.set_workfactor(workFactor);
123 |   api_("%s(%d, %d, %d, %d, %d) =>", method, ifd, ofd, blockSize100k, verbosity, workFactor);
124 |   grpc::Status status = conn.stub()->CompressStream(&context, msg, &rsp);
125 |   assert(status.ok());
126 |   int retval = rsp.result();
127 |   api_("%s(%d, %d, %d, %d, %d) return %d <=", method, ifd, ofd, blockSize100k, verbosity, workFactor, retval);
128 |   return retval;
129 | }
130 | 
131 | extern "C"
132 | int BZ2_bzDecompressStream(int ifd, int ofd, int verbosity, int small) {
133 |   static const char *method = "BZ2_bzDecompressStream";
134 |   DriverConnection conn;
135 |   bz2::DecompressStreamRequest msg;
136 |   bz2::DecompressStreamReply rsp;
137 |   grpc::ClientContext context;
138 |   int ifd_nonce = TransferFd(conn.sock_fd(), ifd);
139 |   msg.set_ifd(ifd_nonce);
140 |   int ofd_nonce = TransferFd(conn.sock_fd(), ofd);
141 |   msg.set_ofd(ofd_nonce);
142 |   msg.set_verbosity(verbosity);
143 |   msg.set_small(small);
144 |   api_("%s(%d, %d, %d, %d) =>", method, ifd, ofd, verbosity, small);
145 |   grpc::Status status = conn.stub()->DecompressStream(&context, msg, &rsp);
146 |   assert(status.ok());
147 |   int retval = rsp.result();
148 |   api_("%s(%d, %d, %d, %d) return %d <=", method, ifd, ofd, verbosity, small, retval);
149 |   return retval;
150 | }
151 | 
152 | extern "C"
153 | int BZ2_bzTestStream(int ifd, int verbosity, int small) {
154 |   static const char *method = "BZ2_bzTestStream";
155 |   DriverConnection conn;
156 |   bz2::TestStreamRequest msg;
157 |   bz2::TestStreamReply rsp;
158 |   grpc::ClientContext context;
159 |   int ifd_nonce = TransferFd(conn.sock_fd(), ifd);
160 |   msg.set_ifd(ifd_nonce);
161 |   msg.set_verbosity(verbosity);
162 |   msg.set_small(small);
163 |   api_("%s(%d, %d, %d) =>", method, ifd, verbosity, small);
164 |   grpc::Status status = conn.stub()->TestStream(&context, msg, &rsp);
165 |   assert(status.ok());
166 |   int retval = rsp.result();
167 |   api_("%s(%d, %d, %d) return %d <=", method, ifd, verbosity, small, retval);
168 |   return retval;
169 | }
170 | 
171 | extern "C"
172 | const char *BZ2_bzlibVersion(void) {
173 |   static const char *method = "BZ2_bzlibVersion";
174 |   static const char *saved_version = NULL;
175 |   if (saved_version) {
176 |     api_("%s() return '%s' <= (saved)", method, saved_version);
177 |     return saved_version;
178 |   }
179 |   DriverConnection conn;
180 |   bz2::LibVersionRequest msg;
181 |   bz2::LibVersionReply rsp;
182 |   grpc::ClientContext context;
183 |   api_("%s() =>", method);
184 |   grpc::Status status = conn.stub()->LibVersion(&context, msg, &rsp);
185 |   assert(status.ok());
186 |   std::string version(rsp.version());
187 |   api_("%s() return '%s' <=", method, version.c_str());
188 |   saved_version = strdup(version.c_str());
189 |   return saved_version;
190 | }
191 | 


--------------------------------------------------------------------------------
/bz2-stub-libnv.c:
--------------------------------------------------------------------------------
  1 | /* Copyright 2016 Google Inc. All Rights Reserved.
  2 |  *
  3 |  * Use of this source code is governed by the bzip2
  4 |  * license that can be found in the LICENSE file. */
  5 | 
  6 | #include 
  7 | #include 
  8 | #include 
  9 | #include 
 10 | #include 
 11 | #include 
 12 | #include 
 13 | #include 
 14 | #include 
 15 | #include 
 16 | 
 17 | #include 
 18 | 
 19 | #include "rpc-util.h"
 20 | 
 21 | int _rpc_verbose = 4;  /* smaller number => more verbose */
 22 | int _rpc_indent = 0;
 23 | 
 24 | static const char *g_exe_file = "./bz2-driver-libnv";
 25 | static int g_exe_fd = -1;  /* File descriptor to driver executable */
 26 | /* Before main(), get an FD for the driver program, so that it is still
 27 |    accessible even if the application enters a sandbox. */
 28 | void __attribute__((constructor)) _stub_construct(void) {
 29 |   g_exe_fd = OpenDriver(g_exe_file);
 30 | }
 31 | 
 32 | struct DriverConnection {
 33 |   /* Child process ID for the driver process */
 34 |   pid_t pid;
 35 |   /* Socket pair for communcation with driver process */
 36 |   int socket_fds[2];
 37 | } g_conn;
 38 | 
 39 | 
 40 | static struct DriverConnection *CreateConnection(void) {
 41 |   struct DriverConnection *conn = &g_conn;
 42 |   /* Create socket for communication with child */
 43 |   conn->socket_fds[0] = -1;
 44 |   conn->socket_fds[1] = -1;
 45 |   int rc = socketpair(AF_UNIX, SOCK_STREAM, 0, conn->socket_fds);
 46 |   if (rc < 0) {
 47 |     error_("failed to open sockets, errno=%d (%s)", errno, strerror(errno));
 48 |     return NULL;
 49 |   }
 50 | 
 51 |   api_("CreateConnection(g_exe_fd=%d, '%s')", g_exe_fd, g_exe_file);
 52 | 
 53 |   conn->pid = fork();
 54 |   if (conn->pid < 0) {
 55 |     error_("failed to fork, errno=%d (%s)", errno, strerror(errno));
 56 |     return NULL;
 57 |   }
 58 | 
 59 |   if (conn->pid == 0) {
 60 |     /* Child process: run the driver */
 61 |     RunDriver(g_exe_fd, g_exe_file, conn->socket_fds[1]);
 62 |   }
 63 | 
 64 |   return conn;
 65 | }
 66 | 
 67 | static void DestroyConnection(struct DriverConnection *conn) {
 68 |   int ii;
 69 |   api_("DestroyConnection(conn=%p {pid=%d })", conn, conn->pid);
 70 | 
 71 |   for (ii = 0; ii < 2; ii ++) {
 72 |     if (conn->socket_fds[ii] >= 0) {
 73 |       verbose_("close socket_fds[%d]= %d", ii, conn->socket_fds[ii]);
 74 |       close(conn->socket_fds[ii]);
 75 |       conn->socket_fds[ii] = -1;
 76 |     }
 77 |   }
 78 |   if (conn->pid > 0) {
 79 |     TerminateChild(conn->pid);
 80 |     conn->pid = 0;
 81 |   }
 82 | }
 83 | 
 84 | 
 85 | /*****************************************************************************/
 86 | /* Everything above here is generic, and would be useful for any remoted API */
 87 | /*****************************************************************************/
 88 | 
 89 | 
 90 | 
 91 | /* RPC-Forwarding versions of libbz2 entrypoints */
 92 | 
 93 | int BZ2_bzCompressStream(int ifd, int ofd, int blockSize100k, int verbosity, int workFactor) {
 94 |   static const char *cmd = "BZ2_bzCompressStream";
 95 |   struct DriverConnection *conn = CreateConnection();
 96 |   nvlist_t *nvl;
 97 | 
 98 |   nvl = nvlist_create(0);
 99 |   nvlist_add_string(nvl, "cmd", cmd);
100 |   nvlist_add_descriptor(nvl, "ifd", ifd);
101 |   nvlist_add_descriptor(nvl, "ofd", ofd);
102 |   nvlist_add_number(nvl, "blockSize100k", (uint64_t)blockSize100k);
103 |   nvlist_add_number(nvl, "verbosity", (uint64_t)verbosity);
104 |   nvlist_add_number(nvl, "workFactor", (uint64_t)workFactor);
105 | 
106 |   api_("%s(%d, %d, %d, %d, %d) =>", cmd, ifd, ofd, blockSize100k, verbosity, workFactor);
107 |   nvl = nvlist_xfer(conn->socket_fds[0], nvl, 0);
108 | 
109 |   assert (nvl != NULL);
110 |   int retval = nvlist_get_number(nvl, "retval");
111 |   api_("%s(%d, %d, %d, %d, %d) return %d <=", cmd, ifd, ofd, blockSize100k, verbosity, workFactor, retval);
112 |   nvlist_destroy(nvl);
113 |   DestroyConnection(conn);
114 |   return retval;
115 | }
116 | 
117 | int BZ2_bzDecompressStream(int ifd, int ofd, int verbosity, int small) {
118 |   static const char *cmd = "BZ2_bzDecompressStream";
119 |   struct DriverConnection *conn = CreateConnection();
120 |   nvlist_t *nvl;
121 | 
122 |   nvl = nvlist_create(0);
123 |   nvlist_add_string(nvl, "cmd", cmd);
124 |   nvlist_add_descriptor(nvl, "ifd", ifd);
125 |   nvlist_add_descriptor(nvl, "ofd", ofd);
126 |   nvlist_add_number(nvl, "verbosity", (uint64_t)verbosity);
127 |   nvlist_add_number(nvl, "small", (uint64_t)small);
128 | 
129 |   api_("%s(%d, %d, %d, %d) =>", cmd, ifd, ofd, verbosity, small);
130 |   nvl = nvlist_xfer(conn->socket_fds[0], nvl, 0);
131 | 
132 |   assert (nvl != NULL);
133 |   int retval = nvlist_get_number(nvl, "retval");
134 |   api_("%s(%d, %d, %d, %d) return %d <=", cmd, ifd, ofd, verbosity, small, retval);
135 |   nvlist_destroy(nvl);
136 |   DestroyConnection(conn);
137 |   return retval;
138 | }
139 | 
140 | int BZ2_bzTestStream(int ifd, int verbosity, int small) {
141 |   static const char *cmd = "BZ2_bzTestStream";
142 |   struct DriverConnection *conn = CreateConnection();
143 |   nvlist_t *nvl;
144 | 
145 |   nvl = nvlist_create(0);
146 |   nvlist_add_string(nvl, "cmd", cmd);
147 |   nvlist_add_descriptor(nvl, "ifd", ifd);
148 |   nvlist_add_number(nvl, "verbosity", (uint64_t)verbosity);
149 |   nvlist_add_number(nvl, "small", (uint64_t)small);
150 | 
151 |   api_("%s(%d, %d, %d) =>", cmd, ifd, verbosity, small);
152 |   nvl = nvlist_xfer(conn->socket_fds[0], nvl, 0);
153 | 
154 |   assert (nvl != NULL);
155 |   int retval = nvlist_get_number(nvl, "retval");
156 |   api_("%s(%d, %d, %d) return %d <=", cmd, ifd, verbosity, small, retval);
157 |   nvlist_destroy(nvl);
158 |   DestroyConnection(conn);
159 |   return retval;
160 | }
161 | 
162 | const char *BZ2_bzlibVersion(void) {
163 |   static const char *cmd = "BZ2_bzlibVersion";
164 |   static const char *saved_version = NULL;
165 |   if (saved_version) {
166 |     api_("%s() return '%s' <= (saved)", cmd, saved_version);
167 |     return saved_version;
168 |   }
169 | 
170 |   struct DriverConnection *conn = CreateConnection();
171 |   nvlist_t *nvl;
172 | 
173 |   nvl = nvlist_create(0);
174 |   nvlist_add_string(nvl, "cmd", cmd);
175 | 
176 |   api_("%s() =>", cmd);
177 |   nvl = nvlist_xfer(conn->socket_fds[0], nvl, 0);
178 | 
179 |   assert (nvl != NULL);
180 |   const char *retval = nvlist_get_string(nvl, "retval");
181 |   api_("%s() return '%s' <=", cmd, retval);
182 |   saved_version = strdup(retval);
183 |   nvlist_destroy(nvl);
184 |   DestroyConnection(conn);
185 |   return saved_version;
186 | }
187 | 


--------------------------------------------------------------------------------
/bzdiff:
--------------------------------------------------------------------------------
 1 | #!/bin/sh
 2 | # sh is buggy on RS/6000 AIX 3.2. Replace above line with #!/bin/ksh
 3 | 
 4 | # Bzcmp/diff wrapped for bzip2, 
 5 | # adapted from zdiff by Philippe Troin  for Debian GNU/Linux.
 6 | 
 7 | # Bzcmp and bzdiff are used to invoke the cmp or the  diff  pro-
 8 | # gram  on compressed files.  All options specified are passed
 9 | # directly to cmp or diff.  If only 1 file is specified,  then
10 | # the  files  compared  are file1 and an uncompressed file1.gz.
11 | # If two files are specified, then they are  uncompressed  (if
12 | # necessary) and fed to cmp or diff.  The exit status from cmp
13 | # or diff is preserved.
14 | 
15 | PATH="/usr/bin:/bin:$PATH"; export PATH
16 | prog=`echo $0 | sed 's|.*/||'`
17 | case "$prog" in
18 |   *cmp) comp=${CMP-cmp}   ;;
19 |   *)    comp=${DIFF-diff} ;;
20 | esac
21 | 
22 | OPTIONS=
23 | FILES=
24 | for ARG
25 | do
26 |     case "$ARG" in
27 |     -*)	OPTIONS="$OPTIONS $ARG";;
28 |      *)	if test -f "$ARG"; then
29 |             FILES="$FILES $ARG"
30 |         else
31 |             echo "${prog}: $ARG not found or not a regular file"
32 | 	    exit 1
33 |         fi ;;
34 |     esac
35 | done
36 | if test -z "$FILES"; then
37 | 	echo "Usage: $prog [${comp}_options] file [file]"
38 | 	exit 1
39 | fi
40 | tmp=`mktemp ${TMPDIR:-/tmp}/bzdiff.XXXXXXXXXX` || {
41 |       echo 'cannot create a temporary file' >&2
42 |       exit 1
43 | }
44 | set $FILES
45 | if test $# -eq 1; then
46 | 	FILE=`echo "$1" | sed 's/.bz2$//'`
47 | 	bzip2 -cd "$FILE.bz2" | $comp $OPTIONS - "$FILE"
48 | 	STAT="$?"
49 | 
50 | elif test $# -eq 2; then
51 | 	case "$1" in
52 |         *.bz2)
53 |                 case "$2" in
54 | 	        *.bz2)
55 | 			F=`echo "$2" | sed 's|.*/||;s|.bz2$||'`
56 |                         bzip2 -cdfq "$2" > $tmp
57 |                         bzip2 -cdfq "$1" | $comp $OPTIONS - $tmp
58 |                         STAT="$?"
59 | 			/bin/rm -f $tmp;;
60 | 
61 |                 *)      bzip2 -cdfq "$1" | $comp $OPTIONS - "$2"
62 |                         STAT="$?";;
63 |                 esac;;
64 |         *)      case "$2" in
65 | 	        *.bz2)
66 |                         bzip2 -cdfq "$2" | $comp $OPTIONS "$1" -
67 |                         STAT="$?";;
68 |                 *)      $comp $OPTIONS "$1" "$2"
69 |                         STAT="$?";;
70 |                 esac;;
71 | 	esac
72 |         exit "$STAT"
73 | else
74 | 	echo "Usage: $prog [${comp}_options] file [file]"
75 | 	exit 1
76 | fi
77 | 


--------------------------------------------------------------------------------
/bzdiff.1:
--------------------------------------------------------------------------------
 1 | \"Shamelessly copied from zmore.1 by Philippe Troin 
 2 | \"for Debian GNU/Linux
 3 | .TH BZDIFF 1
 4 | .SH NAME
 5 | bzcmp, bzdiff \- compare bzip2 compressed files
 6 | .SH SYNOPSIS
 7 | .B bzcmp
 8 | [ cmp_options ] file1
 9 | [ file2 ]
10 | .br
11 | .B bzdiff
12 | [ diff_options ] file1
13 | [ file2 ]
14 | .SH DESCRIPTION
15 | .I  Bzcmp
16 | and 
17 | .I bzdiff
18 | are used to invoke the
19 | .I cmp
20 | or the
21 | .I diff
22 | program on bzip2 compressed files.  All options specified are passed
23 | directly to
24 | .I cmp
25 | or
26 | .IR diff "."
27 | If only 1 file is specified, then the files compared are
28 | .I file1
29 | and an uncompressed
30 | .IR file1 ".bz2."
31 | If two files are specified, then they are uncompressed if necessary and fed to
32 | .I cmp
33 | or
34 | .IR diff "."
35 | The exit status from 
36 | .I cmp
37 | or
38 | .I diff
39 | is preserved.
40 | .SH "SEE ALSO"
41 | cmp(1), diff(1), bzmore(1), bzless(1), bzgrep(1), bzip2(1)
42 | .SH BUGS
43 | Messages from the
44 | .I cmp
45 | or
46 | .I diff
47 | programs refer to temporary filenames instead of those specified.
48 | 


--------------------------------------------------------------------------------
/bzgrep:
--------------------------------------------------------------------------------
 1 | #!/bin/sh
 2 | 
 3 | # Bzgrep wrapped for bzip2, 
 4 | # adapted from zgrep by Philippe Troin  for Debian GNU/Linux.
 5 | ## zgrep notice:
 6 | ## zgrep -- a wrapper around a grep program that decompresses files as needed
 7 | ## Adapted from a version sent by Charles Levert 
 8 | 
 9 | PATH="/usr/bin:$PATH"; export PATH
10 | 
11 | prog=`echo $0 | sed 's|.*/||'`
12 | case "$prog" in
13 | 	*egrep)	grep=${EGREP-egrep}	;;
14 | 	*fgrep)	grep=${FGREP-fgrep}	;;
15 | 	*)	grep=${GREP-grep}	;;
16 | esac
17 | pat=""
18 | while test $# -ne 0; do
19 |   case "$1" in
20 |   -e | -f) opt="$opt $1"; shift; pat="$1"
21 |            if test "$grep" = grep; then  # grep is buggy with -e on SVR4
22 |              grep=egrep
23 |            fi;;
24 |   -A | -B) opt="$opt $1 $2"; shift;;
25 |   -*)	   opt="$opt $1";;
26 |    *)      if test -z "$pat"; then
27 | 	     pat="$1"
28 | 	   else
29 | 	     break;
30 |            fi;;
31 |   esac
32 |   shift
33 | done
34 | 
35 | if test -z "$pat"; then
36 |   echo "grep through bzip2 files"
37 |   echo "usage: $prog [grep_options] pattern [files]"
38 |   exit 1
39 | fi
40 | 
41 | list=0
42 | silent=0
43 | op=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
44 | case "$op" in
45 |   *l*) list=1
46 | esac
47 | case "$op" in
48 |   *h*) silent=1
49 | esac
50 | 
51 | if test $# -eq 0; then
52 |   bzip2 -cdfq | $grep $opt "$pat"
53 |   exit $?
54 | fi
55 | 
56 | res=0
57 | for i do
58 |   if test -f "$i"; then :; else if test -f "$i.bz2"; then i="$i.bz2"; fi; fi
59 |   if test $list -eq 1; then
60 |     bzip2 -cdfq "$i" | $grep $opt "$pat" 2>&1 > /dev/null && echo $i
61 |     r=$?
62 |   elif test $# -eq 1 -o $silent -eq 1; then
63 |     bzip2 -cdfq "$i" | $grep $opt "$pat"
64 |     r=$?
65 |   else
66 |     j=${i//\\/\\\\}
67 |     j=${j//|/\\|}
68 |     j=${j//&/\\&}
69 |     j=`printf "%s" "$j" | tr '\n' ' '`
70 |     bzip2 -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${j}:|"
71 |     r=$?
72 |   fi
73 |   test "$r" -ne 0 && res="$r"
74 | done
75 | exit $res
76 | 


--------------------------------------------------------------------------------
/bzgrep.1:
--------------------------------------------------------------------------------
 1 | \"Shamelessly copied from zmore.1 by Philippe Troin 
 2 | \"for Debian GNU/Linux
 3 | .TH BZGREP 1
 4 | .SH NAME
 5 | bzgrep, bzfgrep, bzegrep \- search possibly bzip2 compressed files for a regular expression
 6 | .SH SYNOPSIS
 7 | .B bzgrep
 8 | [ grep_options ]
 9 | .BI  [\ -e\ ] " pattern"
10 | .IR filename ".\|.\|."
11 | .br
12 | .B bzegrep
13 | [ egrep_options ]
14 | .BI  [\ -e\ ] " pattern"
15 | .IR filename ".\|.\|."
16 | .br
17 | .B bzfgrep
18 | [ fgrep_options ]
19 | .BI  [\ -e\ ] " pattern"
20 | .IR filename ".\|.\|."
21 | .SH DESCRIPTION
22 | .IR  Bzgrep
23 | is used to invoke the
24 | .I grep
25 | on bzip2-compressed files. All options specified are passed directly to
26 | .I grep.
27 | If no file is specified, then the standard input is decompressed
28 | if necessary and fed to grep.
29 | Otherwise the given files are uncompressed if necessary and fed to
30 | .I grep.
31 | .PP
32 | If
33 | .I bzgrep
34 | is invoked as
35 | .I bzegrep
36 | or
37 | .I bzfgrep
38 | then
39 | .I egrep
40 | or
41 | .I fgrep
42 | is used instead of
43 | .I grep.
44 | If the GREP environment variable is set,
45 | .I bzgrep
46 | uses it as the
47 | .I grep
48 | program to be invoked. For example:
49 | 
50 |     for sh:  GREP=fgrep  bzgrep string files
51 |     for csh: (setenv GREP fgrep; bzgrep string files)
52 | .SH AUTHOR
53 | Charles Levert (charles@comm.polymtl.ca). Adapted to bzip2 by Philippe
54 | Troin  for Debian GNU/Linux.
55 | .SH "SEE ALSO"
56 | grep(1), egrep(1), fgrep(1), bzdiff(1), bzmore(1), bzless(1), bzip2(1)
57 | 


--------------------------------------------------------------------------------
/bzip.css:
--------------------------------------------------------------------------------
 1 | /* Colours:
 2 | #74240f  dark brown      h1, h2, h3, h4
 3 | #336699  medium blue     links
 4 | #339999  turquoise       link hover colour
 5 | #202020  almost black    general text
 6 | #761596  purple          md5sum text
 7 | #626262  dark gray       pre border
 8 | #eeeeee  very light gray pre background
 9 | #f2f2f9  very light blue nav table background
10 | #3366cc  medium blue     nav table border
11 | */
12 | 
13 | a, a:link, a:visited, a:active { color: #336699; }
14 | a:hover { color: #339999; }
15 | 
16 | body { font: 80%/126% sans-serif; }
17 | h1, h2, h3, h4 { color: #74240f; }
18 | 
19 | dt { color: #336699; font-weight: bold }
20 | dd { 
21 |  margin-left: 1.5em; 
22 |  padding-bottom: 0.8em;
23 | }
24 | 
25 | /* -- ruler -- */
26 | div.hr_blue { 
27 |   height:  3px; 
28 |   background:#ffffff url("/images/hr_blue.png") repeat-x; }
29 | div.hr_blue hr { display:none; }
30 | 
31 | /* release styles */
32 | #release p { margin-top: 0.4em; }
33 | #release .md5sum { color: #761596; }
34 | 
35 | 
36 | /* ------ styles for docs|manuals|howto ------ */
37 | /* -- lists -- */
38 | ul  { 
39 |  margin:     0px 4px 16px 16px;
40 |  padding:    0px;
41 |  list-style: url("/images/li-blue.png"); 
42 | }
43 | ul li { 
44 |  margin-bottom: 10px;
45 | }
46 | ul ul	{ 
47 |  list-style-type:  none; 
48 |  list-style-image: none; 
49 |  margin-left:      0px; 
50 | }
51 | 
52 | /* header / footer nav tables */
53 | table.nav {
54 |  border:     solid 1px #3366cc;
55 |  background: #f2f2f9;
56 |  background-color: #f2f2f9;
57 |  margin-bottom: 0.5em;
58 | }
59 | /* don't have underlined links in chunked nav menus */
60 | table.nav a { text-decoration: none; }
61 | table.nav a:hover { text-decoration: underline; }
62 | table.nav td { font-size: 85%; }
63 | 
64 | code, tt, pre { font-size: 120%; }
65 | code, tt { color: #761596; }
66 | 
67 | div.literallayout, pre.programlisting, pre.screen {
68 |  color:      #000000;
69 |  padding:    0.5em;
70 |  background: #eeeeee;
71 |  border:     1px solid #626262;
72 |  background-color: #eeeeee;
73 |  margin: 4px 0px 4px 0px; 
74 | }
75 | 


--------------------------------------------------------------------------------
/bzlib.capnp:
--------------------------------------------------------------------------------
 1 | # Copyright 2016 Google Inc. All Rights Reserved.
 2 | #
 3 | # Use of this source code is governed by the bzip2
 4 | # license that can be found in the LICENSE file.
 5 | 
 6 | @0x8484d2d77983b934;
 7 | 
 8 | using Cxx = import "/capnp/c++.capnp";
 9 | $Cxx.namespace("bz2");
10 | 
11 | interface Bz2 {
12 |   compressStream @0 (ifd :Int32,
13 |                      ofd :Int32,
14 |                      blockSize100k :Int32,
15 |                      verbosity :Int32,
16 |                      workFactor :Int32) -> (result :Int32);
17 |   decompressStream @1 (ifd :Int32,
18 |                        ofd :Int32,
19 |                        verbosity :Int32,
20 |                        small :Int32) -> (result :Int32);
21 |   testStream @2 (ifd :Int32,
22 |                  verbosity :Int32,
23 |                  small :Int32) -> (result :Int32);
24 |   libVersion @3 () -> (version :Text);
25 | }
26 | 


--------------------------------------------------------------------------------
/bzlib.h:
--------------------------------------------------------------------------------
  1 | 
  2 | /*-------------------------------------------------------------*/
  3 | /*--- Public header file for the library.                   ---*/
  4 | /*---                                               bzlib.h ---*/
  5 | /*-------------------------------------------------------------*/
  6 | 
  7 | /* ------------------------------------------------------------------
  8 |    This file is part of bzip2/libbzip2, a program and library for
  9 |    lossless, block-sorting data compression.
 10 | 
 11 |    bzip2/libbzip2 version 1.0.6 of 6 September 2010
 12 |    Copyright (C) 1996-2010 Julian Seward 
 13 | 
 14 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
 15 |    README file.
 16 | 
 17 |    This program is released under the terms of the license contained
 18 |    in the file LICENSE.
 19 |    ------------------------------------------------------------------ */
 20 | 
 21 | 
 22 | #ifndef _BZLIB_H
 23 | #define _BZLIB_H
 24 | 
 25 | #include "idolize.h"
 26 | 
 27 | #ifdef __cplusplus
 28 | extern "C" {
 29 | #endif
 30 | 
 31 | #define BZ_RUN               0
 32 | #define BZ_FLUSH             1
 33 | #define BZ_FINISH            2
 34 | 
 35 | #define BZ_OK                0
 36 | #define BZ_RUN_OK            1
 37 | #define BZ_FLUSH_OK          2
 38 | #define BZ_FINISH_OK         3
 39 | #define BZ_STREAM_END        4
 40 | #define BZ_SEQUENCE_ERROR    (-1)
 41 | #define BZ_PARAM_ERROR       (-2)
 42 | #define BZ_MEM_ERROR         (-3)
 43 | #define BZ_DATA_ERROR        (-4)
 44 | #define BZ_DATA_ERROR_MAGIC  (-5)
 45 | #define BZ_IO_ERROR          (-6)
 46 | #define BZ_UNEXPECTED_EOF    (-7)
 47 | #define BZ_OUTBUFF_FULL      (-8)
 48 | #define BZ_CONFIG_ERROR      (-9)
 49 | 
 50 | typedef 
 51 |    struct {
 52 |       const char *next_in  __size(avail_in);
 53 |       unsigned int avail_in;
 54 |       unsigned int total_in_lo32;
 55 |       unsigned int total_in_hi32;
 56 | 
 57 |       char *next_out  __size(avail_out) __out;
 58 |       unsigned int avail_out;
 59 |       unsigned int total_out_lo32;
 60 |       unsigned int total_out_hi32;
 61 | 
 62 |       void *state  __skip;
 63 | 
 64 |       void *(*bzalloc)(void *,int,int)  __skip;
 65 |       void (*bzfree)(void *,void *)  __skip;
 66 |       void *opaque  __skip;
 67 |    } 
 68 |    bz_stream;
 69 | 
 70 | 
 71 | #ifndef BZ_IMPORT
 72 | #define BZ_EXPORT
 73 | #endif
 74 | 
 75 | #ifndef BZ_NO_STDIO
 76 | /* Need a definitition for FILE */
 77 | #include 
 78 | #endif
 79 | 
 80 | #ifdef _WIN32
 81 | #   include 
 82 | #   ifdef small
 83 |       /* windows.h define small to char */
 84 | #      undef small
 85 | #   endif
 86 | #   ifdef BZ_EXPORT
 87 | #   define BZ_API(func) WINAPI func
 88 | #   define BZ_EXTERN extern
 89 | #   else
 90 |    /* import windows dll dynamically */
 91 | #   define BZ_API(func) (WINAPI * func)
 92 | #   define BZ_EXTERN
 93 | #   endif
 94 | #else
 95 | #   define BZ_API(func) func
 96 | #   define BZ_EXTERN extern
 97 | #endif
 98 | 
 99 | 
100 | /*-- Core (low-level) library functions --*/
101 | 
102 | BZ_EXTERN int BZ_API(BZ2_bzCompressInit) ( 
103 |       bz_stream* strm, 
104 |       int        blockSize100k, 
105 |       int        verbosity, 
106 |       int        workFactor 
107 |    )  __init;
108 | 
109 | BZ_EXTERN int BZ_API(BZ2_bzCompress) ( 
110 |       bz_stream* strm, 
111 |       int action 
112 |    );
113 | 
114 | BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) ( 
115 |       bz_stream* strm 
116 |    )  __term;
117 | 
118 | BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) ( 
119 |       bz_stream *strm, 
120 |       int       verbosity, 
121 |       int       small
122 |    )  __init;
123 | 
124 | BZ_EXTERN int BZ_API(BZ2_bzDecompress) ( 
125 |       bz_stream* strm 
126 |    );
127 | 
128 | BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) ( 
129 |       bz_stream *strm 
130 |    )  __term;
131 | 
132 | 
133 | 
134 | /*-- High(er) level library functions --*/
135 | 
136 | #ifndef BZ_NO_STDIO
137 | #define BZ_MAX_UNUSED 5000
138 | 
139 | struct bzF;
140 | typedef struct bzF BZFILE;
141 | 
142 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) ( 
143 |       int*  bzerror,   
144 |       FILE* f, 
145 |       int   verbosity, 
146 |       int   small,
147 |       const void* unused  __size(nUnused),
148 |       int   nUnused
149 |    )  __skip;
150 | 
151 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpenFd) (
152 |       int*  bzerror,
153 |       int   fd  __isfd,
154 |       int   verbosity,
155 |       int   small,
156 |       const void* unused  __size(nUnused),
157 |       int   nUnused
158 |    )  __init;
159 | 
160 | BZ_EXTERN void BZ_API(BZ2_bzReadClose) ( 
161 |       int*    bzerror, 
162 |       BZFILE* b 
163 |    )  __term;
164 | 
165 | BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) ( 
166 |       int*    bzerror, 
167 |       BZFILE* b, 
168 |       const void**  unused,  
169 |       int*    nUnused 
170 |    )  __skip;
171 | 
172 | BZ_EXTERN int BZ_API(BZ2_bzRead) ( 
173 |       int*    bzerror, 
174 |       BZFILE* b, 
175 |       void*   buf  __size(len) __out, 
176 |       int     len 
177 |    );
178 | 
179 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) ( 
180 |       int*  bzerror,      
181 |       FILE* f, 
182 |       int   blockSize100k, 
183 |       int   verbosity, 
184 |       int   workFactor 
185 |    )  __skip;
186 | 
187 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpenFd) (
188 |       int*  bzerror,
189 |       int   fd  __isfd,
190 |       int   blockSize100k,
191 |       int   verbosity,
192 |       int   workFactor
193 |    )  __init;
194 | 
195 | BZ_EXTERN void BZ_API(BZ2_bzWrite) ( 
196 |       int*    bzerror, 
197 |       BZFILE* b, 
198 |       const void* buf  __size(len), 
199 |       int     len 
200 |    );
201 | 
202 | BZ_EXTERN void BZ_API(BZ2_bzWriteClose) ( 
203 |       int*          bzerror, 
204 |       BZFILE*       b, 
205 |       int           abandon, 
206 |       unsigned int* nbytes_in, 
207 |       unsigned int* nbytes_out 
208 |    )  __term;
209 | 
210 | BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) ( 
211 |       int*          bzerror, 
212 |       BZFILE*       b, 
213 |       int           abandon, 
214 |       unsigned int* nbytes_in_lo32, 
215 |       unsigned int* nbytes_in_hi32, 
216 |       unsigned int* nbytes_out_lo32, 
217 |       unsigned int* nbytes_out_hi32
218 |    )  __term;
219 | 
220 | BZ_EXTERN int BZ_API(BZ2_bzCompressStream) (
221 |       int        ifd  __isfd,
222 |       int        ofd  __isfd,
223 |       int        blockSize100k, 
224 |       int        verbosity, 
225 |       int        workFactor 
226 |     )  __init __term;
227 | 
228 | BZ_EXTERN int BZ_API(BZ2_bzDecompressStream) (
229 |       int        ifd  __isfd,
230 |       int        ofd  __isfd,
231 |       int        verbosity, 
232 |       int        small
233 |     )  __init __term;
234 | 
235 | BZ_EXTERN int BZ_API(BZ2_bzTestStream) (
236 |       int        ifd  __isfd,
237 |       int        verbosity, 
238 |       int        small
239 |     )  __init __term;
240 | 
241 | #endif
242 | 
243 | 
244 | /*-- Utility functions --*/
245 | 
246 | BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) ( 
247 |       char*         dest  __size(destLen) __out, 
248 |       unsigned int* destLen,
249 |       const char*   source  __size(sourceLen), 
250 |       unsigned int  sourceLen,
251 |       int           blockSize100k, 
252 |       int           verbosity, 
253 |       int           workFactor 
254 |    );
255 | 
256 | BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) ( 
257 |       char*         dest  __size(destLen) __out, 
258 |       unsigned int* destLen,
259 |       const char*   source  __size(sourceLen), 
260 |       unsigned int  sourceLen,
261 |       int           small, 
262 |       int           verbosity 
263 |    );
264 | 
265 | 
266 | /*--
267 |    Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
268 |    to support better zlib compatibility.
269 |    This code is not _officially_ part of libbzip2 (yet);
270 |    I haven't tested it, documented it, or considered the
271 |    threading-safeness of it.
272 |    If this code breaks, please contact both Yoshioka and me.
273 | --*/
274 | 
275 | BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) (
276 |       void
277 |    )  __cstring __static;
278 | 
279 | #ifndef BZ_NO_STDIO
280 | BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) (
281 |       const char *path,
282 |       const char *mode
283 |    )  __skip;
284 | 
285 | BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) (
286 |       int        fd  __isfd,
287 |       const char *mode  __cstring
288 |    )  __init;
289 |          
290 | BZ_EXTERN int BZ_API(BZ2_bzread) (
291 |       BZFILE* b, 
292 |       void* buf  __size(len) __out, 
293 |       int len 
294 |    );
295 | 
296 | BZ_EXTERN int BZ_API(BZ2_bzwrite) (
297 |       BZFILE* b, 
298 |       const void*   buf  __size(len), 
299 |       int     len 
300 |    );
301 | 
302 | BZ_EXTERN int BZ_API(BZ2_bzflush) (
303 |       BZFILE* b
304 |    );
305 | 
306 | BZ_EXTERN void BZ_API(BZ2_bzclose) (
307 |       BZFILE* b
308 |    )  __term;
309 | 
310 | BZ_EXTERN const char * BZ_API(BZ2_bzerror) (
311 |       BZFILE *b, 
312 |       int    *errnum
313 |    )  __cstring;
314 | #endif
315 | 
316 | #ifdef __cplusplus
317 | }
318 | #endif
319 | 
320 | #endif
321 | 
322 | /*-------------------------------------------------------------*/
323 | /*--- end                                           bzlib.h ---*/
324 | /*-------------------------------------------------------------*/
325 | 


--------------------------------------------------------------------------------
/bzlib.proto:
--------------------------------------------------------------------------------
 1 | // Copyright 2016 Google Inc. All Rights Reserved.
 2 | //
 3 | // Use of this source code is governed by the bzip2
 4 | // license that can be found in the LICENSE file.
 5 | 
 6 | syntax = "proto3";
 7 | 
 8 | package bz2;
 9 | 
10 | // Service definition for bzlib.
11 | service Bz2 {
12 |   rpc CompressStream (CompressStreamRequest) returns (CompressStreamReply) {}
13 |   rpc DecompressStream (DecompressStreamRequest) returns (DecompressStreamReply) {}
14 |   rpc TestStream (TestStreamRequest) returns (TestStreamReply) {}
15 |   rpc LibVersion (LibVersionRequest) returns (LibVersionReply) {}
16 | }
17 | 
18 | message CompressStreamRequest {
19 |   int32 ifd = 1;
20 |   int32 ofd = 2;
21 |   int32 blockSize100k = 3;
22 |   int32 verbosity = 4;
23 |   int32 workFactor = 5;
24 | }
25 | message CompressStreamReply {
26 |   int32 result = 1;
27 | }
28 | 
29 | message DecompressStreamRequest {
30 |   int32 ifd = 1;
31 |   int32 ofd = 2;
32 |   int32 verbosity = 3;
33 |   int32 small = 4;
34 | }
35 | message DecompressStreamReply {
36 |   int32 result = 1;
37 | }
38 | 
39 | message TestStreamRequest {
40 |   int32 ifd = 1;
41 |   int32 verbosity = 2;
42 |   int32 small = 3;
43 | }
44 | 
45 | message TestStreamReply {
46 |   int32 result = 1;
47 | }
48 | 
49 | message LibVersionRequest {
50 | }
51 | message LibVersionReply {
52 |   string version = 1;
53 | }
54 | 


--------------------------------------------------------------------------------
/bzmore:
--------------------------------------------------------------------------------
 1 | #!/bin/sh
 2 | 
 3 | # Bzmore wrapped for bzip2, 
 4 | # adapted from zmore by Philippe Troin  for Debian GNU/Linux.
 5 | 
 6 | PATH="/usr/bin:$PATH"; export PATH
 7 | 
 8 | prog=`echo $0 | sed 's|.*/||'`
 9 | case "$prog" in
10 | 	*less)	more=less	;;
11 | 	*)	more=more       ;;
12 | esac
13 | 
14 | if test "`echo -n a`" = "-n a"; then
15 |   # looks like a SysV system:
16 |   n1=''; n2='\c'
17 | else
18 |   n1='-n'; n2=''
19 | fi
20 | oldtty=`stty -g 2>/dev/null`
21 | if stty -cbreak 2>/dev/null; then
22 |   cb='cbreak'; ncb='-cbreak'
23 | else
24 |   # 'stty min 1' resets eof to ^a on both SunOS and SysV!
25 |   cb='min 1 -icanon'; ncb='icanon eof ^d'
26 | fi
27 | if test $? -eq 0 -a -n "$oldtty"; then
28 |    trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15
29 | else
30 |    trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15
31 | fi
32 | 
33 | if test $# = 0; then
34 |     if test -t 0; then
35 | 	echo usage: $prog files...
36 |     else
37 | 	bzip2 -cdfq | eval $more
38 |     fi
39 | else
40 |     FIRST=1
41 |     for FILE
42 |     do
43 | 	if test $FIRST -eq 0; then
44 | 		echo $n1 "--More--(Next file: $FILE)$n2"
45 | 		stty $cb -echo 2>/dev/null
46 | 		ANS=`dd bs=1 count=1 2>/dev/null` 
47 | 		stty $ncb echo 2>/dev/null
48 | 		echo " "
49 | 		if test "$ANS" = 'e' -o "$ANS" = 'q'; then
50 | 			exit
51 | 		fi
52 | 	fi
53 | 	if test "$ANS" != 's'; then
54 | 		echo "------> $FILE <------"
55 | 		bzip2 -cdfq "$FILE" | eval $more
56 | 	fi
57 | 	if test -t; then
58 | 		FIRST=0
59 | 	fi
60 |     done
61 | fi
62 | 


--------------------------------------------------------------------------------
/bzmore.1:
--------------------------------------------------------------------------------
  1 | .\"Shamelessly copied from zmore.1 by Philippe Troin 
  2 | .\"for Debian GNU/Linux
  3 | .TH BZMORE 1
  4 | .SH NAME
  5 | bzmore, bzless \- file perusal filter for crt viewing of bzip2 compressed text
  6 | .SH SYNOPSIS
  7 | .B bzmore
  8 | [ name ...  ]
  9 | .br
 10 | .B bzless
 11 | [ name ...  ]
 12 | .SH NOTE
 13 | In the following description,
 14 | .I bzless
 15 | and
 16 | .I less
 17 | can be used interchangeably with
 18 | .I bzmore
 19 | and
 20 | .I more.
 21 | .SH DESCRIPTION
 22 | .I  Bzmore
 23 | is a filter which allows examination of compressed or plain text files
 24 | one screenful at a time on a soft-copy terminal.
 25 | .I bzmore
 26 | works on files compressed with
 27 | .I bzip2
 28 | and also on uncompressed files.
 29 | If a file does not exist,
 30 | .I bzmore
 31 | looks for a file of the same name with the addition of a .bz2 suffix.
 32 | .PP
 33 | .I Bzmore
 34 | normally pauses after each screenful, printing --More--
 35 | at the bottom of the screen.
 36 | If the user then types a carriage return, one more line is displayed.
 37 | If the user hits a space,
 38 | another screenful is displayed.  Other possibilities are enumerated later.
 39 | .PP
 40 | .I Bzmore
 41 | looks in the file
 42 | .I /etc/termcap
 43 | to determine terminal characteristics,
 44 | and to determine the default window size.
 45 | On a terminal capable of displaying 24 lines,
 46 | the default window size is 22 lines.
 47 | Other sequences which may be typed when
 48 | .I bzmore
 49 | pauses, and their effects, are as follows (\fIi\fP is an optional integer
 50 | argument, defaulting to 1) :
 51 | .PP
 52 | .IP \fIi\|\fP
 53 | display
 54 | .I i
 55 | more lines, (or another screenful if no argument is given)
 56 | .PP
 57 | .IP ^D
 58 | display 11 more lines (a ``scroll'').
 59 | If
 60 | .I i
 61 | is given, then the scroll size is set to \fIi\|\fP.
 62 | .PP
 63 | .IP d
 64 | same as ^D (control-D)
 65 | .PP
 66 | .IP \fIi\|\fPz
 67 | same as typing a space except that \fIi\|\fP, if present, becomes the new
 68 | window size.  Note that the window size reverts back to the default at the
 69 | end of the current file.
 70 | .PP
 71 | .IP \fIi\|\fPs
 72 | skip \fIi\|\fP lines and print a screenful of lines
 73 | .PP
 74 | .IP \fIi\|\fPf
 75 | skip \fIi\fP screenfuls and print a screenful of lines
 76 | .PP
 77 | .IP "q or Q"
 78 | quit reading the current file; go on to the next (if any)
 79 | .PP
 80 | .IP "e or q"
 81 | When the prompt --More--(Next file: 
 82 | .IR file )
 83 | is printed, this command causes bzmore to exit.
 84 | .PP
 85 | .IP s
 86 | When the prompt --More--(Next file: 
 87 | .IR file )
 88 | is printed, this command causes bzmore to skip the next file and continue.
 89 | .PP 
 90 | .IP =
 91 | Display the current line number.
 92 | .PP
 93 | .IP \fIi\|\fP/expr
 94 | search for the \fIi\|\fP-th occurrence of the regular expression \fIexpr.\fP
 95 | If the pattern is not found,
 96 | .I bzmore
 97 | goes on to the next file (if any).
 98 | Otherwise, a screenful is displayed, starting two lines before the place
 99 | where the expression was found.
100 | The user's erase and kill characters may be used to edit the regular
101 | expression.
102 | Erasing back past the first column cancels the search command.
103 | .PP
104 | .IP \fIi\|\fPn
105 | search for the \fIi\|\fP-th occurrence of the last regular expression entered.
106 | .PP
107 | .IP !command
108 | invoke a shell with \fIcommand\|\fP. 
109 | The character `!' in "command" are replaced with the
110 | previous shell command.  The sequence "\\!" is replaced by "!".
111 | .PP
112 | .IP ":q or :Q"
113 | quit reading the current file; go on to the next (if any)
114 | (same as q or Q).
115 | .PP
116 | .IP .
117 | (dot) repeat the previous command.
118 | .PP
119 | The commands take effect immediately, i.e., it is not necessary to
120 | type a carriage return.
121 | Up to the time when the command character itself is given,
122 | the user may hit the line kill character to cancel the numerical
123 | argument being formed.
124 | In addition, the user may hit the erase character to redisplay the
125 | --More-- message.
126 | .PP
127 | At any time when output is being sent to the terminal, the user can
128 | hit the quit key (normally control\-\\).
129 | .I Bzmore
130 | will stop sending output, and will display the usual --More--
131 | prompt.
132 | The user may then enter one of the above commands in the normal manner.
133 | Unfortunately, some output is lost when this is done, due to the
134 | fact that any characters waiting in the terminal's output queue
135 | are flushed when the quit signal occurs.
136 | .PP
137 | The terminal is set to
138 | .I noecho
139 | mode by this program so that the output can be continuous.
140 | What you type will thus not show on your terminal, except for the / and !
141 | commands.
142 | .PP
143 | If the standard output is not a teletype, then
144 | .I bzmore
145 | acts just like
146 | .I bzcat,
147 | except that a header is printed before each file.
148 | .SH FILES
149 | .DT
150 | /etc/termcap		Terminal data base
151 | .SH "SEE ALSO"
152 | more(1), less(1), bzip2(1), bzdiff(1), bzgrep(1)
153 | 


--------------------------------------------------------------------------------
/crctable.c:
--------------------------------------------------------------------------------
  1 | 
  2 | /*-------------------------------------------------------------*/
  3 | /*--- Table for doing CRCs                                  ---*/
  4 | /*---                                            crctable.c ---*/
  5 | /*-------------------------------------------------------------*/
  6 | 
  7 | /* ------------------------------------------------------------------
  8 |    This file is part of bzip2/libbzip2, a program and library for
  9 |    lossless, block-sorting data compression.
 10 | 
 11 |    bzip2/libbzip2 version 1.0.6 of 6 September 2010
 12 |    Copyright (C) 1996-2010 Julian Seward 
 13 | 
 14 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
 15 |    README file.
 16 | 
 17 |    This program is released under the terms of the license contained
 18 |    in the file LICENSE.
 19 |    ------------------------------------------------------------------ */
 20 | 
 21 | 
 22 | #include "bzlib_private.h"
 23 | 
 24 | /*--
 25 |   I think this is an implementation of the AUTODIN-II,
 26 |   Ethernet & FDDI 32-bit CRC standard.  Vaguely derived
 27 |   from code by Rob Warnock, in Section 51 of the
 28 |   comp.compression FAQ.
 29 | --*/
 30 | 
 31 | UInt32 BZ2_crc32Table[256] = {
 32 | 
 33 |    /*-- Ugly, innit? --*/
 34 | 
 35 |    0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L,
 36 |    0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L,
 37 |    0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L,
 38 |    0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL,
 39 |    0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L,
 40 |    0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L,
 41 |    0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L,
 42 |    0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL,
 43 |    0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L,
 44 |    0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L,
 45 |    0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L,
 46 |    0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL,
 47 |    0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L,
 48 |    0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L,
 49 |    0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L,
 50 |    0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL,
 51 |    0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL,
 52 |    0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L,
 53 |    0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L,
 54 |    0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL,
 55 |    0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL,
 56 |    0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L,
 57 |    0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L,
 58 |    0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL,
 59 |    0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL,
 60 |    0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L,
 61 |    0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L,
 62 |    0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL,
 63 |    0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL,
 64 |    0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L,
 65 |    0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L,
 66 |    0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL,
 67 |    0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L,
 68 |    0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL,
 69 |    0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL,
 70 |    0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L,
 71 |    0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L,
 72 |    0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL,
 73 |    0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL,
 74 |    0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L,
 75 |    0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L,
 76 |    0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL,
 77 |    0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL,
 78 |    0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L,
 79 |    0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L,
 80 |    0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL,
 81 |    0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL,
 82 |    0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L,
 83 |    0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L,
 84 |    0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL,
 85 |    0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L,
 86 |    0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L,
 87 |    0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L,
 88 |    0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL,
 89 |    0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L,
 90 |    0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L,
 91 |    0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L,
 92 |    0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL,
 93 |    0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L,
 94 |    0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L,
 95 |    0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L,
 96 |    0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL,
 97 |    0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L,
 98 |    0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L
 99 | };
100 | 
101 | 
102 | /*-------------------------------------------------------------*/
103 | /*--- end                                        crctable.c ---*/
104 | /*-------------------------------------------------------------*/
105 | 


--------------------------------------------------------------------------------
/dlltest.c:
--------------------------------------------------------------------------------
  1 | /*
  2 |    minibz2
  3 |       libbz2.dll test program.
  4 |       by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
  5 |       This file is Public Domain.  Welcome any email to me.
  6 | 
  7 |    usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]
  8 | */
  9 | 
 10 | #define BZ_IMPORT
 11 | #include 
 12 | #include 
 13 | #include "bzlib.h"
 14 | #ifdef _WIN32
 15 | #include 
 16 | #endif
 17 | 
 18 | 
 19 | #ifdef _WIN32
 20 | 
 21 | #define BZ2_LIBNAME "libbz2-1.0.2.DLL" 
 22 | 
 23 | #include 
 24 | static int BZ2DLLLoaded = 0;
 25 | static HINSTANCE BZ2DLLhLib;
 26 | int BZ2DLLLoadLibrary(void)
 27 | {
 28 |    HINSTANCE hLib;
 29 | 
 30 |    if(BZ2DLLLoaded==1){return 0;}
 31 |    hLib=LoadLibrary(BZ2_LIBNAME);
 32 |    if(hLib == NULL){
 33 |       fprintf(stderr,"Can't load %s\n",BZ2_LIBNAME);
 34 |       return -1;
 35 |    }
 36 |    BZ2_bzlibVersion=GetProcAddress(hLib,"BZ2_bzlibVersion");
 37 |    BZ2_bzopen=GetProcAddress(hLib,"BZ2_bzopen");
 38 |    BZ2_bzdopen=GetProcAddress(hLib,"BZ2_bzdopen");
 39 |    BZ2_bzread=GetProcAddress(hLib,"BZ2_bzread");
 40 |    BZ2_bzwrite=GetProcAddress(hLib,"BZ2_bzwrite");
 41 |    BZ2_bzflush=GetProcAddress(hLib,"BZ2_bzflush");
 42 |    BZ2_bzclose=GetProcAddress(hLib,"BZ2_bzclose");
 43 |    BZ2_bzerror=GetProcAddress(hLib,"BZ2_bzerror");
 44 | 
 45 |    if (!BZ2_bzlibVersion || !BZ2_bzopen || !BZ2_bzdopen
 46 |        || !BZ2_bzread || !BZ2_bzwrite || !BZ2_bzflush
 47 |        || !BZ2_bzclose || !BZ2_bzerror) {
 48 |       fprintf(stderr,"GetProcAddress failed.\n");
 49 |       return -1;
 50 |    }
 51 |    BZ2DLLLoaded=1;
 52 |    BZ2DLLhLib=hLib;
 53 |    return 0;
 54 | 
 55 | }
 56 | int BZ2DLLFreeLibrary(void)
 57 | {
 58 |    if(BZ2DLLLoaded==0){return 0;}
 59 |    FreeLibrary(BZ2DLLhLib);
 60 |    BZ2DLLLoaded=0;
 61 | }
 62 | #endif /* WIN32 */
 63 | 
 64 | void usage(void)
 65 | {
 66 |    puts("usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]");
 67 | }
 68 | 
 69 | int main(int argc,char *argv[])
 70 | {
 71 |    int decompress = 0;
 72 |    int level = 9;
 73 |    char *fn_r = NULL;
 74 |    char *fn_w = NULL;
 75 | 
 76 | #ifdef _WIN32
 77 |    if(BZ2DLLLoadLibrary()<0){
 78 |       fprintf(stderr,"Loading of %s failed.  Giving up.\n", BZ2_LIBNAME);
 79 |       exit(1);
 80 |    }
 81 |    printf("Loading of %s succeeded.  Library version is %s.\n",
 82 |           BZ2_LIBNAME, BZ2_bzlibVersion() );
 83 | #endif
 84 |    while(++argv,--argc){
 85 |       if(**argv =='-' || **argv=='/'){
 86 |          char *p;
 87 | 
 88 |          for(p=*argv+1;*p;p++){
 89 |             if(*p=='d'){
 90 |                decompress = 1;
 91 |             }else if('1'<=*p && *p<='9'){
 92 |                level = *p - '0';
 93 |             }else{
 94 |                usage();
 95 |                exit(1);
 96 |             }
 97 |          }
 98 |       }else{
 99 |          break;
100 |       }
101 |    }
102 |    if(argc>=1){
103 |       fn_r = *argv;
104 |       argc--;argv++;
105 |    }else{
106 |       fn_r = NULL;
107 |    }
108 |    if(argc>=1){
109 |       fn_w = *argv;
110 |       argc--;argv++;
111 |    }else{
112 |       fn_w = NULL;
113 |    }
114 |    {
115 |       int len;
116 |       char buff[0x1000];
117 |       char mode[10];
118 | 
119 |       if(decompress){
120 |          BZFILE *BZ2fp_r = NULL;
121 |          FILE *fp_w = NULL;
122 | 
123 |          if(fn_w){
124 |             if((fp_w = fopen(fn_w,"wb"))==NULL){
125 |                printf("can't open [%s]\n",fn_w);
126 |                perror("reason:");
127 |                exit(1);
128 |             }
129 |          }else{
130 |             fp_w = stdout;
131 |          }
132 |          if((fn_r == NULL && (BZ2fp_r = BZ2_bzdopen(fileno(stdin),"rb"))==NULL)
133 |             || (fn_r != NULL && (BZ2fp_r = BZ2_bzopen(fn_r,"rb"))==NULL)){
134 |             printf("can't bz2openstream\n");
135 |             exit(1);
136 |          }
137 |          while((len=BZ2_bzread(BZ2fp_r,buff,0x1000))>0){
138 |             fwrite(buff,1,len,fp_w);
139 |          }
140 |          BZ2_bzclose(BZ2fp_r);
141 |          if(fp_w != stdout) fclose(fp_w);
142 |       }else{
143 |          BZFILE *BZ2fp_w = NULL;
144 |          FILE *fp_r = NULL;
145 | 
146 |          if(fn_r){
147 |             if((fp_r = fopen(fn_r,"rb"))==NULL){
148 |                printf("can't open [%s]\n",fn_r);
149 |                perror("reason:");
150 |                exit(1);
151 |             }
152 |          }else{
153 |             fp_r = stdin;
154 |          }
155 |          mode[0]='w';
156 |          mode[1] = '0' + level;
157 |          mode[2] = '\0';
158 | 
159 |          if((fn_w == NULL && (BZ2fp_w = BZ2_bzdopen(fileno(stdout),mode))==NULL)
160 |             || (fn_w !=NULL && (BZ2fp_w = BZ2_bzopen(fn_w,mode))==NULL)){
161 |             printf("can't bz2openstream\n");
162 |             exit(1);
163 |          }
164 |          while((len=fread(buff,1,0x1000,fp_r))>0){
165 |             BZ2_bzwrite(BZ2fp_w,buff,len);
166 |          }
167 |          BZ2_bzclose(BZ2fp_w);
168 |          if(fp_r!=stdin)fclose(fp_r);
169 |       }
170 |    }
171 | #ifdef _WIN32
172 |    BZ2DLLFreeLibrary();
173 | #endif
174 |    return 0;
175 | }
176 | 


--------------------------------------------------------------------------------
/dlltest.dsp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/bzip2-rpc/2e6d4f31c9a6b342abe2d19decaba673fce58ac6/dlltest.dsp


--------------------------------------------------------------------------------
/entities.xml:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | 
 4 | 
 5 | 
 6 | 
 7 | 
 8 | 
 9 | 
10 | 


--------------------------------------------------------------------------------
/format.pl:
--------------------------------------------------------------------------------
 1 | #!/usr/bin/perl -w
 2 | #
 3 | # ------------------------------------------------------------------
 4 | # This file is part of bzip2/libbzip2, a program and library for
 5 | # lossless, block-sorting data compression.
 6 | #
 7 | # bzip2/libbzip2 version 1.0.6 of 6 September 2010
 8 | # Copyright (C) 1996-2010 Julian Seward 
 9 | #
10 | # Please read the WARNING, DISCLAIMER and PATENTS sections in the 
11 | # README file.
12 | #
13 | # This program is released under the terms of the license contained
14 | # in the file LICENSE.
15 | # ------------------------------------------------------------------
16 | #
17 | use strict;
18 | 
19 | # get command line values:
20 | if ( $#ARGV !=1 ) {
21 |     die "Usage:  $0 xml_infile xml_outfile\n";
22 | }
23 | 
24 | my $infile = shift;
25 | # check infile exists
26 | die "Can't find file \"$infile\""
27 |   unless -f $infile;
28 | # check we can read infile
29 | if (! -r $infile) {
30 |     die "Can't read input $infile\n";
31 | }
32 | # check we can open infile
33 | open( INFILE,"<$infile" ) or 
34 |     die "Can't input $infile $!";
35 | 
36 | #my $outfile = 'fmt-manual.xml';
37 | my $outfile = shift;
38 | #print "Infile: $infile, Outfile: $outfile\n";
39 | # check we can write to outfile
40 | open( OUTFILE,">$outfile" ) or 
41 |     die "Can't output $outfile $! for writing";
42 | 
43 | my ($prev, $curr, $str);
44 | $prev = ''; $curr = '';
45 | while (  ) {
46 | 
47 | 		print OUTFILE $prev;
48 |     $prev = $curr;
49 |     $curr = $_;
50 |     $str = '';
51 | 
52 |     if ( $prev =~ /$|$/ ) {
53 |         chomp $prev;
54 |         $curr = join( '', $prev, "|<\/screen>/ ) {
59 |         chomp $prev;
60 |         $curr = join( '', $prev, "]]>", $curr );
61 | 				$prev = '';
62 |         next;
63 |     }
64 | }
65 | print OUTFILE $curr;
66 | close INFILE;
67 | close OUTFILE;
68 | exit;
69 | 


--------------------------------------------------------------------------------
/huffman.c:
--------------------------------------------------------------------------------
  1 | 
  2 | /*-------------------------------------------------------------*/
  3 | /*--- Huffman coding low-level stuff                        ---*/
  4 | /*---                                             huffman.c ---*/
  5 | /*-------------------------------------------------------------*/
  6 | 
  7 | /* ------------------------------------------------------------------
  8 |    This file is part of bzip2/libbzip2, a program and library for
  9 |    lossless, block-sorting data compression.
 10 | 
 11 |    bzip2/libbzip2 version 1.0.6 of 6 September 2010
 12 |    Copyright (C) 1996-2010 Julian Seward 
 13 | 
 14 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
 15 |    README file.
 16 | 
 17 |    This program is released under the terms of the license contained
 18 |    in the file LICENSE.
 19 |    ------------------------------------------------------------------ */
 20 | 
 21 | 
 22 | #include "bzlib_private.h"
 23 | 
 24 | /*---------------------------------------------------*/
 25 | #define WEIGHTOF(zz0)  ((zz0) & 0xffffff00)
 26 | #define DEPTHOF(zz1)   ((zz1) & 0x000000ff)
 27 | #define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3))
 28 | 
 29 | #define ADDWEIGHTS(zw1,zw2)                           \
 30 |    (WEIGHTOF(zw1)+WEIGHTOF(zw2)) |                    \
 31 |    (1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2)))
 32 | 
 33 | #define UPHEAP(z)                                     \
 34 | {                                                     \
 35 |    Int32 zz, tmp;                                     \
 36 |    zz = z; tmp = heap[zz];                            \
 37 |    while (weight[tmp] < weight[heap[zz >> 1]]) {      \
 38 |       heap[zz] = heap[zz >> 1];                       \
 39 |       zz >>= 1;                                       \
 40 |    }                                                  \
 41 |    heap[zz] = tmp;                                    \
 42 | }
 43 | 
 44 | #define DOWNHEAP(z)                                   \
 45 | {                                                     \
 46 |    Int32 zz, yy, tmp;                                 \
 47 |    zz = z; tmp = heap[zz];                            \
 48 |    while (True) {                                     \
 49 |       yy = zz << 1;                                   \
 50 |       if (yy > nHeap) break;                          \
 51 |       if (yy < nHeap &&                               \
 52 |           weight[heap[yy+1]] < weight[heap[yy]])      \
 53 |          yy++;                                        \
 54 |       if (weight[tmp] < weight[heap[yy]]) break;      \
 55 |       heap[zz] = heap[yy];                            \
 56 |       zz = yy;                                        \
 57 |    }                                                  \
 58 |    heap[zz] = tmp;                                    \
 59 | }
 60 | 
 61 | 
 62 | /*---------------------------------------------------*/
 63 | void BZ2_hbMakeCodeLengths ( UChar *len, 
 64 |                              Int32 *freq,
 65 |                              Int32 alphaSize,
 66 |                              Int32 maxLen )
 67 | {
 68 |    /*--
 69 |       Nodes and heap entries run from 1.  Entry 0
 70 |       for both the heap and nodes is a sentinel.
 71 |    --*/
 72 |    Int32 nNodes, nHeap, n1, n2, i, j, k;
 73 |    Bool  tooLong;
 74 | 
 75 |    Int32 heap   [ BZ_MAX_ALPHA_SIZE + 2 ];
 76 |    Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ];
 77 |    Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ]; 
 78 | 
 79 |    for (i = 0; i < alphaSize; i++)
 80 |       weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
 81 | 
 82 |    while (True) {
 83 | 
 84 |       nNodes = alphaSize;
 85 |       nHeap = 0;
 86 | 
 87 |       heap[0] = 0;
 88 |       weight[0] = 0;
 89 |       parent[0] = -2;
 90 | 
 91 |       for (i = 1; i <= alphaSize; i++) {
 92 |          parent[i] = -1;
 93 |          nHeap++;
 94 |          heap[nHeap] = i;
 95 |          UPHEAP(nHeap);
 96 |       }
 97 | 
 98 |       AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 );
 99 |    
100 |       while (nHeap > 1) {
101 |          n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
102 |          n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
103 |          nNodes++;
104 |          parent[n1] = parent[n2] = nNodes;
105 |          weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);
106 |          parent[nNodes] = -1;
107 |          nHeap++;
108 |          heap[nHeap] = nNodes;
109 |          UPHEAP(nHeap);
110 |       }
111 | 
112 |       AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 );
113 | 
114 |       tooLong = False;
115 |       for (i = 1; i <= alphaSize; i++) {
116 |          j = 0;
117 |          k = i;
118 |          while (parent[k] >= 0) { k = parent[k]; j++; }
119 |          len[i-1] = j;
120 |          if (j > maxLen) tooLong = True;
121 |       }
122 |       
123 |       if (! tooLong) break;
124 | 
125 |       /* 17 Oct 04: keep-going condition for the following loop used
126 |          to be 'i < alphaSize', which missed the last element,
127 |          theoretically leading to the possibility of the compressor
128 |          looping.  However, this count-scaling step is only needed if
129 |          one of the generated Huffman code words is longer than
130 |          maxLen, which up to and including version 1.0.2 was 20 bits,
131 |          which is extremely unlikely.  In version 1.0.3 maxLen was
132 |          changed to 17 bits, which has minimal effect on compression
133 |          ratio, but does mean this scaling step is used from time to
134 |          time, enough to verify that it works.
135 | 
136 |          This means that bzip2-1.0.3 and later will only produce
137 |          Huffman codes with a maximum length of 17 bits.  However, in
138 |          order to preserve backwards compatibility with bitstreams
139 |          produced by versions pre-1.0.3, the decompressor must still
140 |          handle lengths of up to 20. */
141 | 
142 |       for (i = 1; i <= alphaSize; i++) {
143 |          j = weight[i] >> 8;
144 |          j = 1 + (j / 2);
145 |          weight[i] = j << 8;
146 |       }
147 |    }
148 | }
149 | 
150 | 
151 | /*---------------------------------------------------*/
152 | void BZ2_hbAssignCodes ( Int32 *code,
153 |                          UChar *length,
154 |                          Int32 minLen,
155 |                          Int32 maxLen,
156 |                          Int32 alphaSize )
157 | {
158 |    Int32 n, vec, i;
159 | 
160 |    vec = 0;
161 |    for (n = minLen; n <= maxLen; n++) {
162 |       for (i = 0; i < alphaSize; i++)
163 |          if (length[i] == n) { code[i] = vec; vec++; };
164 |       vec <<= 1;
165 |    }
166 | }
167 | 
168 | 
169 | /*---------------------------------------------------*/
170 | void BZ2_hbCreateDecodeTables ( Int32 *limit,
171 |                                 Int32 *base,
172 |                                 Int32 *perm,
173 |                                 UChar *length,
174 |                                 Int32 minLen,
175 |                                 Int32 maxLen,
176 |                                 Int32 alphaSize )
177 | {
178 |    Int32 pp, i, j, vec;
179 | 
180 |    pp = 0;
181 |    for (i = minLen; i <= maxLen; i++)
182 |       for (j = 0; j < alphaSize; j++)
183 |          if (length[j] == i) { perm[pp] = j; pp++; };
184 | 
185 |    for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0;
186 |    for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
187 | 
188 |    for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1];
189 | 
190 |    for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0;
191 |    vec = 0;
192 | 
193 |    for (i = minLen; i <= maxLen; i++) {
194 |       vec += (base[i+1] - base[i]);
195 |       limit[i] = vec-1;
196 |       vec <<= 1;
197 |    }
198 |    for (i = minLen + 1; i <= maxLen; i++)
199 |       base[i] = ((limit[i-1] + 1) << 1) - base[i];
200 | }
201 | 
202 | 
203 | /*-------------------------------------------------------------*/
204 | /*--- end                                         huffman.c ---*/
205 | /*-------------------------------------------------------------*/
206 | 


--------------------------------------------------------------------------------
/idolize.h:
--------------------------------------------------------------------------------
 1 | #ifndef _IDOLIZE_H
 2 | #define _IDOLIZE_H
 3 | /* Copyright 2016 Google Inc. All Rights Reserved.
 4 |  *
 5 |  * Use of this source code is governed by the bzip2
 6 |  * license that can be found in the LICENSE file. */
 7 | 
 8 | #ifdef IDL_GENERATE
 9 | 
10 | /* Function annotations */
11 | 
12 | /* Initialization function for API */
13 | #define __init		__attribute__((annotate("idl:init")))
14 | /* Termination function for API */
15 | #define __term		__attribute__((annotate("idl:term")))
16 | /* Don't include this function */
17 | #define __skip		__attribute__((annotate("idl:skip")))
18 | /* Function taking a filename that has an alternative version taking a file descriptor */
19 | #define __fdalt(f)	__attribute__((annotate("idl:fdalt=" #f)))
20 | 
21 | /* Parameter and return value annotations */
22 | /* C string, \0-terminated */
23 | #define __cstring	__attribute__((annotate("idl:cstring")))
24 | /* Pointer to memory with size (in bytes) given by:
25 |  *  - the N-th parameter (counting from 1) if sz is an integer N
26 |  *  - the field or parameter with name sz if sz is an identifier
27 |  */
28 | #define __size(sz)	__attribute__((annotate("idl:size=" #sz)))
29 | /* Pointer to array of  entries */
30 | #define __count(n)	__attribute__((annotate("idl:count=" #n)))
31 | /* Pointer to freshly-allocated memory that the caller owns */
32 | #define __move		__attribute__((annotate("idl:move")))
33 | /* File descriptor */
34 | #define __isfd		__attribute__((annotate("idl:fd")))
35 | /* Parameter that is (just) an output value */
36 | #define __out		__attribute__((annotate("idl:out")))
37 | /* Pointer that is an opaque handle */
38 | #define __handle	__attribute__((annotate("idl:handle")))
39 | /* Pointer to static data */
40 | #define __static	__attribute__((annotate("idl:static")))
41 | 
42 | #else
43 | 
44 | #define __init
45 | #define __term
46 | #define __skip
47 | #define __fdalt(n)
48 | 
49 | #define __cstring
50 | #define __size(sz)
51 | #define __count(n)
52 | #define __move
53 | #define __isfd
54 | #define __out
55 | #define __handle
56 | #define __static
57 | 
58 | #endif
59 | 
60 | #endif
61 | 


--------------------------------------------------------------------------------
/libbz2.def:
--------------------------------------------------------------------------------
 1 | LIBRARY			LIBBZ2
 2 | DESCRIPTION		"libbzip2: library for data compression"
 3 | EXPORTS
 4 | 	BZ2_bzCompressInit
 5 | 	BZ2_bzCompress
 6 | 	BZ2_bzCompressEnd
 7 | 	BZ2_bzDecompressInit
 8 | 	BZ2_bzDecompress
 9 | 	BZ2_bzDecompressEnd
10 | 	BZ2_bzReadOpen
11 | 	BZ2_bzReadClose
12 | 	BZ2_bzReadGetUnused
13 | 	BZ2_bzRead
14 | 	BZ2_bzWriteOpen
15 | 	BZ2_bzWrite
16 | 	BZ2_bzWriteClose
17 | 	BZ2_bzWriteClose64
18 | 	BZ2_bzBuffToBuffCompress
19 | 	BZ2_bzBuffToBuffDecompress
20 | 	BZ2_bzlibVersion
21 | 	BZ2_bzopen
22 | 	BZ2_bzdopen
23 | 	BZ2_bzread
24 | 	BZ2_bzwrite
25 | 	BZ2_bzflush
26 | 	BZ2_bzclose
27 | 	BZ2_bzerror
28 | 


--------------------------------------------------------------------------------
/libbz2.dsp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/bzip2-rpc/2e6d4f31c9a6b342abe2d19decaba673fce58ac6/libbz2.dsp


--------------------------------------------------------------------------------
/makefile.msc:
--------------------------------------------------------------------------------
 1 | # Makefile for Microsoft Visual C++ 6.0
 2 | # usage: nmake -f makefile.msc
 3 | # K.M. Syring (syring@gsf.de)
 4 | # Fixed up by JRS for bzip2-0.9.5d release.
 5 | 
 6 | CC=cl
 7 | CFLAGS= -DWIN32 -MD -Ox -D_FILE_OFFSET_BITS=64 -nologo
 8 | 
 9 | OBJS= blocksort.obj  \
10 |       huffman.obj    \
11 |       crctable.obj   \
12 |       randtable.obj  \
13 |       compress.obj   \
14 |       decompress.obj \
15 |       bzlib.obj
16 | 
17 | all: lib bzip2 test
18 | 
19 | bzip2: lib
20 | 	$(CC) $(CFLAGS) -o bzip2 bzip2.c libbz2.lib setargv.obj
21 | 	$(CC) $(CFLAGS) -o bzip2recover bzip2recover.c
22 | 
23 | lib: $(OBJS)
24 | 	lib /out:libbz2.lib $(OBJS)
25 | 
26 | test: bzip2
27 | 	type words1
28 | 	.\\bzip2 -1  < sample1.ref > sample1.rb2
29 | 	.\\bzip2 -2  < sample2.ref > sample2.rb2
30 | 	.\\bzip2 -3  < sample3.ref > sample3.rb2
31 | 	.\\bzip2 -d  < sample1.bz2 > sample1.tst
32 | 	.\\bzip2 -d  < sample2.bz2 > sample2.tst
33 | 	.\\bzip2 -ds < sample3.bz2 > sample3.tst
34 | 	@echo All six of the fc's should find no differences.
35 | 	@echo If fc finds an error on sample3.bz2, this could be
36 | 	@echo because WinZip's 'TAR file smart CR/LF conversion'
37 | 	@echo is too clever for its own good.  Disable this option.
38 | 	@echo The correct size for sample3.ref is 120,244.  If it
39 | 	@echo is 150,251, WinZip has messed it up.
40 | 	fc sample1.bz2 sample1.rb2 
41 | 	fc sample2.bz2 sample2.rb2
42 | 	fc sample3.bz2 sample3.rb2
43 | 	fc sample1.tst sample1.ref
44 | 	fc sample2.tst sample2.ref
45 | 	fc sample3.tst sample3.ref
46 | 
47 | 
48 | 
49 | clean: 
50 | 	del *.obj
51 | 	del libbz2.lib 
52 | 	del bzip2.exe
53 | 	del bzip2recover.exe
54 | 	del sample1.rb2 
55 | 	del sample2.rb2 
56 | 	del sample3.rb2
57 | 	del sample1.tst 
58 | 	del sample2.tst
59 | 	del sample3.tst
60 | 
61 | .c.obj: 
62 | 	$(CC) $(CFLAGS) -c $*.c -o $*.obj
63 | 
64 | 


--------------------------------------------------------------------------------
/manual.html:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/bzip2-rpc/2e6d4f31c9a6b342abe2d19decaba673fce58ac6/manual.html


--------------------------------------------------------------------------------
/manual.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/bzip2-rpc/2e6d4f31c9a6b342abe2d19decaba673fce58ac6/manual.pdf


--------------------------------------------------------------------------------
/mk251.c:
--------------------------------------------------------------------------------
 1 | 
 2 | /* Spew out a long sequence of the byte 251.  When fed to bzip2
 3 |    versions 1.0.0 or 1.0.1, causes it to die with internal error
 4 |    1007 in blocksort.c.  This assertion misses an extremely rare
 5 |    case, which is fixed in this version (1.0.2) and above.
 6 | */
 7 | 
 8 | /* ------------------------------------------------------------------
 9 |    This file is part of bzip2/libbzip2, a program and library for
10 |    lossless, block-sorting data compression.
11 | 
12 |    bzip2/libbzip2 version 1.0.6 of 6 September 2010
13 |    Copyright (C) 1996-2010 Julian Seward 
14 | 
15 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
16 |    README file.
17 | 
18 |    This program is released under the terms of the license contained
19 |    in the file LICENSE.
20 |    ------------------------------------------------------------------ */
21 | 
22 | 
23 | #include 
24 | 
25 | int main ()
26 | {
27 |    int i;
28 |    for (i = 0; i < 48500000 ; i++)
29 |      putchar(251);
30 |    return 0;
31 | }
32 | 


--------------------------------------------------------------------------------
/randtable.c:
--------------------------------------------------------------------------------
 1 | 
 2 | /*-------------------------------------------------------------*/
 3 | /*--- Table for randomising repetitive blocks               ---*/
 4 | /*---                                           randtable.c ---*/
 5 | /*-------------------------------------------------------------*/
 6 | 
 7 | /* ------------------------------------------------------------------
 8 |    This file is part of bzip2/libbzip2, a program and library for
 9 |    lossless, block-sorting data compression.
10 | 
11 |    bzip2/libbzip2 version 1.0.6 of 6 September 2010
12 |    Copyright (C) 1996-2010 Julian Seward 
13 | 
14 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
15 |    README file.
16 | 
17 |    This program is released under the terms of the license contained
18 |    in the file LICENSE.
19 |    ------------------------------------------------------------------ */
20 | 
21 | 
22 | #include "bzlib_private.h"
23 | 
24 | 
25 | /*---------------------------------------------*/
26 | Int32 BZ2_rNums[512] = { 
27 |    619, 720, 127, 481, 931, 816, 813, 233, 566, 247, 
28 |    985, 724, 205, 454, 863, 491, 741, 242, 949, 214, 
29 |    733, 859, 335, 708, 621, 574, 73, 654, 730, 472, 
30 |    419, 436, 278, 496, 867, 210, 399, 680, 480, 51, 
31 |    878, 465, 811, 169, 869, 675, 611, 697, 867, 561, 
32 |    862, 687, 507, 283, 482, 129, 807, 591, 733, 623, 
33 |    150, 238, 59, 379, 684, 877, 625, 169, 643, 105, 
34 |    170, 607, 520, 932, 727, 476, 693, 425, 174, 647, 
35 |    73, 122, 335, 530, 442, 853, 695, 249, 445, 515, 
36 |    909, 545, 703, 919, 874, 474, 882, 500, 594, 612, 
37 |    641, 801, 220, 162, 819, 984, 589, 513, 495, 799, 
38 |    161, 604, 958, 533, 221, 400, 386, 867, 600, 782, 
39 |    382, 596, 414, 171, 516, 375, 682, 485, 911, 276, 
40 |    98, 553, 163, 354, 666, 933, 424, 341, 533, 870, 
41 |    227, 730, 475, 186, 263, 647, 537, 686, 600, 224, 
42 |    469, 68, 770, 919, 190, 373, 294, 822, 808, 206, 
43 |    184, 943, 795, 384, 383, 461, 404, 758, 839, 887, 
44 |    715, 67, 618, 276, 204, 918, 873, 777, 604, 560, 
45 |    951, 160, 578, 722, 79, 804, 96, 409, 713, 940, 
46 |    652, 934, 970, 447, 318, 353, 859, 672, 112, 785, 
47 |    645, 863, 803, 350, 139, 93, 354, 99, 820, 908, 
48 |    609, 772, 154, 274, 580, 184, 79, 626, 630, 742, 
49 |    653, 282, 762, 623, 680, 81, 927, 626, 789, 125, 
50 |    411, 521, 938, 300, 821, 78, 343, 175, 128, 250, 
51 |    170, 774, 972, 275, 999, 639, 495, 78, 352, 126, 
52 |    857, 956, 358, 619, 580, 124, 737, 594, 701, 612, 
53 |    669, 112, 134, 694, 363, 992, 809, 743, 168, 974, 
54 |    944, 375, 748, 52, 600, 747, 642, 182, 862, 81, 
55 |    344, 805, 988, 739, 511, 655, 814, 334, 249, 515, 
56 |    897, 955, 664, 981, 649, 113, 974, 459, 893, 228, 
57 |    433, 837, 553, 268, 926, 240, 102, 654, 459, 51, 
58 |    686, 754, 806, 760, 493, 403, 415, 394, 687, 700, 
59 |    946, 670, 656, 610, 738, 392, 760, 799, 887, 653, 
60 |    978, 321, 576, 617, 626, 502, 894, 679, 243, 440, 
61 |    680, 879, 194, 572, 640, 724, 926, 56, 204, 700, 
62 |    707, 151, 457, 449, 797, 195, 791, 558, 945, 679, 
63 |    297, 59, 87, 824, 713, 663, 412, 693, 342, 606, 
64 |    134, 108, 571, 364, 631, 212, 174, 643, 304, 329, 
65 |    343, 97, 430, 751, 497, 314, 983, 374, 822, 928, 
66 |    140, 206, 73, 263, 980, 736, 876, 478, 430, 305, 
67 |    170, 514, 364, 692, 829, 82, 855, 953, 676, 246, 
68 |    369, 970, 294, 750, 807, 827, 150, 790, 288, 923, 
69 |    804, 378, 215, 828, 592, 281, 565, 555, 710, 82, 
70 |    896, 831, 547, 261, 524, 462, 293, 465, 502, 56, 
71 |    661, 821, 976, 991, 658, 869, 905, 758, 745, 193, 
72 |    768, 550, 608, 933, 378, 286, 215, 979, 792, 961, 
73 |    61, 688, 793, 644, 986, 403, 106, 366, 905, 644, 
74 |    372, 567, 466, 434, 645, 210, 389, 550, 919, 135, 
75 |    780, 773, 635, 389, 707, 100, 626, 958, 165, 504, 
76 |    920, 176, 193, 713, 857, 265, 203, 50, 668, 108, 
77 |    645, 990, 626, 197, 510, 357, 358, 850, 858, 364, 
78 |    936, 638
79 | };
80 | 
81 | 
82 | /*-------------------------------------------------------------*/
83 | /*--- end                                       randtable.c ---*/
84 | /*-------------------------------------------------------------*/
85 | 


--------------------------------------------------------------------------------
/rpc-invoke.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/bzip2-rpc/2e6d4f31c9a6b342abe2d19decaba673fce58ac6/rpc-invoke.png


--------------------------------------------------------------------------------
/rpc-setup.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/bzip2-rpc/2e6d4f31c9a6b342abe2d19decaba673fce58ac6/rpc-setup.png


--------------------------------------------------------------------------------
/rpc-util.c:
--------------------------------------------------------------------------------
  1 | /* Copyright 2016 Google Inc. All Rights Reserved.
  2 |  *
  3 |  * Use of this source code is governed by the bzip2
  4 |  * license that can be found in the LICENSE file. */
  5 | 
  6 | #include "rpc-util.h"
  7 | 
  8 | #include 
  9 | #include 
 10 | #include 
 11 | #include 
 12 | #include 
 13 | #include 
 14 | #include 
 15 | #include 
 16 | #include 
 17 | #include 
 18 | #include 
 19 | 
 20 | void _log_at(int level, const char *filename, int lineno, const char *format, ...) {
 21 |   if (level < _rpc_verbose) return;
 22 |   va_list args;
 23 |   va_start(args, format);
 24 |   fprintf(stderr, "%*s[%d %s:%d] ", _rpc_indent, "", getpid(), filename, lineno);
 25 |   vfprintf(stderr, format, args);
 26 |   fprintf(stderr, "\n");
 27 |   va_end(args);
 28 |   if (level >= 10) exit(1);
 29 | }
 30 | 
 31 | static void __attribute__((constructor)) _log_init(void) {
 32 |   const char *value = getenv("RPC_DEBUG");
 33 |   if (!value) return;
 34 |   _rpc_verbose = atoi(value);
 35 | }
 36 | 
 37 | void CrashHandler(int sig) {
 38 |   void *bt[20];
 39 |   size_t count;
 40 |   int ii;
 41 | 
 42 |   error_("Crash handler for signal %d", sig);
 43 |   count = backtrace(bt, 20);
 44 |   char **frames = backtrace_symbols(bt, count);
 45 |   for (ii = 0; ii < count; ii++) {
 46 |     error_("  %s", frames[ii]);
 47 |   }
 48 |   exit(1);
 49 | }
 50 | 
 51 | int OpenDriver(const char* filename) {
 52 |   int fd = open(filename, O_RDONLY|O_CLOEXEC);
 53 |   if (fd < 0) {
 54 |     error_("failed to open driver executable %s, errno=%d", filename, errno);
 55 |   }
 56 |   verbose_("opened fd=%d for '%s'", fd, filename);
 57 |   return fd;
 58 | }
 59 | 
 60 | void RunDriver(int xfd, const char *filename, int sock_fd) {
 61 |   /* Child process: store the socket FD in the environment */
 62 |   char *argv[] = {(char *)filename, NULL};
 63 |   char nonce_buffer[] = "API_NONCE_FD=xxxxxxxx";
 64 |   char debug_buffer[] = "RPC_DEBUG=xxxxxxx";
 65 |   char * envp[] = {nonce_buffer, debug_buffer, NULL};
 66 |   sprintf(nonce_buffer, "API_NONCE_FD=%d", sock_fd);
 67 |   sprintf(debug_buffer, "RPC_DEBUG=%d", _rpc_verbose);
 68 |   verbose_("in child process, about to fexecve(fd=%d ('%s'), API_NONCE_FD=%d)",
 69 |            xfd, filename, sock_fd);
 70 |   /* Execute the driver program. */
 71 |   fexecve(xfd, argv, envp);
 72 |   fatal_("!!! in child process, failed to fexecve, errno=%d (%s)", errno, strerror(errno));
 73 | }
 74 | 
 75 | void TerminateChild(pid_t child) {
 76 |   if (child > 0) {
 77 |     int status;
 78 |     log_("kill child %d", child);
 79 |     kill(child, SIGKILL);
 80 |     log_("reap child %d", child);
 81 |     pid_t rc = waitpid(child, &status, 0);
 82 |     log_("reaped child %d, rc=%d, status=%x", child, rc, status);
 83 |     child = 0;
 84 |   }
 85 | }
 86 | 
 87 | int GetTransferredFd(int sock_fd, int nonce) {
 88 |   int value = -1;
 89 |   struct iovec iov;
 90 |   iov.iov_base = &value;
 91 |   iov.iov_len = sizeof(nonce);
 92 |   unsigned char data[CMSG_SPACE(sizeof(int))];
 93 |   struct msghdr msg;
 94 |   memset(&msg, 0, sizeof(msg));
 95 |   msg.msg_iov = &iov;
 96 |   msg.msg_iovlen = 1;
 97 |   msg.msg_controllen = sizeof(data);
 98 |   msg.msg_control = data;
 99 | 
100 |   struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
101 |   cmsg->cmsg_len = CMSG_LEN(sizeof(int));
102 |   cmsg->cmsg_level = SOL_SOCKET;
103 |   cmsg->cmsg_type = SCM_RIGHTS;
104 | 
105 |   int rc;
106 |   do {
107 |     rc = recvmsg(sock_fd, &msg, 0);
108 |   } while (rc == -1 && errno == EINTR);
109 |   cmsg = CMSG_FIRSTHDR(&msg);
110 |   if (cmsg == NULL)
111 |     fatal_("no cmsghdr received");
112 |   if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
113 |     fatal_("unexpected cmsg_len %d", cmsg->cmsg_len);
114 |   if (cmsg->cmsg_level != SOL_SOCKET)
115 |     fatal_("unexpected cmsg_level %d", cmsg->cmsg_level);
116 |   if (cmsg->cmsg_type != SCM_RIGHTS)
117 |     fatal_("unexpected cmsg_type %d", cmsg->cmsg_type);
118 |   if (value != nonce)
119 |     fatal_("unexpected nonce value %d not %d", value, nonce);
120 | 
121 |   int fd = *((int *) CMSG_DATA(cmsg));
122 |   log_("received fd %d across socket %d nonce=%d rc=%d", fd, sock_fd, nonce, rc);
123 |   return fd;
124 | }
125 | 
126 | /* Returns nonce to be sent instead */
127 | int TransferFd(int sock_fd, int fd) {
128 |   int nonce = rand();
129 |   struct iovec iov;
130 |   iov.iov_base = &nonce;
131 |   iov.iov_len = sizeof(nonce);
132 |   unsigned char data[CMSG_SPACE(sizeof(int))];
133 |   struct msghdr msg;
134 |   memset(&msg, 0, sizeof(msg));
135 |   msg.msg_iov = &iov;
136 |   msg.msg_iovlen = 1;
137 |   msg.msg_controllen = sizeof(data);
138 |   msg.msg_control = data;
139 | 
140 |   struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
141 |   cmsg->cmsg_len = CMSG_LEN(sizeof(int));
142 |   cmsg->cmsg_level = SOL_SOCKET;
143 |   cmsg->cmsg_type = SCM_RIGHTS;
144 |   *((int*)CMSG_DATA(cmsg)) = fd;
145 | 
146 |   int rc = sendmsg(sock_fd, &msg, 0);
147 |   log_("sent fd %d across socket %d with nonce=%d rc=%d", fd, sock_fd, nonce, rc);
148 |   return nonce;
149 | }
150 | 


--------------------------------------------------------------------------------
/rpc-util.h:
--------------------------------------------------------------------------------
 1 | #ifndef _RPC_UTIL_H
 2 | #define _RPC_UTIL_H
 3 | /* Copyright 2016 Google Inc. All Rights Reserved.
 4 |  *
 5 |  * Use of this source code is governed by the bzip2
 6 |  * license that can be found in the LICENSE file. */
 7 | 
 8 | /* Logging & other utilities */
 9 | #include 
10 | #include 
11 | 
12 | extern int _rpc_verbose;
13 | extern int _rpc_indent;
14 | 
15 | #ifdef __cplusplus
16 | extern "C" {
17 | #endif
18 | 
19 | void _log_at(int level, const char *filename, int lineno, const char *format, ...);
20 | void CrashHandler(int sig);
21 | int OpenDriver(const char* filename);
22 | void RunDriver(int xfd, const char *filename, int sock_fd);
23 | void TerminateChild(pid_t child);
24 | int GetTransferredFd(int sock_fd, int nonce);
25 | int TransferFd(int sock_fd, int fd);
26 | 
27 | #ifdef __cplusplus
28 | }
29 | #endif
30 | 
31 | #define verbose_(...) _log_at(0, __FILE__, __LINE__, __VA_ARGS__)
32 | #define log_(...)     _log_at(1, __FILE__, __LINE__, __VA_ARGS__)
33 | #define api_(...)     _log_at(2, __FILE__, __LINE__, __VA_ARGS__)
34 | #define warning_(...) _log_at(3, __FILE__, __LINE__, __VA_ARGS__)
35 | #define error_(...)   _log_at(4, __FILE__, __LINE__, __VA_ARGS__)
36 | #define fatal_(...)   _log_at(10,__FILE__, __LINE__, __VA_ARGS__)
37 | 
38 | #endif
39 | 


--------------------------------------------------------------------------------
/sample1.bz2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/bzip2-rpc/2e6d4f31c9a6b342abe2d19decaba673fce58ac6/sample1.bz2


--------------------------------------------------------------------------------
/sample1.ref:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/bzip2-rpc/2e6d4f31c9a6b342abe2d19decaba673fce58ac6/sample1.ref


--------------------------------------------------------------------------------
/sample2.bz2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/bzip2-rpc/2e6d4f31c9a6b342abe2d19decaba673fce58ac6/sample2.bz2


--------------------------------------------------------------------------------
/sample2.ref:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/bzip2-rpc/2e6d4f31c9a6b342abe2d19decaba673fce58ac6/sample2.ref


--------------------------------------------------------------------------------
/sample3.bz2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/bzip2-rpc/2e6d4f31c9a6b342abe2d19decaba673fce58ac6/sample3.bz2


--------------------------------------------------------------------------------
/spewG.c:
--------------------------------------------------------------------------------
 1 | 
 2 | /* spew out a thoroughly gigantic file designed so that bzip2
 3 |    can compress it reasonably rapidly.  This is to help test
 4 |    support for large files (> 2GB) in a reasonable amount of time.
 5 |    I suggest you use the undocumented --exponential option to
 6 |    bzip2 when compressing the resulting file; this saves a bit of
 7 |    time.  Note: *don't* bother with --exponential when compressing 
 8 |    Real Files; it'll just waste a lot of CPU time :-)
 9 |    (but is otherwise harmless).
10 | */
11 | 
12 | /* ------------------------------------------------------------------
13 |    This file is part of bzip2/libbzip2, a program and library for
14 |    lossless, block-sorting data compression.
15 | 
16 |    bzip2/libbzip2 version 1.0.6 of 6 September 2010
17 |    Copyright (C) 1996-2010 Julian Seward 
18 | 
19 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
20 |    README file.
21 | 
22 |    This program is released under the terms of the license contained
23 |    in the file LICENSE.
24 | 	 ------------------------------------------------------------------ */
25 | 
26 | 
27 | #define _FILE_OFFSET_BITS 64
28 | 
29 | #include 
30 | #include 
31 | 
32 | /* The number of megabytes of junk to spew out (roughly) */
33 | #define MEGABYTES 5000
34 | 
35 | #define N_BUF 1000000
36 | char buf[N_BUF];
37 | 
38 | int main ( int argc, char** argv )
39 | {
40 |    int ii, kk, p;
41 |    srandom(1);
42 |    setbuffer ( stdout, buf, N_BUF );
43 |    for (kk = 0; kk < MEGABYTES * 515; kk+=3) {
44 |       p = 25+random()%50;
45 |       for (ii = 0; ii < p; ii++)
46 |          printf ( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" );
47 |       for (ii = 0; ii < p-1; ii++)
48 |          printf ( "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" );
49 |       for (ii = 0; ii < p+1; ii++)
50 |          printf ( "ccccccccccccccccccccccccccccccccccccc" );
51 |    }
52 |    fflush(stdout);
53 |    return 0;
54 | }
55 | 


--------------------------------------------------------------------------------
/stream.c:
--------------------------------------------------------------------------------
  1 | #include "bzlib_private.h"
  2 | 
  3 | /* ------------------------------------------------------------------
  4 |    This file is part of bzip2/libbzip2, a program and library for
  5 |    lossless, block-sorting data compression.
  6 | 
  7 |    bzip2/libbzip2 version 1.0.6 of 6 September 2010
  8 |    Copyright (C) 1996-2010 Julian Seward 
  9 | 
 10 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the
 11 |    README file.
 12 | 
 13 |    This program is released under the terms of the license contained
 14 |    in the file LICENSE.
 15 |    ------------------------------------------------------------------ */
 16 | 
 17 | /*---------------------------------------------------*/
 18 | /*--- An implementation of 64-bit ints.  Sigh.    ---*/
 19 | /*--- Roll on widespread deployment of ANSI C9X ! ---*/
 20 | /*---------------------------------------------------*/
 21 | 
 22 | void uInt64_from_UInt32s ( UInt64* n, UInt32 lo32, UInt32 hi32 )
 23 | {
 24 |    n->b[7] = (UChar)((hi32 >> 24) & 0xFF);
 25 |    n->b[6] = (UChar)((hi32 >> 16) & 0xFF);
 26 |    n->b[5] = (UChar)((hi32 >> 8)  & 0xFF);
 27 |    n->b[4] = (UChar) (hi32        & 0xFF);
 28 |    n->b[3] = (UChar)((lo32 >> 24) & 0xFF);
 29 |    n->b[2] = (UChar)((lo32 >> 16) & 0xFF);
 30 |    n->b[1] = (UChar)((lo32 >> 8)  & 0xFF);
 31 |    n->b[0] = (UChar) (lo32        & 0xFF);
 32 | }
 33 | 
 34 | double uInt64_to_double ( UInt64* n )
 35 | {
 36 |    Int32  i;
 37 |    double base = 1.0;
 38 |    double sum  = 0.0;
 39 |    for (i = 0; i < 8; i++) {
 40 |       sum  += base * (double)(n->b[i]);
 41 |       base *= 256.0;
 42 |    }
 43 |    return sum;
 44 | }
 45 | 
 46 | Bool uInt64_isZero ( UInt64* n )
 47 | {
 48 |    Int32 i;
 49 |    for (i = 0; i < 8; i++)
 50 |       if (n->b[i] != 0) return 0;
 51 |    return 1;
 52 | }
 53 | 
 54 | 
 55 | /* Divide *n by 10, and return the remainder.  */
 56 | Int32 uInt64_qrm10 ( UInt64* n )
 57 | {
 58 |    UInt32 rem, tmp;
 59 |    Int32  i;
 60 |    rem = 0;
 61 |    for (i = 7; i >= 0; i--) {
 62 |       tmp = rem * 256 + n->b[i];
 63 |       n->b[i] = tmp / 10;
 64 |       rem = tmp % 10;
 65 |    }
 66 |    return rem;
 67 | }
 68 | 
 69 | 
 70 | /* ... and the Whole Entire Point of all this UInt64 stuff is
 71 |    so that we can supply the following function.
 72 | */
 73 | void uInt64_toAscii ( char* outbuf, UInt64* n )
 74 | {
 75 |    Int32  i, q;
 76 |    UChar  buf[32];
 77 |    Int32  nBuf   = 0;
 78 |    UInt64 n_copy = *n;
 79 |    do {
 80 |       q = uInt64_qrm10 ( &n_copy );
 81 |       buf[nBuf] = q + '0';
 82 |       nBuf++;
 83 |    } while (!uInt64_isZero(&n_copy));
 84 |    outbuf[nBuf] = 0;
 85 |    for (i = 0; i < nBuf; i++)
 86 |       outbuf[i] = buf[nBuf-i-1];
 87 | }
 88 | 
 89 | 
 90 | /*---------------------------------------------------*/
 91 | /*--- Processing of complete files and streams    ---*/
 92 | /*---------------------------------------------------*/
 93 | 
 94 | /*---------------------------------------------*/
 95 | static
 96 | Bool myfeof ( FILE* f )
 97 | {
 98 |    Int32 c = fgetc ( f );
 99 |    if (c == EOF) return True;
100 |    ungetc ( c, f );
101 |    return False;
102 | }
103 | 
104 | 
105 | /*---------------------------------------------------*/
106 | int BZ_API(BZ2_bzCompressStream)( int        ifd,
107 |                                   int        ofd,
108 |                                   int        blockSize100k,
109 |                                   int        verbosity,
110 |                                   int        workFactor )
111 | {
112 |    FILE*   stream;
113 |    FILE*   zStream;
114 |    BZFILE* bzf = NULL;
115 |    UChar   ibuf[5000];
116 |    Int32   nIbuf;
117 |    UInt32  nbytes_in_lo32, nbytes_in_hi32;
118 |    UInt32  nbytes_out_lo32, nbytes_out_hi32;
119 |    Int32   bzerr, ret;
120 | 
121 |    stream = fdopen(ifd, "r");
122 |    if (!stream || ferror(stream)) return BZ_IO_ERROR;
123 |    zStream = fdopen(ofd, "w");
124 |    if (!zStream || ferror(zStream)) return BZ_IO_ERROR;
125 | 
126 |    bzf = BZ2_bzWriteOpen ( &bzerr, zStream,
127 |                            blockSize100k, verbosity, workFactor );
128 |    if (bzerr != BZ_OK) return bzerr;
129 | 
130 |    if (verbosity >= 2) fprintf ( stderr, "\n" );
131 | 
132 |    while (True) {
133 | 
134 |       if (myfeof(stream)) break;
135 |       nIbuf = fread ( ibuf, sizeof(UChar), 5000, stream );
136 |       if (ferror(stream)) return BZ_IO_ERROR;
137 |       if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf );
138 |       if (bzerr != BZ_OK) return bzerr;
139 | 
140 |    }
141 | 
142 |    BZ2_bzWriteClose64 ( &bzerr, bzf, 0,
143 |                         &nbytes_in_lo32, &nbytes_in_hi32,
144 |                         &nbytes_out_lo32, &nbytes_out_hi32 );
145 |    if (bzerr != BZ_OK) return bzerr;
146 | 
147 |    if (ferror(zStream)) return BZ_IO_ERROR;
148 |    ret = fflush ( zStream );
149 |    if (ret == EOF) return BZ_IO_ERROR;
150 | 
151 |    if (verbosity >= 1) {
152 |       if (nbytes_in_lo32 == 0 && nbytes_in_hi32 == 0) {
153 |          fprintf ( stderr, " no data compressed.\n");
154 |       } else {
155 |          Char   buf_nin[32], buf_nout[32];
156 |          UInt64 nbytes_in,   nbytes_out;
157 |          double nbytes_in_d, nbytes_out_d;
158 |          uInt64_from_UInt32s ( &nbytes_in,
159 |                                nbytes_in_lo32, nbytes_in_hi32 );
160 |          uInt64_from_UInt32s ( &nbytes_out,
161 |                                nbytes_out_lo32, nbytes_out_hi32 );
162 |          nbytes_in_d  = uInt64_to_double ( &nbytes_in );
163 |          nbytes_out_d = uInt64_to_double ( &nbytes_out );
164 |          uInt64_toAscii ( buf_nin, &nbytes_in );
165 |          uInt64_toAscii ( buf_nout, &nbytes_out );
166 |          fprintf ( stderr, "%6.3f:1, %6.3f bits/byte, "
167 |                    "%5.2f%% saved, %s in, %s out.\n",
168 |                    nbytes_in_d / nbytes_out_d,
169 |                    (8.0 * nbytes_out_d) / nbytes_in_d,
170 |                    100.0 * (1.0 - nbytes_out_d / nbytes_in_d),
171 |                    buf_nin,
172 |                    buf_nout
173 |                  );
174 |       }
175 |    }
176 | 
177 |    return BZ_OK;
178 | }
179 | 
180 | /*---------------------------------------------------*/
181 | int BZ_API(BZ2_bzDecompressStream)( int        ifd,
182 |                                     int        ofd,
183 |                                     int        verbosity,
184 |                                     int        small )
185 | {
186 |    FILE*   stream;
187 |    FILE*   zStream;
188 |    BZFILE* bzf = NULL;
189 |    Int32   bzerr, ret, nread, streamNo, i;
190 |    UChar   obuf[5000];
191 |    UChar   unused[BZ_MAX_UNUSED];
192 |    Int32   nUnused;
193 |    const void* unusedTmpV;
194 |    UChar*  unusedTmp;
195 | 
196 |    nUnused = 0;
197 |    streamNo = 0;
198 | 
199 |    zStream = fdopen(ifd, "r");
200 |    if (!zStream || ferror(zStream)) return BZ_IO_ERROR;
201 |    stream = fdopen(ofd, "w");
202 |    if (!stream || ferror(stream)) return BZ_IO_ERROR;
203 | 
204 |    while (True) {
205 | 
206 |       bzf = BZ2_bzReadOpen ( &bzerr, zStream, verbosity,
207 |                              small, unused, nUnused );
208 |       if (bzerr != BZ_OK) return bzerr;
209 |       if (bzf == NULL) return BZ_IO_ERROR;
210 |       streamNo++;
211 | 
212 |       while (bzerr == BZ_OK) {
213 |          nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
214 |          if (bzerr == BZ_DATA_ERROR_MAGIC) {
215 |            if (streamNo == 1) {
216 |              return bzerr;
217 |            } else {
218 |              return BZ_OK;
219 |            }
220 |          }
221 |          if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0)
222 |             fwrite ( obuf, sizeof(UChar), nread, stream );
223 |          if (ferror(stream)) return BZ_IO_ERROR;
224 |       }
225 |       if (bzerr != BZ_STREAM_END) return bzerr;
226 | 
227 |       BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
228 |       if (bzerr != BZ_OK) return bzerr;
229 | 
230 |       unusedTmp = (UChar*)unusedTmpV;
231 |       for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
232 | 
233 |       BZ2_bzReadClose ( &bzerr, bzf );
234 |       if (bzerr != BZ_OK) return bzerr;
235 | 
236 |       if (nUnused == 0 && myfeof(zStream)) break;
237 |    }
238 | 
239 |    if (ferror(zStream)) return BZ_IO_ERROR;
240 |    if (ferror(stream)) return BZ_IO_ERROR;
241 |    ret = fflush ( stream );
242 |    if (ret != 0) return BZ_IO_ERROR;
243 |    if (verbosity >= 2) fprintf ( stderr, "\n    " );
244 |    return BZ_OK;
245 | }
246 | 
247 | /*---------------------------------------------------*/
248 | int BZ_API(BZ2_bzTestStream)( int        ifd,
249 |                               int        verbosity,
250 |                               int        small )
251 | {
252 |    FILE*   zStream;
253 |    BZFILE* bzf = NULL;
254 |    Int32   bzerr, streamNo, i;
255 |    UChar   obuf[5000];
256 |    UChar   unused[BZ_MAX_UNUSED];
257 |    Int32   nUnused;
258 |    const void* unusedTmpV;
259 |    UChar*  unusedTmp;
260 | 
261 |    nUnused = 0;
262 |    streamNo = 0;
263 | 
264 |    zStream = fdopen(ifd, "r");
265 |    if (!zStream || ferror(zStream)) return BZ_IO_ERROR;
266 | 
267 |    while (True) {
268 | 
269 |       bzf = BZ2_bzReadOpen ( &bzerr, zStream, verbosity,
270 |                              small, unused, nUnused );
271 |       if (bzerr != BZ_OK) return bzerr;
272 |       if (bzf == NULL) return BZ_IO_ERROR;
273 |       streamNo++;
274 | 
275 |       while (bzerr == BZ_OK) {
276 |          BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
277 |          if (bzerr == BZ_DATA_ERROR_MAGIC) return bzerr;
278 |       }
279 |       if (bzerr != BZ_STREAM_END) return bzerr;
280 | 
281 |       BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
282 |       if (bzerr != BZ_OK) return bzerr;
283 | 
284 |       unusedTmp = (UChar*)unusedTmpV;
285 |       for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
286 | 
287 |       BZ2_bzReadClose ( &bzerr, bzf );
288 |       if (bzerr != BZ_OK) return bzerr;
289 |       if (nUnused == 0 && myfeof(zStream)) break;
290 | 
291 |    }
292 | 
293 |    if (ferror(zStream)) return BZ_IO_ERROR;
294 | 
295 |    if (verbosity >= 2) fprintf ( stderr, "\n    " );
296 |    return BZ_OK;
297 | }
298 | 


--------------------------------------------------------------------------------
/test-run.sh:
--------------------------------------------------------------------------------
 1 | #!/bin/sh
 2 | # Copyright 2016 Google Inc. All Rights Reserved.
 3 | #
 4 | # Use of this source code is governed by the bzip2
 5 | # license that can be found in the LICENSE file.
 6 | BZIP=$1
 7 | set -e
 8 | $BZIP -1  < sample1.ref > sample1.rb2
 9 | cmp sample1.bz2 sample1.rb2
10 | $BZIP -2  < sample2.ref > sample2.rb2
11 | cmp sample2.bz2 sample2.rb2
12 | $BZIP -3  < sample3.ref > sample3.rb2
13 | cmp sample3.bz2 sample3.rb2
14 | $BZIP -d  < sample1.bz2 > sample1.tst
15 | cmp sample1.tst sample1.ref
16 | $BZIP -d  < sample2.bz2 > sample2.tst
17 | cmp sample2.tst sample2.ref
18 | $BZIP -ds < sample3.bz2 > sample3.tst
19 | cmp sample3.tst sample3.ref
20 | 


--------------------------------------------------------------------------------
/third_party/libnv/LICENSE:
--------------------------------------------------------------------------------
 1 | Copyright (c) 2009-2013 The FreeBSD Foundation
 2 | Copyright (c) 2013-2015 Mariusz Zaborski 
 3 | All rights reserved.
 4 | 
 5 | This software was developed by Pawel Jakub Dawidek under sponsorship from
 6 | the FreeBSD Foundation.
 7 | 
 8 | Redistribution and use in source and binary forms, with or without
 9 | modification, are permitted provided that the following conditions
10 | are met:
11 | 1. Redistributions of source code must retain the above copyright
12 |    notice, this list of conditions and the following disclaimer.
13 | 2. Redistributions in binary form must reproduce the above copyright
14 |    notice, this list of conditions and the following disclaimer in the
15 |    documentation and/or other materials provided with the distribution.
16 | 
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 | SUCH DAMAGE.
28 | 


--------------------------------------------------------------------------------
/third_party/libnv/README.google:
--------------------------------------------------------------------------------
 1 | URL:
 2 |   https://svnweb.freebsd.org/base/head/lib/libnv/?revision=291939
 3 |   https://svnweb.freebsd.org/base/head/sys/contrib/libnv/?revision=291939
 4 |   https://svnweb.freebsd.org/base/head/share/man/man9/nv.9?revision=291939
 5 | Version: r291939
 6 | License: BSD
 7 | License File: LICENSE
 8 | Description: Name/value pairs library.
 9 |   The libnv library allows to easily manage name value pairs as well as
10 |   send and receive them over sockets.
11 | Local Modifications:
12 |   - Drop _KERNEL macroing, as this version is only ever in userspace.
13 |   - Add extern "C" {} wrapper to header.
14 |   - Support Linux credential transfer with struct ucred.


--------------------------------------------------------------------------------
/third_party/libnv/common_impl.h:
--------------------------------------------------------------------------------
 1 | /*-
 2 |  * Copyright (c) 2013 The FreeBSD Foundation
 3 |  * All rights reserved.
 4 |  *
 5 |  * This software was developed by Pawel Jakub Dawidek under sponsorship from
 6 |  * the FreeBSD Foundation.
 7 |  *
 8 |  * Redistribution and use in source and binary forms, with or without
 9 |  * modification, are permitted provided that the following conditions
10 |  * are met:
11 |  * 1. Redistributions of source code must retain the above copyright
12 |  *    notice, this list of conditions and the following disclaimer.
13 |  * 2. Redistributions in binary form must reproduce the above copyright
14 |  *    notice, this list of conditions and the following disclaimer in the
15 |  *    documentation and/or other materials provided with the distribution.
16 |  *
17 |  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18 |  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 |  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21 |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 |  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 |  * SUCH DAMAGE.
28 |  *
29 |  * $FreeBSD$
30 |  */
31 | 
32 | #ifndef	_COMMON_IMPL_H_
33 | #define	_COMMON_IMPL_H_
34 | 
35 | #define	fd_is_valid(fd)	(fcntl((fd), F_GETFL) != -1 || errno != EBADF)
36 | 
37 | #endif	/* !_COMMON_IMPL_H_ */
38 | 


--------------------------------------------------------------------------------
/third_party/libnv/dnv.h:
--------------------------------------------------------------------------------
 1 | /*-
 2 |  * Copyright (c) 2013 The FreeBSD Foundation
 3 |  * All rights reserved.
 4 |  *
 5 |  * This software was developed by Pawel Jakub Dawidek under sponsorship from
 6 |  * the FreeBSD Foundation.
 7 |  *
 8 |  * Redistribution and use in source and binary forms, with or without
 9 |  * modification, are permitted provided that the following conditions
10 |  * are met:
11 |  * 1. Redistributions of source code must retain the above copyright
12 |  *    notice, this list of conditions and the following disclaimer.
13 |  * 2. Redistributions in binary form must reproduce the above copyright
14 |  *    notice, this list of conditions and the following disclaimer in the
15 |  *    documentation and/or other materials provided with the distribution.
16 |  *
17 |  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18 |  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 |  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21 |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 |  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 |  * SUCH DAMAGE.
28 |  *
29 |  * $FreeBSD$
30 |  */
31 | 
32 | #ifndef	_DNV_H_
33 | #define	_DNV_H_
34 | 
35 | #include 
36 | 
37 | #include 
38 | #include 
39 | #include 
40 | #include 
41 | 
42 | #ifndef __printflike
43 | #define __printflike(A, B)	__attribute__ ((__format__ (__printf__, A, B)))
44 | #endif
45 | 
46 | #ifndef	_NVLIST_T_DECLARED
47 | #define	_NVLIST_T_DECLARED
48 | struct nvlist;
49 | 
50 | typedef struct nvlist nvlist_t;
51 | #endif
52 | 
53 | #ifdef __cplusplus
54 | extern "C" {
55 | #endif
56 | /*
57 |  * The dnvlist_get functions returns value associated with the given name.
58 |  * If it returns a pointer, the pointer represents internal buffer and should
59 |  * not be freed by the caller.
60 |  * If no element of the given name and type exists, the function will return
61 |  * provided default value.
62 |  */
63 | 
64 | bool dnvlist_get_bool(const nvlist_t *nvl, const char *name, bool defval);
65 | uint64_t dnvlist_get_number(const nvlist_t *nvl, const char *name, uint64_t defval);
66 | const char *dnvlist_get_string(const nvlist_t *nvl, const char *name, const char *defval);
67 | const nvlist_t *dnvlist_get_nvlist(const nvlist_t *nvl, const char *name, const nvlist_t *defval);
68 | int dnvlist_get_descriptor(const nvlist_t *nvl, const char *name, int defval);
69 | const void *dnvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep, const void *defval, size_t defsize);
70 | 
71 | /*
72 |  * The dnvlist_take functions returns value associated with the given name and
73 |  * remove corresponding nvpair.
74 |  * If it returns a pointer, the caller has to free it.
75 |  * If no element of the given name and type exists, the function will return
76 |  * provided default value.
77 |  */
78 | 
79 | bool dnvlist_take_bool(nvlist_t *nvl, const char *name, bool defval);
80 | uint64_t dnvlist_take_number(nvlist_t *nvl, const char *name, uint64_t defval);
81 | char *dnvlist_take_string(nvlist_t *nvl, const char *name, char *defval);
82 | nvlist_t *dnvlist_take_nvlist(nvlist_t *nvl, const char *name, nvlist_t *defval);
83 | int dnvlist_take_descriptor(nvlist_t *nvl, const char *name, int defval);
84 | void *dnvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep, void *defval, size_t defsize);
85 | 
86 | #ifdef __cplusplus
87 | }
88 | #endif
89 | 
90 | #endif	/* !_DNV_H_ */
91 | 


--------------------------------------------------------------------------------
/third_party/libnv/dnvlist.c:
--------------------------------------------------------------------------------
  1 | /*-
  2 |  * Copyright (c) 2013 The FreeBSD Foundation
  3 |  * All rights reserved.
  4 |  *
  5 |  * This software was developed by Pawel Jakub Dawidek under sponsorship from
  6 |  * the FreeBSD Foundation.
  7 |  *
  8 |  * Redistribution and use in source and binary forms, with or without
  9 |  * modification, are permitted provided that the following conditions
 10 |  * are met:
 11 |  * 1. Redistributions of source code must retain the above copyright
 12 |  *    notice, this list of conditions and the following disclaimer.
 13 |  * 2. Redistributions in binary form must reproduce the above copyright
 14 |  *    notice, this list of conditions and the following disclaimer in the
 15 |  *    documentation and/or other materials provided with the distribution.
 16 |  *
 17 |  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
 18 |  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 19 |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 20 |  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
 21 |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 22 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 23 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 24 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 25 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 26 |  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 27 |  * SUCH DAMAGE.
 28 |  */
 29 | 
 30 | #include 
 31 | 
 32 | #include 
 33 | #include 
 34 | #include 
 35 | #include 
 36 | 
 37 | #include "nv.h"
 38 | #include "nv_impl.h"
 39 | 
 40 | #include "dnv.h"
 41 | 
 42 | #define	DNVLIST_GET(ftype, type)					\
 43 | ftype									\
 44 | dnvlist_get_##type(const nvlist_t *nvl, const char *name, ftype defval)	\
 45 | {									\
 46 | 									\
 47 | 	if (nvlist_exists_##type(nvl, name))				\
 48 | 		return (nvlist_get_##type(nvl, name));			\
 49 | 	else								\
 50 | 		return (defval);					\
 51 | }
 52 | 
 53 | DNVLIST_GET(bool, bool)
 54 | DNVLIST_GET(uint64_t, number)
 55 | DNVLIST_GET(const char *, string)
 56 | DNVLIST_GET(const nvlist_t *, nvlist)
 57 | DNVLIST_GET(int, descriptor)
 58 | 
 59 | #undef	DNVLIST_GET
 60 | 
 61 | const void *
 62 | dnvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep,
 63 |     const void *defval, size_t defsize)
 64 | {
 65 | 	const void *value;
 66 | 
 67 | 	if (nvlist_exists_binary(nvl, name))
 68 | 		value = nvlist_get_binary(nvl, name, sizep);
 69 | 	else {
 70 | 		if (sizep != NULL)
 71 | 			*sizep = defsize;
 72 | 		value = defval;
 73 | 	}
 74 | 	return (value);
 75 | }
 76 | 
 77 | #define	DNVLIST_TAKE(ftype, type)					\
 78 | ftype									\
 79 | dnvlist_take_##type(nvlist_t *nvl, const char *name, ftype defval)	\
 80 | {									\
 81 | 									\
 82 | 	if (nvlist_exists_##type(nvl, name))				\
 83 | 		return (nvlist_take_##type(nvl, name));			\
 84 | 	else								\
 85 | 		return (defval);					\
 86 | }
 87 | 
 88 | DNVLIST_TAKE(bool, bool)
 89 | DNVLIST_TAKE(uint64_t, number)
 90 | DNVLIST_TAKE(char *, string)
 91 | DNVLIST_TAKE(nvlist_t *, nvlist)
 92 | DNVLIST_TAKE(int, descriptor)
 93 | 
 94 | #undef	DNVLIST_TAKE
 95 | 
 96 | void *
 97 | dnvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep,
 98 |     void *defval, size_t defsize)
 99 | {
100 | 	void *value;
101 | 
102 | 	if (nvlist_exists_binary(nvl, name))
103 | 		value = nvlist_take_binary(nvl, name, sizep);
104 | 	else {
105 | 		if (sizep != NULL)
106 | 			*sizep = defsize;
107 | 		value = defval;
108 | 	}
109 | 	return (value);
110 | }
111 | 
112 | 


--------------------------------------------------------------------------------
/third_party/libnv/local.h:
--------------------------------------------------------------------------------
 1 | #ifndef LOCAL_H
 2 | #define LOCAL_H
 3 | /* Copyright 2016 Google Inc. All Rights Reserved.
 4 |  *
 5 |  * Use of this source code is governed by a BSD-style
 6 |  * license that can be found in the LICENSE file in
 7 |  * this directory. */
 8 | 
 9 | #include 
10 | #include 
11 | #include 
12 | 
13 | #include "sys_endian.h"
14 | 
15 | #define HAVE_STRUCT_UCRED 1
16 | 
17 | #ifndef __DECONST
18 | #define __DECONST(type, var)	((type)(uintptr_t)(const void *)(var))
19 | #endif
20 | 
21 | #ifndef __unused
22 | #define __unused	__attribute__ ((unused))
23 | #endif
24 | 
25 | #endif
26 | 


--------------------------------------------------------------------------------
/third_party/libnv/msgio.h:
--------------------------------------------------------------------------------
 1 | /*-
 2 |  * Copyright (c) 2013 The FreeBSD Foundation
 3 |  * All rights reserved.
 4 |  *
 5 |  * This software was developed by Pawel Jakub Dawidek under sponsorship from
 6 |  * the FreeBSD Foundation.
 7 |  *
 8 |  * Copyright (c) 2013 Mariusz Zaborski 
 9 |  *
10 |  * Redistribution and use in source and binary forms, with or without
11 |  * modification, are permitted provided that the following conditions
12 |  * are met:
13 |  * 1. Redistributions of source code must retain the above copyright
14 |  *    notice, this list of conditions and the following disclaimer.
15 |  * 2. Redistributions in binary form must reproduce the above copyright
16 |  *    notice, this list of conditions and the following disclaimer in the
17 |  *    documentation and/or other materials provided with the distribution.
18 |  *
19 |  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
20 |  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 |  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
23 |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 |  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 |  * SUCH DAMAGE.
30 |  *
31 |  * $FreeBSD$
32 |  */
33 | 
34 | #ifndef	_MSGIO_H_
35 | #define	_MSGIO_H_
36 | 
37 | #include 
38 | 
39 | struct iovec;
40 | struct msghdr;
41 | 
42 | #ifdef __cplusplus
43 | extern "C" {
44 | #endif
45 | 
46 | int cred_send(int sock);
47 | int cred_recv(int sock, uid_t *uid, gid_t *gid, int *ngroups, gid_t *groups);
48 | 
49 | int fd_send(int sock, const int *fds, size_t nfds);
50 | int fd_recv(int sock, int *fds, size_t nfds);
51 | 
52 | int buf_send(int sock, void *buf, size_t size);
53 | int buf_recv(int sock, void *buf, size_t size);
54 | 
55 | #ifdef __cplusplus
56 | }
57 | #endif
58 | 
59 | #endif	/* !_MSGIO_H_ */
60 | 


--------------------------------------------------------------------------------
/third_party/libnv/nv.h:
--------------------------------------------------------------------------------
  1 | /*-
  2 |  * Copyright (c) 2009-2013 The FreeBSD Foundation
  3 |  * All rights reserved.
  4 |  *
  5 |  * This software was developed by Pawel Jakub Dawidek under sponsorship from
  6 |  * the FreeBSD Foundation.
  7 |  *
  8 |  * Redistribution and use in source and binary forms, with or without
  9 |  * modification, are permitted provided that the following conditions
 10 |  * are met:
 11 |  * 1. Redistributions of source code must retain the above copyright
 12 |  *    notice, this list of conditions and the following disclaimer.
 13 |  * 2. Redistributions in binary form must reproduce the above copyright
 14 |  *    notice, this list of conditions and the following disclaimer in the
 15 |  *    documentation and/or other materials provided with the distribution.
 16 |  *
 17 |  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
 18 |  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 19 |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 20 |  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
 21 |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 22 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 23 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 24 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 25 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 26 |  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 27 |  * SUCH DAMAGE.
 28 |  *
 29 |  * $FreeBSD$
 30 |  */
 31 | 
 32 | #ifndef	_NV_H_
 33 | #define	_NV_H_
 34 | 
 35 | #include 
 36 | 
 37 | #include 
 38 | #include 
 39 | #include 
 40 | #include 
 41 | 
 42 | #ifndef __printflike
 43 | #define __printflike(A, B)	__attribute__ ((__format__ (__printf__, A, B)))
 44 | #endif
 45 | 
 46 | #ifndef	_NVLIST_T_DECLARED
 47 | #define	_NVLIST_T_DECLARED
 48 | struct nvlist;
 49 | 
 50 | typedef struct nvlist nvlist_t;
 51 | #endif
 52 | 
 53 | #define	NV_NAME_MAX	2048
 54 | 
 55 | #define	NV_TYPE_NONE			0
 56 | 
 57 | #define	NV_TYPE_NULL			1
 58 | #define	NV_TYPE_BOOL			2
 59 | #define	NV_TYPE_NUMBER			3
 60 | #define	NV_TYPE_STRING			4
 61 | #define	NV_TYPE_NVLIST			5
 62 | #define	NV_TYPE_DESCRIPTOR		6
 63 | #define	NV_TYPE_BINARY			7
 64 | #define	NV_TYPE_BOOL_ARRAY		8
 65 | #define	NV_TYPE_NUMBER_ARRAY		9
 66 | #define	NV_TYPE_STRING_ARRAY		10
 67 | #define	NV_TYPE_NVLIST_ARRAY		11
 68 | #define	NV_TYPE_DESCRIPTOR_ARRAY	12
 69 | 
 70 | /*
 71 |  * Perform case-insensitive lookups of provided names.
 72 |  */
 73 | #define	NV_FLAG_IGNORE_CASE		0x01
 74 | /*
 75 |  * Names don't have to be unique.
 76 |  */
 77 | #define	NV_FLAG_NO_UNIQUE		0x02
 78 | 
 79 | #ifdef __cplusplus
 80 | extern "C" {
 81 | #endif
 82 | 
 83 | nvlist_t	*nvlist_create(int flags);
 84 | void		 nvlist_destroy(nvlist_t *nvl);
 85 | int		 nvlist_error(const nvlist_t *nvl);
 86 | bool		 nvlist_empty(const nvlist_t *nvl);
 87 | int		 nvlist_flags(const nvlist_t *nvl);
 88 | void		 nvlist_set_error(nvlist_t *nvl, int error);
 89 | 
 90 | nvlist_t *nvlist_clone(const nvlist_t *nvl);
 91 | 
 92 | void nvlist_dump(const nvlist_t *nvl, int fd);
 93 | void nvlist_fdump(const nvlist_t *nvl, FILE *fp);
 94 | 
 95 | size_t		 nvlist_size(const nvlist_t *nvl);
 96 | void		*nvlist_pack(const nvlist_t *nvl, size_t *sizep);
 97 | nvlist_t	*nvlist_unpack(const void *buf, size_t size, int flags);
 98 | 
 99 | int nvlist_send(int sock, const nvlist_t *nvl);
100 | nvlist_t *nvlist_recv(int sock, int flags);
101 | nvlist_t *nvlist_xfer(int sock, nvlist_t *nvl, int flags);
102 | 
103 | const char *nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep);
104 | 
105 | const nvlist_t *nvlist_get_parent(const nvlist_t *nvl, void **cookiep);
106 | 
107 | const nvlist_t *nvlist_get_array_next(const nvlist_t *nvl);
108 | bool nvlist_in_array(const nvlist_t *nvl);
109 | 
110 | const nvlist_t *nvlist_get_pararr(const nvlist_t *nvl, void **cookiep);
111 | 
112 | /*
113 |  * The nvlist_exists functions check if the given name (optionally of the given
114 |  * type) exists on nvlist.
115 |  */
116 | 
117 | bool nvlist_exists(const nvlist_t *nvl, const char *name);
118 | bool nvlist_exists_type(const nvlist_t *nvl, const char *name, int type);
119 | 
120 | bool nvlist_exists_null(const nvlist_t *nvl, const char *name);
121 | bool nvlist_exists_bool(const nvlist_t *nvl, const char *name);
122 | bool nvlist_exists_number(const nvlist_t *nvl, const char *name);
123 | bool nvlist_exists_string(const nvlist_t *nvl, const char *name);
124 | bool nvlist_exists_nvlist(const nvlist_t *nvl, const char *name);
125 | bool nvlist_exists_binary(const nvlist_t *nvl, const char *name);
126 | bool nvlist_exists_bool_array(const nvlist_t *nvl, const char *name);
127 | bool nvlist_exists_number_array(const nvlist_t *nvl, const char *name);
128 | bool nvlist_exists_string_array(const nvlist_t *nvl, const char *name);
129 | bool nvlist_exists_nvlist_array(const nvlist_t *nvl, const char *name);
130 | bool nvlist_exists_descriptor(const nvlist_t *nvl, const char *name);
131 | bool nvlist_exists_descriptor_array(const nvlist_t *nvl, const char *name);
132 | 
133 | /*
134 |  * The nvlist_add functions add the given name/value pair.
135 |  * If a pointer is provided, nvlist_add will internally allocate memory for the
136 |  * given data (in other words it won't consume provided buffer).
137 |  */
138 | 
139 | void nvlist_add_null(nvlist_t *nvl, const char *name);
140 | void nvlist_add_bool(nvlist_t *nvl, const char *name, bool value);
141 | void nvlist_add_number(nvlist_t *nvl, const char *name, uint64_t value);
142 | void nvlist_add_string(nvlist_t *nvl, const char *name, const char *value);
143 | void nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...) __printflike(3, 4);
144 | void nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt, va_list valueap) __printflike(3, 0);
145 | void nvlist_add_nvlist(nvlist_t *nvl, const char *name, const nvlist_t *value);
146 | void nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value, size_t size);
147 | void nvlist_add_bool_array(nvlist_t *nvl, const char *name, const bool *value, size_t nitems);
148 | void nvlist_add_number_array(nvlist_t *nvl, const char *name, const uint64_t *value, size_t nitems);
149 | void nvlist_add_string_array(nvlist_t *nvl, const char *name, const char * const *value, size_t nitems);
150 | void nvlist_add_nvlist_array(nvlist_t *nvl, const char *name, const nvlist_t * const *value, size_t nitems);
151 | void nvlist_add_descriptor(nvlist_t *nvl, const char *name, int value);
152 | void nvlist_add_descriptor_array(nvlist_t *nvl, const char *name, const int *value, size_t nitems);
153 | 
154 | /*
155 |  * The nvlist_move functions add the given name/value pair.
156 |  * The functions consumes provided buffer.
157 |  */
158 | 
159 | void nvlist_move_string(nvlist_t *nvl, const char *name, char *value);
160 | void nvlist_move_nvlist(nvlist_t *nvl, const char *name, nvlist_t *value);
161 | void nvlist_move_binary(nvlist_t *nvl, const char *name, void *value, size_t size);
162 | void nvlist_move_bool_array(nvlist_t *nvl, const char *name, bool *value, size_t nitems);
163 | void nvlist_move_string_array(nvlist_t *nvl, const char *name, char **value, size_t nitems);
164 | void nvlist_move_nvlist_array(nvlist_t *nvl, const char *name, nvlist_t **value, size_t nitems);
165 | void nvlist_move_number_array(nvlist_t *nvl, const char *name, uint64_t *value, size_t nitems);
166 | void nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value);
167 | void nvlist_move_descriptor_array(nvlist_t *nvl, const char *name, int *value, size_t nitems);
168 | 
169 | /*
170 |  * The nvlist_get functions returns value associated with the given name.
171 |  * If it returns a pointer, the pointer represents internal buffer and should
172 |  * not be freed by the caller.
173 |  */
174 | 
175 | bool		 nvlist_get_bool(const nvlist_t *nvl, const char *name);
176 | uint64_t	 nvlist_get_number(const nvlist_t *nvl, const char *name);
177 | const char	*nvlist_get_string(const nvlist_t *nvl, const char *name);
178 | const nvlist_t	*nvlist_get_nvlist(const nvlist_t *nvl, const char *name);
179 | const void	*nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep);
180 | const bool		*nvlist_get_bool_array(const nvlist_t *nvl, const char *name, size_t *nitemsp);
181 | const uint64_t		*nvlist_get_number_array(const nvlist_t *nvl, const char *name, size_t *nitemsp);
182 | const char * const	*nvlist_get_string_array(const nvlist_t *nvl, const char *name, size_t *nitemsp);
183 | const nvlist_t * const	*nvlist_get_nvlist_array(const nvlist_t *nvl, const char *name, size_t *nitemsp);
184 | int			 nvlist_get_descriptor(const nvlist_t *nvl, const char *name);
185 | const int		*nvlist_get_descriptor_array(const nvlist_t *nvl, const char *name, size_t *nitemsp);
186 | 
187 | /*
188 |  * The nvlist_take functions returns value associated with the given name and
189 |  * remove the given entry from the nvlist.
190 |  * The caller is responsible for freeing received data.
191 |  */
192 | 
193 | bool		 nvlist_take_bool(nvlist_t *nvl, const char *name);
194 | uint64_t	 nvlist_take_number(nvlist_t *nvl, const char *name);
195 | char		*nvlist_take_string(nvlist_t *nvl, const char *name);
196 | nvlist_t	*nvlist_take_nvlist(nvlist_t *nvl, const char *name);
197 | void		*nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep);
198 | bool		 *nvlist_take_bool_array(nvlist_t *nvl, const char *name, size_t *nitemsp);
199 | uint64_t	 *nvlist_take_number_array(nvlist_t *nvl, const char *name, size_t *nitemsp);
200 | char		**nvlist_take_string_array(nvlist_t *nvl, const char *name, size_t *nitemsp);
201 | nvlist_t	**nvlist_take_nvlist_array(nvlist_t *nvl, const char *name, size_t *nitemsp);
202 | int		 nvlist_take_descriptor(nvlist_t *nvl, const char *name);
203 | int		 *nvlist_take_descriptor_array(nvlist_t *nvl, const char *name, size_t *nitemsp);
204 | 
205 | /*
206 |  * The nvlist_free functions removes the given name/value pair from the nvlist
207 |  * and frees memory associated with it.
208 |  */
209 | 
210 | void nvlist_free(nvlist_t *nvl, const char *name);
211 | void nvlist_free_type(nvlist_t *nvl, const char *name, int type);
212 | 
213 | void nvlist_free_null(nvlist_t *nvl, const char *name);
214 | void nvlist_free_bool(nvlist_t *nvl, const char *name);
215 | void nvlist_free_number(nvlist_t *nvl, const char *name);
216 | void nvlist_free_string(nvlist_t *nvl, const char *name);
217 | void nvlist_free_nvlist(nvlist_t *nvl, const char *name);
218 | void nvlist_free_binary(nvlist_t *nvl, const char *name);
219 | void nvlist_free_bool_array(nvlist_t *nvl, const char *name);
220 | void nvlist_free_number_array(nvlist_t *nvl, const char *name);
221 | void nvlist_free_string_array(nvlist_t *nvl, const char *name);
222 | void nvlist_free_nvlist_array(nvlist_t *nvl, const char *name);
223 | void nvlist_free_binary_array(nvlist_t *nvl, const char *name);
224 | void nvlist_free_descriptor(nvlist_t *nvl, const char *name);
225 | void nvlist_free_descriptor_array(nvlist_t *nvl, const char *name);
226 | 
227 | #ifdef __cplusplus
228 | }
229 | #endif
230 | 
231 | #endif	/* !_NV_H_ */
232 | 


--------------------------------------------------------------------------------
/third_party/libnv/nv_impl.h:
--------------------------------------------------------------------------------
  1 | /*-
  2 |  * Copyright (c) 2013 The FreeBSD Foundation
  3 |  * Copyright (c) 2013-2015 Mariusz Zaborski 
  4 |  * All rights reserved.
  5 |  *
  6 |  * This software was developed by Pawel Jakub Dawidek under sponsorship from
  7 |  * the FreeBSD Foundation.
  8 |  *
  9 |  * Redistribution and use in source and binary forms, with or without
 10 |  * modification, are permitted provided that the following conditions
 11 |  * are met:
 12 |  * 1. Redistributions of source code must retain the above copyright
 13 |  *    notice, this list of conditions and the following disclaimer.
 14 |  * 2. Redistributions in binary form must reproduce the above copyright
 15 |  *    notice, this list of conditions and the following disclaimer in the
 16 |  *    documentation and/or other materials provided with the distribution.
 17 |  *
 18 |  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
 19 |  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 20 |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 21 |  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
 22 |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 23 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 24 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 26 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 27 |  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 28 |  * SUCH DAMAGE.
 29 |  *
 30 |  * $FreeBSD$
 31 |  */
 32 | 
 33 | #ifndef	_NV_IMPL_H_
 34 | #define	_NV_IMPL_H_
 35 | 
 36 | #ifndef	_NVPAIR_T_DECLARED
 37 | #define	_NVPAIR_T_DECLARED
 38 | struct nvpair;
 39 | 
 40 | typedef struct nvpair nvpair_t;
 41 | #endif
 42 | 
 43 | #define	NV_TYPE_NVLIST_ARRAY_NEXT	254
 44 | #define	NV_TYPE_NVLIST_UP		255
 45 | 
 46 | #define	NV_TYPE_FIRST		NV_TYPE_NULL
 47 | #define	NV_TYPE_LAST		NV_TYPE_DESCRIPTOR_ARRAY
 48 | 
 49 | #define	NV_FLAG_BIG_ENDIAN		0x080
 50 | #define	NV_FLAG_IN_ARRAY		0x100
 51 | 
 52 | #define	nv_malloc(size)			malloc((size))
 53 | #define	nv_calloc(n, size)		calloc((n), (size))
 54 | #define	nv_realloc(buf, size)		realloc((buf), (size))
 55 | #define	nv_free(buf)			free((buf))
 56 | #define	nv_strdup(buf)			strdup((buf))
 57 | #define	nv_vasprintf(ptr, ...)		vasprintf(ptr, __VA_ARGS__)
 58 | 
 59 | #define	ERRNO_SET(var)			do { errno = (var); } while (0)
 60 | #define	ERRNO_SAVE()			do {				\
 61 | 						int _serrno;		\
 62 | 									\
 63 | 						_serrno = errno
 64 | 
 65 | #define	ERRNO_RESTORE()				errno = _serrno;	\
 66 | 					} while (0)
 67 | 
 68 | #define	ERRNO_OR_DEFAULT(default)	(errno == 0 ? (default) : errno)
 69 | 
 70 | int	*nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp);
 71 | size_t	 nvlist_ndescriptors(const nvlist_t *nvl);
 72 | void	 nvlist_set_flags(nvlist_t *nvl, int flags);
 73 | 
 74 | nvpair_t *nvlist_first_nvpair(const nvlist_t *nvl);
 75 | nvpair_t *nvlist_next_nvpair(const nvlist_t *nvl, const nvpair_t *nvp);
 76 | nvpair_t *nvlist_prev_nvpair(const nvlist_t *nvl, const nvpair_t *nvp);
 77 | 
 78 | void nvlist_add_nvpair(nvlist_t *nvl, const nvpair_t *nvp);
 79 | 
 80 | bool nvlist_move_nvpair(nvlist_t *nvl, nvpair_t *nvp);
 81 | 
 82 | void nvlist_set_parent(nvlist_t *nvl, nvpair_t *parent);
 83 | void nvlist_set_array_next(nvlist_t *nvl, nvpair_t *ele);
 84 | 
 85 | const nvpair_t *nvlist_get_nvpair(const nvlist_t *nvl, const char *name);
 86 | 
 87 | nvpair_t *nvlist_take_nvpair(nvlist_t *nvl, const char *name);
 88 | 
 89 | /* Function removes the given nvpair from the nvlist. */
 90 | void nvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp);
 91 | 
 92 | void nvlist_free_nvpair(nvlist_t *nvl, nvpair_t *nvp);
 93 | 
 94 | int nvpair_type(const nvpair_t *nvp);
 95 | const char *nvpair_name(const nvpair_t *nvp);
 96 | 
 97 | nvpair_t *nvpair_clone(const nvpair_t *nvp);
 98 | 
 99 | nvpair_t *nvpair_create_null(const char *name);
100 | nvpair_t *nvpair_create_bool(const char *name, bool value);
101 | nvpair_t *nvpair_create_number(const char *name, uint64_t value);
102 | nvpair_t *nvpair_create_string(const char *name, const char *value);
103 | nvpair_t *nvpair_create_stringf(const char *name, const char *valuefmt, ...) __printflike(2, 3);
104 | nvpair_t *nvpair_create_stringv(const char *name, const char *valuefmt, va_list valueap) __printflike(2, 0);
105 | nvpair_t *nvpair_create_nvlist(const char *name, const nvlist_t *value);
106 | nvpair_t *nvpair_create_descriptor(const char *name, int value);
107 | nvpair_t *nvpair_create_binary(const char *name, const void *value, size_t size);
108 | nvpair_t *nvpair_create_bool_array(const char *name, const bool *value, size_t nitems);
109 | nvpair_t *nvpair_create_number_array(const char *name, const uint64_t *value, size_t nitems);
110 | nvpair_t *nvpair_create_string_array(const char *name, const char * const *value, size_t nitems);
111 | nvpair_t *nvpair_create_nvlist_array(const char *name, const nvlist_t * const *value, size_t nitems);
112 | nvpair_t *nvpair_create_descriptor_array(const char *name, const int *value, size_t nitems);
113 | 
114 | nvpair_t *nvpair_move_string(const char *name, char *value);
115 | nvpair_t *nvpair_move_nvlist(const char *name, nvlist_t *value);
116 | nvpair_t *nvpair_move_descriptor(const char *name, int value);
117 | nvpair_t *nvpair_move_binary(const char *name, void *value, size_t size);
118 | nvpair_t *nvpair_move_bool_array(const char *name, bool *value, size_t nitems);
119 | nvpair_t *nvpair_move_nvlist_array(const char *name, nvlist_t **value, size_t nitems);
120 | nvpair_t *nvpair_move_descriptor_array(const char *name, int *value, size_t nitems);
121 | nvpair_t *nvpair_move_number_array(const char *name, uint64_t *value, size_t nitems);
122 | nvpair_t *nvpair_move_string_array(const char *name, char **value, size_t nitems);
123 | 
124 | bool		 nvpair_get_bool(const nvpair_t *nvp);
125 | uint64_t	 nvpair_get_number(const nvpair_t *nvp);
126 | const char	*nvpair_get_string(const nvpair_t *nvp);
127 | const nvlist_t	*nvpair_get_nvlist(const nvpair_t *nvp);
128 | int		 nvpair_get_descriptor(const nvpair_t *nvp);
129 | const void	*nvpair_get_binary(const nvpair_t *nvp, size_t *sizep);
130 | const bool		*nvpair_get_bool_array(const nvpair_t *nvp, size_t *nitemsp);
131 | const uint64_t		*nvpair_get_number_array(const nvpair_t *nvp, size_t *nitemsp);
132 | const char * const	*nvpair_get_string_array(const nvpair_t *nvp, size_t *nitemsp);
133 | const nvlist_t * const	*nvpair_get_nvlist_array(const nvpair_t *nvp, size_t *nitemsp);
134 | const int		*nvpair_get_descriptor_array(const nvpair_t *nvp, size_t *nitemsp);
135 | 
136 | void nvpair_free(nvpair_t *nvp);
137 | 
138 | #endif	/* !_NV_IMPL_H_ */
139 | 


--------------------------------------------------------------------------------
/third_party/libnv/nvlist_impl.h:
--------------------------------------------------------------------------------
 1 | /*-
 2 |  * Copyright (c) 2013 The FreeBSD Foundation
 3 |  * Copyright (c) 2013-2015 Mariusz Zaborski 
 4 |  * All rights reserved.
 5 |  *
 6 |  * This software was developed by Pawel Jakub Dawidek under sponsorship from
 7 |  * the FreeBSD Foundation.
 8 |  *
 9 |  * Redistribution and use in source and binary forms, with or without
10 |  * modification, are permitted provided that the following conditions
11 |  * are met:
12 |  * 1. Redistributions of source code must retain the above copyright
13 |  *    notice, this list of conditions and the following disclaimer.
14 |  * 2. Redistributions in binary form must reproduce the above copyright
15 |  *    notice, this list of conditions and the following disclaimer in the
16 |  *    documentation and/or other materials provided with the distribution.
17 |  *
18 |  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
19 |  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 |  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
22 |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 |  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 |  * SUCH DAMAGE.
29 |  *
30 |  * $FreeBSD$
31 |  */
32 | 
33 | #ifndef	_NVLIST_IMPL_H_
34 | #define	_NVLIST_IMPL_H_
35 | 
36 | #include 
37 | 
38 | #include "nv.h"
39 | 
40 | nvpair_t *nvlist_get_nvpair_parent(const nvlist_t *nvl);
41 | const unsigned char *nvlist_unpack_header(nvlist_t *nvl,
42 |     const unsigned char *ptr, size_t nfds, bool *isbep, size_t *leftp);
43 | 
44 | #endif	/* !_NVLIST_IMPL_H_ */
45 | 


--------------------------------------------------------------------------------
/third_party/libnv/nvpair_impl.h:
--------------------------------------------------------------------------------
  1 | /*-
  2 |  * Copyright (c) 2009-2013 The FreeBSD Foundation
  3 |  * Copyright (c) 2013-2015 Mariusz Zaborski 
  4 |  * All rights reserved.
  5 |  *
  6 |  * This software was developed by Pawel Jakub Dawidek under sponsorship from
  7 |  * the FreeBSD Foundation.
  8 |  *
  9 |  * Redistribution and use in source and binary forms, with or without
 10 |  * modification, are permitted provided that the following conditions
 11 |  * are met:
 12 |  * 1. Redistributions of source code must retain the above copyright
 13 |  *    notice, this list of conditions and the following disclaimer.
 14 |  * 2. Redistributions in binary form must reproduce the above copyright
 15 |  *    notice, this list of conditions and the following disclaimer in the
 16 |  *    documentation and/or other materials provided with the distribution.
 17 |  *
 18 |  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
 19 |  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 20 |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 21 |  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
 22 |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 23 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 24 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 26 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 27 |  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 28 |  * SUCH DAMAGE.
 29 |  *
 30 |  * $FreeBSD$
 31 |  */
 32 | 
 33 | #ifndef	_NVPAIR_IMPL_H_
 34 | #define	_NVPAIR_IMPL_H_
 35 | 
 36 | #include "nv.h"
 37 | #include 
 38 | 
 39 | #include 
 40 | 
 41 | TAILQ_HEAD(nvl_head, nvpair);
 42 | 
 43 | void nvpair_assert(const nvpair_t *nvp);
 44 | nvlist_t *nvpair_nvlist(const nvpair_t *nvp);
 45 | nvpair_t *nvpair_next(const nvpair_t *nvp);
 46 | nvpair_t *nvpair_prev(const nvpair_t *nvp);
 47 | void nvpair_insert(struct nvl_head *head, nvpair_t *nvp, nvlist_t *nvl);
 48 | void nvpair_remove(struct nvl_head *head, nvpair_t *nvp, const nvlist_t *nvl);
 49 | size_t nvpair_header_size(void);
 50 | size_t nvpair_size(const nvpair_t *nvp);
 51 | const unsigned char *nvpair_unpack(bool isbe, const unsigned char *ptr,
 52 |     size_t *leftp, nvpair_t **nvpp);
 53 | void nvpair_free_structure(nvpair_t *nvp);
 54 | void nvpair_init_datasize(nvpair_t *nvp);
 55 | const char *nvpair_type_string(int type);
 56 | 
 57 | /* Pack functions. */
 58 | unsigned char *nvpair_pack_header(const nvpair_t *nvp, unsigned char *ptr,
 59 |     size_t *leftp);
 60 | unsigned char *nvpair_pack_null(const nvpair_t *nvp, unsigned char *ptr,
 61 |     size_t *leftp);
 62 | unsigned char *nvpair_pack_bool(const nvpair_t *nvp, unsigned char *ptr,
 63 |     size_t *leftp);
 64 | unsigned char *nvpair_pack_number(const nvpair_t *nvp, unsigned char *ptr,
 65 |     size_t *leftp);
 66 | unsigned char *nvpair_pack_string(const nvpair_t *nvp, unsigned char *ptr,
 67 |     size_t *leftp);
 68 | unsigned char *nvpair_pack_descriptor(const nvpair_t *nvp, unsigned char *ptr,
 69 |     int64_t *fdidxp, size_t *leftp);
 70 | unsigned char *nvpair_pack_binary(const nvpair_t *nvp, unsigned char *ptr,
 71 |     size_t *leftp);
 72 | unsigned char *nvpair_pack_nvlist_up(unsigned char *ptr, size_t *leftp);
 73 | unsigned char *nvpair_pack_bool_array(const nvpair_t *nvp, unsigned char *ptr,
 74 |     size_t *leftp);
 75 | unsigned char *nvpair_pack_number_array(const nvpair_t *nvp, unsigned char *ptr,
 76 |     size_t *leftp);
 77 | unsigned char *nvpair_pack_string_array(const nvpair_t *nvp, unsigned char *ptr,
 78 |     size_t *leftp);
 79 | unsigned char *nvpair_pack_descriptor_array(const nvpair_t *nvp,
 80 |     unsigned char *ptr, int64_t *fdidxp, size_t *leftp);
 81 | unsigned char *nvpair_pack_nvlist_array_next(unsigned char *ptr, size_t *leftp);
 82 | 
 83 | /* Unpack data functions. */
 84 | const unsigned char *nvpair_unpack_header(bool isbe, nvpair_t *nvp,
 85 |     const unsigned char *ptr, size_t *leftp);
 86 | const unsigned char *nvpair_unpack_null(bool isbe, nvpair_t *nvp,
 87 |     const unsigned char *ptr, size_t *leftp);
 88 | const unsigned char *nvpair_unpack_bool(bool isbe, nvpair_t *nvp,
 89 |     const unsigned char *ptr, size_t *leftp);
 90 | const unsigned char *nvpair_unpack_number(bool isbe, nvpair_t *nvp,
 91 |     const unsigned char *ptr, size_t *leftp);
 92 | const unsigned char *nvpair_unpack_string(bool isbe, nvpair_t *nvp,
 93 |     const unsigned char *ptr, size_t *leftp);
 94 | const unsigned char *nvpair_unpack_nvlist(bool isbe, nvpair_t *nvp,
 95 |     const unsigned char *ptr, size_t *leftp, size_t nfds, nvlist_t **child);
 96 | const unsigned char *nvpair_unpack_descriptor(bool isbe, nvpair_t *nvp,
 97 |     const unsigned char *ptr, size_t *leftp, const int *fds, size_t nfds);
 98 | const unsigned char *nvpair_unpack_binary(bool isbe, nvpair_t *nvp,
 99 |     const unsigned char *ptr, size_t *leftp);
100 | const unsigned char *nvpair_unpack_bool_array(bool isbe, nvpair_t *nvp,
101 |     const unsigned char *ptr, size_t *leftp);
102 | const unsigned char *nvpair_unpack_number_array(bool isbe, nvpair_t *nvp,
103 |     const unsigned char *ptr, size_t *leftp);
104 | const unsigned char *nvpair_unpack_string_array(bool isbe, nvpair_t *nvp,
105 |     const unsigned char *ptr, size_t *leftp);
106 | const unsigned char *nvpair_unpack_descriptor_array(bool isbe, nvpair_t *nvp,
107 |     const unsigned char *ptr, size_t *leftp, const int *fds, size_t nfds);
108 | const unsigned char *nvpair_unpack_nvlist_array(bool isbe, nvpair_t *nvp,
109 |     const unsigned char *ptr, size_t *leftp, nvlist_t **firstel);
110 | 
111 | #endif	/* !_NVPAIR_IMPL_H_ */
112 | 


--------------------------------------------------------------------------------
/third_party/libnv/sys_endian.h:
--------------------------------------------------------------------------------
  1 | #ifndef LIBBSD_SYS_ENDIAN_H
  2 | #define LIBBSD_SYS_ENDIAN_H
  3 | 
  4 | /*
  5 |  * Copyright © 2002 Thomas Moestl 
  6 |  * All rights reserved.
  7 |  *
  8 |  * Redistribution and use in source and binary forms, with or without
  9 |  * modification, are permitted provided that the following conditions
 10 |  * are met:
 11 |  * 1. Redistributions of source code must retain the above copyright
 12 |  *    notice, this list of conditions and the following disclaimer.
 13 |  * 2. Redistributions in binary form must reproduce the above copyright
 14 |  *    notice, this list of conditions and the following disclaimer in the
 15 |  *    documentation and/or other materials provided with the distribution.
 16 |  *
 17 |  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 18 |  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 19 |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 20 |  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 21 |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 22 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 23 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 24 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 25 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 26 |  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 27 |  * SUCH DAMAGE.
 28 |  */
 29 | 
 30 | #include 
 31 | #include 
 32 | 
 33 | /* Alignment-agnostic encode/decode bytestream to/from little/big endian. */
 34 | 
 35 | static __inline uint16_t
 36 | be16dec(const void *pp)
 37 | {
 38 | 	uint8_t const *p = (uint8_t const *)pp;
 39 | 
 40 | 	return ((p[0] << 8) | p[1]);
 41 | }
 42 | 
 43 | static __inline uint32_t
 44 | be32dec(const void *pp)
 45 | {
 46 | 	uint8_t const *p = (uint8_t const *)pp;
 47 | 
 48 | 	return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
 49 | }
 50 | 
 51 | static __inline uint64_t
 52 | be64dec(const void *pp)
 53 | {
 54 | 	uint8_t const *p = (uint8_t const *)pp;
 55 | 
 56 | 	return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4));
 57 | }
 58 | 
 59 | static __inline uint16_t
 60 | le16dec(const void *pp)
 61 | {
 62 | 	uint8_t const *p = (uint8_t const *)pp;
 63 | 
 64 | 	return ((p[1] << 8) | p[0]);
 65 | }
 66 | 
 67 | static __inline uint32_t
 68 | le32dec(const void *pp)
 69 | {
 70 | 	uint8_t const *p = (uint8_t const *)pp;
 71 | 
 72 | 	return (((unsigned)p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
 73 | }
 74 | 
 75 | static __inline uint64_t
 76 | le64dec(const void *pp)
 77 | {
 78 | 	uint8_t const *p = (uint8_t const *)pp;
 79 | 
 80 | 	return (((uint64_t)le32dec(p + 4) << 32) | le32dec(p));
 81 | }
 82 | 
 83 | static __inline void
 84 | be16enc(void *pp, uint16_t u)
 85 | {
 86 | 	uint8_t *p = (uint8_t *)pp;
 87 | 
 88 | 	p[0] = (u >> 8) & 0xff;
 89 | 	p[1] = u & 0xff;
 90 | }
 91 | 
 92 | static __inline void
 93 | be32enc(void *pp, uint32_t u)
 94 | {
 95 | 	uint8_t *p = (uint8_t *)pp;
 96 | 
 97 | 	p[0] = (u >> 24) & 0xff;
 98 | 	p[1] = (u >> 16) & 0xff;
 99 | 	p[2] = (u >> 8) & 0xff;
100 | 	p[3] = u & 0xff;
101 | }
102 | 
103 | static __inline void
104 | be64enc(void *pp, uint64_t u)
105 | {
106 | 	uint8_t *p = (uint8_t *)pp;
107 | 
108 | 	be32enc(p, (uint32_t)(u >> 32));
109 | 	be32enc(p + 4, (uint32_t)(u & 0xffffffffU));
110 | }
111 | 
112 | static __inline void
113 | le16enc(void *pp, uint16_t u)
114 | {
115 | 	uint8_t *p = (uint8_t *)pp;
116 | 
117 | 	p[0] = u & 0xff;
118 | 	p[1] = (u >> 8) & 0xff;
119 | }
120 | 
121 | static __inline void
122 | le32enc(void *pp, uint32_t u)
123 | {
124 | 	uint8_t *p = (uint8_t *)pp;
125 | 
126 | 	p[0] = u & 0xff;
127 | 	p[1] = (u >> 8) & 0xff;
128 | 	p[2] = (u >> 16) & 0xff;
129 | 	p[3] = (u >> 24) & 0xff;
130 | }
131 | 
132 | static __inline void
133 | le64enc(void *pp, uint64_t u)
134 | {
135 | 	uint8_t *p = (uint8_t *)pp;
136 | 
137 | 	le32enc(p, (uint32_t)(u & 0xffffffffU));
138 | 	le32enc(p + 4, (uint32_t)(u >> 32));
139 | }
140 | 
141 | #endif
142 | 
143 | 


--------------------------------------------------------------------------------
/unzcrash.c:
--------------------------------------------------------------------------------
  1 | 
  2 | /* A test program written to test robustness to decompression of
  3 |    corrupted data.  Usage is 
  4 |        unzcrash filename
  5 |    and the program will read the specified file, compress it (in memory),
  6 |    and then repeatedly decompress it, each time with a different bit of
  7 |    the compressed data inverted, so as to test all possible one-bit errors.
  8 |    This should not cause any invalid memory accesses.  If it does, 
  9 |    I want to know about it!
 10 | 
 11 |    PS.  As you can see from the above description, the process is
 12 |    incredibly slow.  A file of size eg 5KB will cause it to run for
 13 |    many hours.
 14 | */
 15 | 
 16 | /* ------------------------------------------------------------------
 17 |    This file is part of bzip2/libbzip2, a program and library for
 18 |    lossless, block-sorting data compression.
 19 | 
 20 |    bzip2/libbzip2 version 1.0.6 of 6 September 2010
 21 |    Copyright (C) 1996-2010 Julian Seward 
 22 | 
 23 |    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
 24 |    README file.
 25 | 
 26 |    This program is released under the terms of the license contained
 27 |    in the file LICENSE.
 28 |    ------------------------------------------------------------------ */
 29 | 
 30 | 
 31 | #include 
 32 | #include 
 33 | #include "bzlib.h"
 34 | 
 35 | #define M_BLOCK 1000000
 36 | 
 37 | typedef unsigned char uchar;
 38 | 
 39 | #define M_BLOCK_OUT (M_BLOCK + 1000000)
 40 | uchar inbuf[M_BLOCK];
 41 | uchar outbuf[M_BLOCK_OUT];
 42 | uchar zbuf[M_BLOCK + 600 + (M_BLOCK / 100)];
 43 | 
 44 | int nIn, nOut, nZ;
 45 | 
 46 | static char *bzerrorstrings[] = {
 47 |        "OK"
 48 |       ,"SEQUENCE_ERROR"
 49 |       ,"PARAM_ERROR"
 50 |       ,"MEM_ERROR"
 51 |       ,"DATA_ERROR"
 52 |       ,"DATA_ERROR_MAGIC"
 53 |       ,"IO_ERROR"
 54 |       ,"UNEXPECTED_EOF"
 55 |       ,"OUTBUFF_FULL"
 56 |       ,"???"   /* for future */
 57 |       ,"???"   /* for future */
 58 |       ,"???"   /* for future */
 59 |       ,"???"   /* for future */
 60 |       ,"???"   /* for future */
 61 |       ,"???"   /* for future */
 62 | };
 63 | 
 64 | void flip_bit ( int bit )
 65 | {
 66 |    int byteno = bit / 8;
 67 |    int bitno  = bit % 8;
 68 |    uchar mask = 1 << bitno;
 69 |    //fprintf ( stderr, "(byte %d  bit %d  mask %d)",
 70 |    //          byteno, bitno, (int)mask );
 71 |    zbuf[byteno] ^= mask;
 72 | }
 73 | 
 74 | int main ( int argc, char** argv )
 75 | {
 76 |    FILE* f;
 77 |    int   r;
 78 |    int   bit;
 79 |    int   i;
 80 | 
 81 |    if (argc != 2) {
 82 |       fprintf ( stderr, "usage: unzcrash filename\n" );
 83 |       return 1;
 84 |    }
 85 | 
 86 |    f = fopen ( argv[1], "r" );
 87 |    if (!f) {
 88 |       fprintf ( stderr, "unzcrash: can't open %s\n", argv[1] );
 89 |       return 1;
 90 |    }
 91 | 
 92 |    nIn = fread ( inbuf, 1, M_BLOCK, f );
 93 |    fprintf ( stderr, "%d bytes read\n", nIn );
 94 | 
 95 |    nZ = M_BLOCK;
 96 |    r = BZ2_bzBuffToBuffCompress (
 97 |          zbuf, &nZ, inbuf, nIn, 9, 0, 30 );
 98 | 
 99 |    assert (r == BZ_OK);
100 |    fprintf ( stderr, "%d after compression\n", nZ );
101 | 
102 |    for (bit = 0; bit < nZ*8; bit++) {
103 |       fprintf ( stderr, "bit %d  ", bit );
104 |       flip_bit ( bit );
105 |       nOut = M_BLOCK_OUT;
106 |       r = BZ2_bzBuffToBuffDecompress (
107 |             outbuf, &nOut, zbuf, nZ, 0, 0 );
108 |       fprintf ( stderr, " %d  %s ", r, bzerrorstrings[-r] );
109 | 
110 |       if (r != BZ_OK) {
111 |          fprintf ( stderr, "\n" );
112 |       } else {
113 |          if (nOut != nIn) {
114 |            fprintf(stderr, "nIn/nOut mismatch %d %d\n", nIn, nOut );
115 |            return 1;
116 |          } else {
117 |            for (i = 0; i < nOut; i++)
118 |              if (inbuf[i] != outbuf[i]) { 
119 |                 fprintf(stderr, "mismatch at %d\n", i ); 
120 |                 return 1; 
121 |            }
122 |            if (i == nOut) fprintf(stderr, "really ok!\n" );
123 |          }
124 |       }
125 | 
126 |       flip_bit ( bit );
127 |    }
128 | 
129 | #if 0
130 |    assert (nOut == nIn);
131 |    for (i = 0; i < nOut; i++) {
132 |      if (inbuf[i] != outbuf[i]) {
133 |         fprintf ( stderr, "difference at %d !\n", i );
134 |         return 1;
135 |      }
136 |    }
137 | #endif
138 | 
139 |    fprintf ( stderr, "all ok\n" );
140 |    return 0;
141 | }
142 | 


--------------------------------------------------------------------------------
/words0:
--------------------------------------------------------------------------------
 1 | 
 2 | If compilation produces errors, or a large number of warnings,
 3 | please read README.COMPILATION.PROBLEMS -- you might be able to
 4 | adjust the flags in this Makefile to improve matters.
 5 | 
 6 | Also in README.COMPILATION.PROBLEMS are some hints that may help
 7 | if your build produces an executable which is unable to correctly
 8 | handle so-called 'large files' -- files of size 2GB or more.
 9 | 
10 | 


--------------------------------------------------------------------------------
/words1:
--------------------------------------------------------------------------------
1 | 
2 | Doing 6 tests (3 compress, 3 uncompress) ...
3 | If there's a problem, things might stop at this point.
4 |  
5 | 


--------------------------------------------------------------------------------
/words2:
--------------------------------------------------------------------------------
1 | 
2 | Checking test results.  If any of the four "cmp"s which follow
3 | report any differences, something is wrong.  If you can't easily
4 | figure out what, please let me know (jseward@bzip.org).
5 | 
6 | 


--------------------------------------------------------------------------------
/words3:
--------------------------------------------------------------------------------
 1 | 
 2 | If you got this far and the 'cmp's didn't complain, it looks
 3 | like you're in business.  
 4 | 
 5 | To install in /usr/local/bin, /usr/local/lib, /usr/local/man and 
 6 | /usr/local/include, type
 7 | 
 8 |    make install
 9 | 
10 | To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type 
11 | 
12 |    make install PREFIX=/xxx/yyy
13 | 
14 | If you are (justifiably) paranoid and want to see what 'make install'
15 | is going to do, you can first do
16 | 
17 |    make -n install                      or
18 |    make -n install PREFIX=/xxx/yyy      respectively.
19 | 
20 | The -n instructs make to show the commands it would execute, but
21 | not actually execute them.
22 | 
23 | Instructions for use are in the preformatted manual page, in the file
24 | bzip2.txt.  For more detailed documentation, read the full manual.  
25 | It is available in Postscript form (manual.ps), PDF form (manual.pdf),
26 | and HTML form (manual.html).
27 | 
28 | You can also do "bzip2 --help" to see some helpful information. 
29 | "bzip2 -L" displays the software license.
30 | 
31 | 


--------------------------------------------------------------------------------
/xmlproc.sh:
--------------------------------------------------------------------------------
  1 | #!/bin/bash
  2 | # see the README file for usage etc.
  3 | #
  4 | # ------------------------------------------------------------------
  5 | #  This file is part of bzip2/libbzip2, a program and library for
  6 | #  lossless, block-sorting data compression.
  7 | #
  8 | #  bzip2/libbzip2 version 1.0.6 of 6 September 2010
  9 | #  Copyright (C) 1996-2010 Julian Seward 
 10 | #
 11 | #  Please read the WARNING, DISCLAIMER and PATENTS sections in the 
 12 | #  README file.
 13 | #
 14 | #  This program is released under the terms of the license contained
 15 | #  in the file LICENSE.
 16 | # ----------------------------------------------------------------
 17 | 
 18 | 
 19 | usage() {
 20 |   echo '';
 21 |   echo 'Usage: xmlproc.sh -[option] ';
 22 |   echo 'Specify a target from:';
 23 |   echo '-v      verify xml file conforms to dtd';
 24 |   echo '-html   output in html format (single file)';
 25 |   echo '-ps     output in postscript format';
 26 |   echo '-pdf    output in pdf format';
 27 |   exit;
 28 | }
 29 | 
 30 | if test $# -ne 2; then
 31 |   usage
 32 | fi
 33 | # assign the variable for the output type
 34 | action=$1; shift
 35 | # assign the output filename
 36 | xmlfile=$1; shift
 37 | # and check user input it correct
 38 | if !(test -f $xmlfile); then
 39 |   echo "No such file: $xmlfile";
 40 |   exit;
 41 | fi
 42 | # some other stuff we will use
 43 | OUT=output
 44 | xsl_fo=bz-fo.xsl
 45 | xsl_html=bz-html.xsl
 46 | 
 47 | basename=$xmlfile
 48 | basename=${basename//'.xml'/''}
 49 | 
 50 | fofile="${basename}.fo"
 51 | htmlfile="${basename}.html"
 52 | pdffile="${basename}.pdf"
 53 | psfile="${basename}.ps"
 54 | xmlfmtfile="${basename}.fmt"
 55 | 
 56 | # first process the xmlfile with CDATA tags
 57 | ./format.pl $xmlfile $xmlfmtfile
 58 | # so the shell knows where the catalogs live
 59 | export XML_CATALOG_FILES=/etc/xml/catalog
 60 | 
 61 | # post-processing tidy up
 62 | cleanup() {
 63 |   echo "Cleaning up: $@" 
 64 |   while [ $# != 0 ]
 65 |   do
 66 |     arg=$1; shift;
 67 |     echo "  deleting $arg";
 68 |     rm $arg
 69 |   done
 70 | }
 71 | 
 72 | case $action in
 73 |   -v)
 74 |    flags='--noout --xinclude --noblanks --postvalid'
 75 |    dtd='--dtdvalid http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd'
 76 |    xmllint $flags $dtd $xmlfmtfile 2> $OUT 
 77 |    egrep 'error' $OUT 
 78 |    rm $OUT
 79 |   ;;
 80 | 
 81 |   -html)
 82 |    echo "Creating $htmlfile ..."
 83 |    xsltproc --nonet --xinclude  -o $htmlfile $xsl_html $xmlfmtfile
 84 |    cleanup $xmlfmtfile
 85 |   ;;
 86 | 
 87 |   -pdf)
 88 |    echo "Creating $pdffile ..."
 89 |    xsltproc --nonet --xinclude -o $fofile $xsl_fo $xmlfmtfile
 90 |    pdfxmltex $fofile >$OUT $OUT $OUT $OUT $OUT $OUT $OUT $OUT $OUT