aboutsummaryrefslogtreecommitdiff
path: root/src/tar.c
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2020-08-01 21:38:07 +0200
committerJan200101 <sentrycraft123@gmail.com>2020-08-01 21:38:07 +0200
commitc11dd0eae09df4982459a34d764910d0501f2ae2 (patch)
tree940934202f436d67f94728c0704a19ac62f5c299 /src/tar.c
parent1db300d8815b5f997dd6f992e4ca416537018c2f (diff)
downloadpolecat-c11dd0eae09df4982459a34d764910d0501f2ae2.tar.gz
polecat-c11dd0eae09df4982459a34d764910d0501f2ae2.zip
Improve code structure […]
- create a dedicated "usage" macro to reuse - add various checks in the case no memory is available - fix cwd fetching check - correctly free json_objects to remove all existing leaks
Diffstat (limited to 'src/tar.c')
-rw-r--r--src/tar.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/tar.c b/src/tar.c
index b2f4ba5..8894676 100644
--- a/src/tar.c
+++ b/src/tar.c
@@ -28,7 +28,7 @@ static int copy_data(struct archive* ar, struct archive* aw)
void extract(const char* filename, const char* outputdir)
{
char cwd[256];
- getcwd(cwd, sizeof(cwd));
+ void* err = getcwd(cwd, sizeof(cwd));
if (chdir(outputdir) < 0)
{
@@ -50,10 +50,12 @@ void extract(const char* filename, const char* outputdir)
a = archive_read_new();
archive_read_support_format_all(a);
archive_read_support_filter_all(a);
+
ext = archive_write_disk_new();
archive_write_disk_set_options(ext, flags);
archive_write_disk_set_standard_lookup(ext);
- if ((r = archive_read_open_filename(a, filename, 10240))) return;
+
+ if ((r = archive_read_open_filename(a, filename, 0x4000))) return;
for (;;)
{
@@ -98,5 +100,5 @@ void extract(const char* filename, const char* outputdir)
archive_write_close(ext);
archive_write_free(ext);
- if (cwd != NULL) chdir(cwd);
+ if (err) chdir(cwd);
}