26 ret = deflateInit(&strm, level);
32 strm.avail_in = fread(in, 1,
CHUNK, source);
34 (void)deflateEnd(&strm);
37 flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
43 strm.avail_out =
CHUNK;
45 ret = deflate(&strm, flush);
46 assert(ret != Z_STREAM_ERROR);
47 have =
CHUNK - strm.avail_out;
48 if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
49 (void)deflateEnd(&strm);
52 }
while (strm.avail_out == 0);
53 assert(strm.avail_in == 0);
56 }
while (flush != Z_FINISH);
57 assert(ret == Z_STREAM_END);
60 (void)deflateEnd(&strm);
83 strm.next_in = Z_NULL;
85 ret = inflateInit2(&strm, (16+MAX_WBITS));
91 strm.avail_in = fread(in, 1,
CHUNK, source);
93 (void)inflateEnd(&strm);
96 if (strm.avail_in == 0)
102 strm.avail_out =
CHUNK;
104 ret = inflate(&strm, Z_NO_FLUSH);
105 assert(ret != Z_STREAM_ERROR);
111 (void)inflateEnd(&strm);
114 have =
CHUNK - strm.avail_out;
115 if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
116 (void)inflateEnd(&strm);
119 }
while (strm.avail_out == 0);
122 }
while (ret != Z_STREAM_END);
125 (void)inflateEnd(&strm);
126 return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
132 fputs(
"zpipe: ", stderr);
136 fputs(
"error reading stdin\n", stderr);
138 fputs(
"error writing stdout\n", stderr);
141 fputs(
"invalid compression level\n", stderr);
144 fputs(
"invalid or incomplete deflate data\n", stderr);
147 fputs(
"out of memory\n", stderr);
149 case Z_VERSION_ERROR:
150 fputs(
"zlib version mismatch!\n", stderr);
157 const char *tmpdir = getenv(
"TMPDIR");
160 if (tmpdir && (strlen(tmpdir) > 50)) {
161 setenv(
"TMPDIR",
"/tmp",
true);
168 FILE *
in = fopen(infile.c_str(),
"r");
170 FILE *
out = fopen(outfile.c_str(),
"w");
192 while (*p < '0' || *p >
'7') {
196 while (*p >=
'0' && *p <= '7' && n > 0) {
208 for (n = 511; n >= 0; --
n)
220 if (pathname[strlen(pathname) - 1] ==
'/')
221 pathname[strlen(pathname) - 1] =
'\0';
224 r = mkdir(pathname, mode);
228 p = strrchr(pathname,
'/');
233 r = mkdir(pathname, mode);
237 fprintf(stderr,
"Could not create directory %s\n", pathname);
243 f = fopen(pathname,
"w+");
246 char *
p = strrchr(pathname,
'/');
251 f = fopen(pathname,
"w+");
260 for (n = 0; n < 512; ++
n) {
261 if (n < 148 || n > 155)
263 u += ((
unsigned char *)p)[
n];
273 bool longpathname=
false;
274 bool longlinkname=
false;
275 char newlongpathname[512];
276 char newlonglinkname[512];
282 printf(
"Extracting from %s\n", path);
285 bytes_read = fread(buff, 1, 512, a);
286 if (bytes_read < 512) {
288 "Short read on %s: expected 512, got %d\n",path, (
int)bytes_read);
292 printf(
"End of %s\n", path);
296 fprintf(stderr,
"Checksum failure\n");
299 filesize =
parseoct(buff + 124, 12);
303 printf(
" Ignoring hardlink %s\n", buff);
306 if (longpathname && longlinkname){
309 printf(
" Extracting symlink %s\n", newlongpathname);
310 symlink(newlonglinkname,newlongpathname);
311 }
else if (longpathname) {
313 printf(
" Extracting symlink %s\n", newlongpathname);
314 symlink(buff+157,newlongpathname);
315 }
else if (longlinkname) {
317 printf(
" Extracting symlink %s\n", buff);
318 symlink(newlonglinkname,buff);
320 printf(
" Extracting symlink %s\n", buff);
321 symlink(buff+157,buff);
325 printf(
" Ignoring character device %s\n", buff);
328 printf(
" Ignoring block device %s\n", buff);
333 for (
int k=99;
k>=0;
k--){
334 if (buff[
k]==
'\0') endposition=
k;
336 if (endposition==-1) {
339 for (
int k=0;
k<100;
k++){
340 newlongpathname[
k]=buff[
k];
342 newlongpathname[100]=
'\0';
348 printf(
" Extracting dir %s\n", newlongpathname);
353 printf(
" Extracting dir %s\n", buff);
361 printf(
" Ignoring FIFO %s\n", buff);
394 for (
int k=99;
k>=0;
k--){
395 if (buff[
k]==
'\0') endposition=
k;
397 if (endposition==-1) {
400 for (
int k=0;
k<100;
k++){
401 newlongpathname[
k]=buff[
k];
403 newlongpathname[100]=
'\0';
408 printf(
" Extracting file %s\n", newlongpathname);
413 printf(
" Extracting file %s\n", buff);
419 if (longlinkname || longpathname) {
422 for (
int ll=0; ll<512; ll++){ printf(
"%c",buff[ll]);} printf(
"\n");
423 bytes_read = fread(buff, 1, 512, a);
424 for (
int ll=0; ll<512; ll++){ printf(
"%c",buff[ll]);} printf(
"\n");
425 for (
int k=0;
k<filesize;
k++){
426 newlonglinkname[
k]=buff[
k];
428 newlonglinkname[filesize]=
'\0';
429 for (
int k=filesize+1;
k<512;
k++){
430 newlonglinkname[
k]=
'0';
433 }
else if (buff[156]==
'L'){
434 bytes_read = fread(buff, 1, 512, a);
435 for (
int k=0;
k<filesize;
k++){
436 newlongpathname[
k]=buff[
k];
438 newlongpathname[filesize]=
'\0';
439 for (
int k=filesize+1;
k<512;
k++){
440 newlongpathname[
k]=
'0';
460 if (!longpathname && !longlinkname) {
461 while (filesize > 0) {
462 bytes_read = fread(buff, 1, 512, a);
463 if (bytes_read < 512) {
465 "Short read on %s: Expected 512, got %d\n", path, (
int)bytes_read);
469 bytes_read = filesize;
471 if (fwrite(buff, 1, bytes_read, f)
474 fprintf(stderr,
"Failed write\n");
479 filesize -= bytes_read;
498 int fd = open(filename.c_str(), O_RDONLY);
500 while ((nb_read =
read(fd, buffer, 4096 - 1)))
502 MD5_Update(&md5, buffer, nb_read);
503 memset(buffer, 0, 4096);
505 unsigned char tmp[MD5_DIGEST_LENGTH];
506 MD5_Final(tmp, &md5);
509 for (
int k = 0;
k < MD5_DIGEST_LENGTH; ++
k) {
510 sprintf(result +
k * 2,
"%02x", tmp[
k]);
int def(FILE *, FILE *, int)
void md5_File(std::string, char *)
FILE * create_file(char *, int)
int verify_checksum(const char *)
tuple path
else: Piece not in the list, fine.
void Untar(FILE *, const char *)
int is_end_of_archive(const char *)
#define SET_BINARY_MODE(file)
std::vector< std::vector< double > > tmp
void create_dir(char *, int)
int parseoct(const char *, size_t)
static std::string const source
int Unzip(std::string, std::string)