34 (
void)deflateEnd(&strm);
37 flush = feof(
source) ? Z_FINISH : Z_NO_FLUSH;
43 strm.avail_out =
CHUNK;
45 ret = deflate(&strm, flush);
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);
60 (
void)deflateEnd(&strm);
82 strm.next_in = Z_NULL;
84 ret = inflateInit2(&strm, (16 + MAX_WBITS));
92 (
void)inflateEnd(&strm);
95 if (strm.avail_in == 0)
101 strm.avail_out =
CHUNK;
103 ret = inflate(&strm, Z_NO_FLUSH);
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;
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);
158 const char *tmpdir = std::getenv(
"TMPDIR");
159 if (tmpdir && (strlen(tmpdir) > 50)) {
160 setenv(
"TMPDIR",
"/tmp",
true);
166 FILE *
in = fopen(
infile.c_str(),
"r");
190 while (*p < '0' || *p >
'7') {
194 while (*
p >=
'0' && *p <= '7' && n > 0) {
206 for (
n = 511;
n >= 0; --
n)
258 for (
n = 0;
n < 512; ++
n) {
259 if (n < 148 || n > 155)
261 u += ((
unsigned char *)
p)[
n];
270 bool longpathname =
false;
271 bool longlinkname =
false;
272 char newlongpathname[512];
273 char newlonglinkname[512];
279 printf(
"Extracting from %s\n",
path);
281 bytes_read = fread(buff, 1, 512,
a);
282 if (bytes_read < 512) {
283 fprintf(
stderr,
"Short read on %s: expected 512, got %d\n",
path, (
int)bytes_read);
287 printf(
"End of %s\n",
path);
291 fprintf(
stderr,
"Checksum failure\n");
294 filesize =
parseoct(buff + 124, 12);
298 printf(
" Ignoring hardlink %s\n", buff);
301 if (longpathname && longlinkname) {
302 longlinkname =
false;
303 longpathname =
false;
304 printf(
" Extracting symlink %s\n", newlongpathname);
305 symlink(newlonglinkname, newlongpathname);
306 }
else if (longpathname) {
307 longpathname =
false;
308 printf(
" Extracting symlink %s\n", newlongpathname);
309 symlink(buff + 157, newlongpathname);
310 }
else if (longlinkname) {
311 longlinkname =
false;
312 printf(
" Extracting symlink %s\n", buff);
313 symlink(newlonglinkname, buff);
315 printf(
" Extracting symlink %s\n", buff);
316 symlink(buff + 157, buff);
320 printf(
" Ignoring character device %s\n", buff);
323 printf(
" Ignoring block device %s\n", buff);
327 int endposition = -1;
328 for (
int k = 99;
k >= 0;
k--) {
332 if (endposition == -1) {
335 for (
int k = 0;
k < 100;
k++) {
336 newlongpathname[
k] = buff[
k];
338 newlongpathname[100] =
'\0';
344 printf(
" Extracting dir %s\n", newlongpathname);
346 longpathname =
false;
348 printf(
" Extracting dir %s\n", buff);
356 printf(
" Ignoring FIFO %s\n", buff);
388 int endposition = -1;
389 for (
int k = 99;
k >= 0;
k--) {
393 if (endposition == -1) {
396 for (
int k = 0;
k < 100;
k++) {
397 newlongpathname[
k] = buff[
k];
399 newlongpathname[100] =
'\0';
404 printf(
" Extracting file %s\n", newlongpathname);
406 longpathname =
false;
408 printf(
" Extracting file %s\n", buff);
414 if (longlinkname || longpathname) {
415 if (buff[156] ==
'K') {
416 for (
int ll = 0; ll < 512; ll++) {
417 printf(
"%c", buff[ll]);
420 bytes_read = fread(buff, 1, 512,
a);
421 for (
int ll = 0; ll < 512; ll++) {
422 printf(
"%c", buff[ll]);
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) {
464 fprintf(
stderr,
"Short read on %s: Expected 512, got %d\n",
path, (
int)bytes_read);
468 bytes_read = filesize;
470 if (fwrite(buff, 1, bytes_read,
f) != bytes_read) {
471 fprintf(
stderr,
"Failed write\n");
476 filesize -= bytes_read;
491 const EVP_MD *md = EVP_get_digestbyname(
"MD5");
492 EVP_DigestInit_ex(mdctx, md,
nullptr);
498 EVP_DigestUpdate(mdctx,
buffer, nb_read);
502 unsigned int md_len = 0;
503 unsigned char tmp[EVP_MAX_MD_SIZE];
504 EVP_DigestFinal_ex(mdctx,
tmp, &md_len);
509 for (
unsigned int k = 0;
k < md_len; ++
k) {
int def(FILE *, FILE *, int)
ret
prodAgent to be discontinued
void md5_File(std::string, char *)
FILE * create_file(char *, int)
TEMPL(T2) struct Divides void
int verify_checksum(const char *)
void Untar(FILE *, const char *)
int is_end_of_archive(const char *)
#define SET_BINARY_MODE(file)
void create_dir(char *, int)
int parseoct(const char *, size_t)
static std::string const source
int Unzip(std::string, std::string)