33 (
void)deflateEnd(&strm);
36 flush = feof(
source) ? Z_FINISH : Z_NO_FLUSH;
42 strm.avail_out =
CHUNK;
44 ret = deflate(&strm, flush);
46 have =
CHUNK - strm.avail_out;
47 if (fwrite(
out, 1, have,
dest) != have || ferror(
dest)) {
48 (
void)deflateEnd(&strm);
51 }
while (strm.avail_out == 0);
52 assert(strm.avail_in == 0);
55 }
while (flush != Z_FINISH);
59 (
void)deflateEnd(&strm);
81 strm.next_in = Z_NULL;
83 ret = inflateInit2(&strm, (16 + MAX_WBITS));
91 (
void)inflateEnd(&strm);
94 if (strm.avail_in == 0)
100 strm.avail_out =
CHUNK;
102 ret = inflate(&strm, Z_NO_FLUSH);
110 (
void)inflateEnd(&strm);
113 have =
CHUNK - strm.avail_out;
114 if (fwrite(
out, 1, have,
dest) != have || ferror(
dest)) {
115 (
void)inflateEnd(&strm);
118 }
while (strm.avail_out == 0);
121 }
while (
ret != Z_STREAM_END);
124 (
void)inflateEnd(&strm);
125 return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
134 fputs(
"error reading stdin\n",
stderr);
136 fputs(
"error writing stdout\n",
stderr);
139 fputs(
"invalid compression level\n",
stderr);
142 fputs(
"invalid or incomplete deflate data\n",
stderr);
145 fputs(
"out of memory\n",
stderr);
147 case Z_VERSION_ERROR:
148 fputs(
"zlib version mismatch!\n",
stderr);
157 const char *tmpdir = std::getenv(
"TMPDIR");
158 if (tmpdir && (strlen(tmpdir) > 50)) {
159 setenv(
"TMPDIR",
"/tmp",
true);
165 FILE *
in = fopen(
infile.c_str(),
"r");
189 while (*p < '0' || *p >
'7') {
193 while (*
p >=
'0' && *p <= '7' && n > 0) {
205 for (
n = 511;
n >= 0; --
n)
257 for (
n = 0;
n < 512; ++
n) {
258 if (n < 148 || n > 155)
260 u += ((
unsigned char *)
p)[
n];
269 bool longpathname =
false;
270 bool longlinkname =
false;
271 char newlongpathname[512];
272 char newlonglinkname[512];
278 printf(
"Extracting from %s\n",
path);
280 bytes_read = fread(buff, 1, 512,
a);
281 if (bytes_read < 512) {
282 fprintf(
stderr,
"Short read on %s: expected 512, got %d\n",
path, (
int)bytes_read);
286 printf(
"End of %s\n",
path);
290 fprintf(
stderr,
"Checksum failure\n");
293 filesize =
parseoct(buff + 124, 12);
297 printf(
" Ignoring hardlink %s\n", buff);
300 if (longpathname && longlinkname) {
301 longlinkname =
false;
302 longpathname =
false;
303 printf(
" Extracting symlink %s\n", newlongpathname);
304 symlink(newlonglinkname, newlongpathname);
305 }
else if (longpathname) {
306 longpathname =
false;
307 printf(
" Extracting symlink %s\n", newlongpathname);
308 symlink(buff + 157, newlongpathname);
309 }
else if (longlinkname) {
310 longlinkname =
false;
311 printf(
" Extracting symlink %s\n", buff);
312 symlink(newlonglinkname, buff);
314 printf(
" Extracting symlink %s\n", buff);
315 symlink(buff + 157, buff);
319 printf(
" Ignoring character device %s\n", buff);
322 printf(
" Ignoring block device %s\n", buff);
326 int endposition = -1;
327 for (
int k = 99;
k >= 0;
k--) {
331 if (endposition == -1) {
334 for (
int k = 0;
k < 100;
k++) {
335 newlongpathname[
k] = buff[
k];
337 newlongpathname[100] =
'\0';
343 printf(
" Extracting dir %s\n", newlongpathname);
345 longpathname =
false;
347 printf(
" Extracting dir %s\n", buff);
355 printf(
" Ignoring FIFO %s\n", buff);
387 int endposition = -1;
388 for (
int k = 99;
k >= 0;
k--) {
392 if (endposition == -1) {
395 for (
int k = 0;
k < 100;
k++) {
396 newlongpathname[
k] = buff[
k];
398 newlongpathname[100] =
'\0';
403 printf(
" Extracting file %s\n", newlongpathname);
405 longpathname =
false;
407 printf(
" Extracting file %s\n", buff);
413 if (longlinkname || longpathname) {
414 if (buff[156] ==
'K') {
415 for (
int ll = 0; ll < 512; ll++) {
416 printf(
"%c", buff[ll]);
419 bytes_read = fread(buff, 1, 512,
a);
420 for (
int ll = 0; ll < 512; ll++) {
421 printf(
"%c", buff[ll]);
424 for (
int k = 0;
k < filesize;
k++) {
425 newlonglinkname[
k] = buff[
k];
427 newlonglinkname[filesize] =
'\0';
428 for (
int k = filesize + 1;
k < 512;
k++) {
429 newlonglinkname[
k] =
'0';
432 }
else if (buff[156] ==
'L') {
433 bytes_read = fread(buff, 1, 512,
a);
434 for (
int k = 0;
k < filesize;
k++) {
435 newlongpathname[
k] = buff[
k];
437 newlongpathname[filesize] =
'\0';
438 for (
int k = filesize + 1;
k < 512;
k++) {
439 newlongpathname[
k] =
'0';
459 if (!longpathname && !longlinkname) {
460 while (filesize > 0) {
461 bytes_read = fread(buff, 1, 512,
a);
462 if (bytes_read < 512) {
463 fprintf(
stderr,
"Short read on %s: Expected 512, got %d\n",
path, (
int)bytes_read);
467 bytes_read = filesize;
469 if (fwrite(buff, 1, bytes_read,
f) != bytes_read) {
470 fprintf(
stderr,
"Failed write\n");
475 filesize -= bytes_read;
495 MD5_Update(&md5,
buffer, nb_read);
498 unsigned char tmp[MD5_DIGEST_LENGTH];
499 MD5_Final(
tmp, &md5);
502 for (
int k = 0;
k < MD5_DIGEST_LENGTH; ++
k) {