more code for tar extraction

This commit is contained in:
2022-12-13 14:21:19 +00:00
parent 9bea60d43a
commit 7904964e0d
3 changed files with 95 additions and 238 deletions

View File

@ -6,7 +6,7 @@
int main (int argc, char* argv[])
{
hio_t* hio;
hio_tar_t* untar;
hio_tar_t* tar;
FILE* fp;
if (argc != 2)
@ -22,10 +22,10 @@ int main (int argc, char* argv[])
return -1;
}
untar = hio_tar_open(hio, 0);
if (!untar)
tar = hio_tar_open(hio, 0);
if (!tar)
{
fprintf (stderr, "Error: unable to open untar\n");
fprintf (stderr, "Error: unable to open tar\n");
hio_close (hio);
return -1;
}
@ -34,31 +34,30 @@ int main (int argc, char* argv[])
if (!fp)
{
fprintf (stderr, "Error: unable to open file %s\n", argv[1]);
hio_tar_close (untar);
hio_tar_close (tar);
hio_close (hio);
return -1;
}
//hio_extract_tar(hio, argv[1]);
while (!feof(fp) && !ferror(fp))
{
int n;
char buf[512]; /* TODO: use a different buffer size???*/
char buf[4096]; /* TODO: use a different buffer size???*/
n = fread(buf, 1, sizeof(buf), fp);
if (n > 0)
{
if (hio_tar_feed(untar, buf, n) <= -1)
if (hio_tar_xfeed(tar, buf, n) <= -1)
{
fprintf (stderr, "Error: untar error - %s\n", hio_geterrbmsg(hio));
fprintf (stderr, "Error: tar error - %s\n", hio_geterrbmsg(hio));
break;
}
}
}
hio_tar_feed (untar, HIO_NULL, 0); /* indicate the end of input */
hio_tar_endxfeed (tar); /* indicate the end of input */
fclose (fp);
hio_tar_close (untar);
hio_tar_close (tar);
hio_close (hio);
return 0;
}