25 ret = deflateInit(&strm, level);
31 strm.avail_in = fread(in, 1,
CHUNK, source);
33 (void)deflateEnd(&strm);
36 flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
42 strm.avail_out =
CHUNK;
44 ret = deflate(&strm, flush);
45 assert(ret != Z_STREAM_ERROR);
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);
56 assert(ret == Z_STREAM_END);
59 (void)deflateEnd(&strm);
82 strm.next_in = Z_NULL;
84 ret = inflateInit2(&strm, (16+MAX_WBITS));
90 strm.avail_in = fread(in, 1,
CHUNK, source);
92 (void)inflateEnd(&strm);
95 if (strm.avail_in == 0)
101 strm.avail_out =
CHUNK;
103 ret = inflate(&strm, Z_NO_FLUSH);
104 assert(ret != Z_STREAM_ERROR);
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;
131 fputs(
"zpipe: ", stderr);
135 fputs(
"error reading stdin\n", stderr);
137 fputs(
"error writing stdout\n", stderr);
140 fputs(
"invalid compression level\n", stderr);
143 fputs(
"invalid or incomplete deflate data\n", stderr);
146 fputs(
"out of memory\n", stderr);
148 case Z_VERSION_ERROR:
149 fputs(
"zlib version mismatch!\n", stderr);
157 FILE *
in = fopen(infile.c_str(),
"r");
159 FILE *
out = fopen(outfile.c_str(),
"w");
181 while (*p < '0' || *p >
'7') {
185 while (*p >=
'0' && *p <= '7' && n > 0) {
197 for (n = 511; n >= 0; --
n)
209 if (pathname[strlen(pathname) - 1] ==
'/')
210 pathname[strlen(pathname) - 1] =
'\0';
213 r =
mkdir(pathname, mode);
217 p = strrchr(pathname,
'/');
222 r =
mkdir(pathname, mode);
226 fprintf(stderr,
"Could not create directory %s\n", pathname);
232 f = fopen(pathname,
"w+");
235 char *
p = strrchr(pathname,
'/');
240 f = fopen(pathname,
"w+");
249 for (n = 0; n < 512; ++
n) {
250 if (n < 148 || n > 155)
252 u += ((
unsigned char *)p)[
n];
262 bool longpathname=
false;
263 bool longlinkname=
false;
264 char newlongpathname[512];
265 char newlonglinkname[512];
271 printf(
"Extracting from %s\n", path);
274 bytes_read = fread(buff, 1, 512, a);
275 if (bytes_read < 512) {
277 "Short read on %s: expected 512, got %d\n",path, (
int)bytes_read);
281 printf(
"End of %s\n", path);
285 fprintf(stderr,
"Checksum failure\n");
288 filesize =
parseoct(buff + 124, 12);
292 printf(
" Ignoring hardlink %s\n", buff);
295 if (longpathname && longlinkname){
298 printf(
" Extracting symlink %s\n", newlongpathname);
299 symlink(newlonglinkname,newlongpathname);
300 }
else if (longpathname) {
302 printf(
" Extracting symlink %s\n", newlongpathname);
303 symlink(buff+157,newlongpathname);
304 }
else if (longlinkname) {
306 printf(
" Extracting symlink %s\n", buff);
307 symlink(newlonglinkname,buff);
309 printf(
" Extracting symlink %s\n", buff);
310 symlink(buff+157,buff);
314 printf(
" Ignoring character device %s\n", buff);
317 printf(
" Ignoring block device %s\n", buff);
322 for (
int k=99;
k>=0;
k--){
323 if (buff[
k]==
'\0') endposition=
k;
325 if (endposition==-1) {
328 for (
int k=0;
k<100;
k++){
329 newlongpathname[
k]=buff[
k];
331 newlongpathname[100]=
'\0';
337 printf(
" Extracting dir %s\n", newlongpathname);
342 printf(
" Extracting dir %s\n", buff);
350 printf(
" Ignoring FIFO %s\n", buff);
383 for (
int k=99;
k>=0;
k--){
384 if (buff[
k]==
'\0') endposition=
k;
386 if (endposition==-1) {
389 for (
int k=0;
k<100;
k++){
390 newlongpathname[
k]=buff[
k];
392 newlongpathname[100]=
'\0';
397 printf(
" Extracting file %s\n", newlongpathname);
402 printf(
" Extracting file %s\n", buff);
408 if (longlinkname || longpathname) {
411 for (
int ll=0; ll<512; ll++){ printf(
"%c",buff[ll]);} printf(
"\n");
412 bytes_read = fread(buff, 1, 512, a);
413 for (
int ll=0; ll<512; ll++){ printf(
"%c",buff[ll]);} printf(
"\n");
414 for (
int k=0;
k<filesize;
k++){
415 newlonglinkname[
k]=buff[
k];
417 newlonglinkname[filesize]=
'\0';
418 for (
int k=filesize+1;
k<512;
k++){
419 newlonglinkname[
k]=
'0';
422 }
else if (buff[156]==
'L'){
423 bytes_read = fread(buff, 1, 512, a);
424 for (
int k=0;
k<filesize;
k++){
425 newlongpathname[
k]=buff[
k];
427 newlongpathname[filesize]=
'\0';
428 for (
int k=filesize+1;
k<512;
k++){
429 newlongpathname[
k]=
'0';
449 if (!longpathname && !longlinkname) {
450 while (filesize > 0) {
451 bytes_read = fread(buff, 1, 512, a);
452 if (bytes_read < 512) {
454 "Short read on %s: Expected 512, got %d\n", path, (
int)bytes_read);
458 bytes_read = filesize;
460 if (fwrite(buff, 1, bytes_read, f)
463 fprintf(stderr,
"Failed write\n");
468 filesize -= bytes_read;
487 int fd = open(filename.c_str(), O_RDONLY);
489 while ((nb_read =
read(fd, buffer, 4096 - 1)))
491 MD5_Update(&md5, buffer, nb_read);
492 memset(buffer, 0, 4096);
494 unsigned char tmp[MD5_DIGEST_LENGTH];
495 MD5_Final(tmp, &md5);
498 for (
int k = 0;
k < MD5_DIGEST_LENGTH; ++
k) {
499 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)