27 ret = deflateInit(&strm, level);
33 strm.avail_in = fread(in, 1,
CHUNK, source);
35 (void)deflateEnd(&strm);
38 flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
44 strm.avail_out =
CHUNK;
46 ret = deflate(&strm, flush);
47 assert(ret != Z_STREAM_ERROR);
48 have =
CHUNK - strm.avail_out;
49 if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
50 (void)deflateEnd(&strm);
53 }
while (strm.avail_out == 0);
54 assert(strm.avail_in == 0);
57 }
while (flush != Z_FINISH);
58 assert(ret == Z_STREAM_END);
61 (void)deflateEnd(&strm);
84 strm.next_in = Z_NULL;
86 ret = inflateInit2(&strm, (16+MAX_WBITS));
92 strm.avail_in = fread(in, 1,
CHUNK, source);
94 (void)inflateEnd(&strm);
97 if (strm.avail_in == 0)
103 strm.avail_out =
CHUNK;
105 ret = inflate(&strm, Z_NO_FLUSH);
106 assert(ret != Z_STREAM_ERROR);
112 (void)inflateEnd(&strm);
115 have =
CHUNK - strm.avail_out;
116 if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
117 (void)inflateEnd(&strm);
120 }
while (strm.avail_out == 0);
123 }
while (ret != Z_STREAM_END);
126 (void)inflateEnd(&strm);
127 return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
133 fputs(
"zpipe: ", stderr);
137 fputs(
"error reading stdin\n", stderr);
139 fputs(
"error writing stdout\n", stderr);
142 fputs(
"invalid compression level\n", stderr);
145 fputs(
"invalid or incomplete deflate data\n", stderr);
148 fputs(
"out of memory\n", stderr);
150 case Z_VERSION_ERROR:
151 fputs(
"zlib version mismatch!\n", stderr);
161 const char *tmpdir = getenv(
"TMPDIR");
162 if (tmpdir && (strlen(tmpdir) > 50)) {
163 setenv(
"TMPDIR",
"/tmp",
true);
169 FILE *
in = fopen(infile.c_str(),
"r");
171 FILE *
out = fopen(outfile.c_str(),
"w");
193 while (*p < '0' || *p >
'7') {
197 while (*p >=
'0' && *p <= '7' && n > 0) {
209 for (n = 511; n >= 0; --
n)
221 if (pathname[strlen(pathname) - 1] ==
'/')
222 pathname[strlen(pathname) - 1] =
'\0';
225 r =
mkdir(pathname, mode);
229 p = strrchr(pathname,
'/');
234 r =
mkdir(pathname, mode);
238 fprintf(stderr,
"Could not create directory %s\n", pathname);
244 f = fopen(pathname,
"w+");
247 char *
p = strrchr(pathname,
'/');
252 f = fopen(pathname,
"w+");
261 for (n = 0; n < 512; ++
n) {
262 if (n < 148 || n > 155)
264 u += ((
unsigned char *)p)[
n];
274 bool longpathname=
false;
275 bool longlinkname=
false;
276 char newlongpathname[512];
277 char newlonglinkname[512];
283 printf(
"Extracting from %s\n", path);
286 bytes_read = fread(buff, 1, 512, a);
287 if (bytes_read < 512) {
289 "Short read on %s: expected 512, got %d\n",path, (
int)bytes_read);
293 printf(
"End of %s\n", path);
297 fprintf(stderr,
"Checksum failure\n");
300 filesize =
parseoct(buff + 124, 12);
304 printf(
" Ignoring hardlink %s\n", buff);
307 if (longpathname && longlinkname){
310 printf(
" Extracting symlink %s\n", newlongpathname);
311 symlink(newlonglinkname,newlongpathname);
312 }
else if (longpathname) {
314 printf(
" Extracting symlink %s\n", newlongpathname);
315 symlink(buff+157,newlongpathname);
316 }
else if (longlinkname) {
318 printf(
" Extracting symlink %s\n", buff);
319 symlink(newlonglinkname,buff);
321 printf(
" Extracting symlink %s\n", buff);
322 symlink(buff+157,buff);
326 printf(
" Ignoring character device %s\n", buff);
329 printf(
" Ignoring block device %s\n", buff);
334 for (
int k=99;
k>=0;
k--){
335 if (buff[
k]==
'\0') endposition=
k;
337 if (endposition==-1) {
340 for (
int k=0;
k<100;
k++){
341 newlongpathname[
k]=buff[
k];
343 newlongpathname[100]=
'\0';
349 printf(
" Extracting dir %s\n", newlongpathname);
354 printf(
" Extracting dir %s\n", buff);
362 printf(
" Ignoring FIFO %s\n", buff);
395 for (
int k=99;
k>=0;
k--){
396 if (buff[
k]==
'\0') endposition=
k;
398 if (endposition==-1) {
401 for (
int k=0;
k<100;
k++){
402 newlongpathname[
k]=buff[
k];
404 newlongpathname[100]=
'\0';
409 printf(
" Extracting file %s\n", newlongpathname);
414 printf(
" Extracting file %s\n", buff);
420 if (longlinkname || longpathname) {
423 for (
int ll=0; ll<512; ll++){ printf(
"%c",buff[ll]);} printf(
"\n");
424 bytes_read = fread(buff, 1, 512, a);
425 for (
int ll=0; ll<512; ll++){ printf(
"%c",buff[ll]);} printf(
"\n");
426 for (
int k=0;
k<filesize;
k++){
427 newlonglinkname[
k]=buff[
k];
429 newlonglinkname[filesize]=
'\0';
430 for (
int k=filesize+1;
k<512;
k++){
431 newlonglinkname[
k]=
'0';
434 }
else if (buff[156]==
'L'){
435 bytes_read = fread(buff, 1, 512, a);
436 for (
int k=0;
k<filesize;
k++){
437 newlongpathname[
k]=buff[
k];
439 newlongpathname[filesize]=
'\0';
440 for (
int k=filesize+1;
k<512;
k++){
441 newlongpathname[
k]=
'0';
461 if (!longpathname && !longlinkname) {
462 while (filesize > 0) {
463 bytes_read = fread(buff, 1, 512, a);
464 if (bytes_read < 512) {
466 "Short read on %s: Expected 512, got %d\n", path, (
int)bytes_read);
470 bytes_read = filesize;
472 if (fwrite(buff, 1, bytes_read, f)
475 fprintf(stderr,
"Failed write\n");
480 filesize -= bytes_read;
499 int fd = open(filename.c_str(), O_RDONLY);
501 while ((nb_read = read(fd, buffer, 4096 - 1)))
503 MD5_Update(&md5, buffer, nb_read);
504 memset(buffer, 0, 4096);
506 unsigned char tmp[MD5_DIGEST_LENGTH];
507 MD5_Final(tmp, &md5);
510 for (
int k = 0;
k < MD5_DIGEST_LENGTH; ++
k) {
511 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 *)
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)