mirror of
https://github.com/ckolivas/lrzip.git
synced 2025-12-06 07:12:00 +01:00
Make liblrzip work when FILE provided is anything other than stdin. This will allow bindings to be created to lrzip
This commit is contained in:
parent
ac393eff44
commit
6e0016daf7
|
|
@ -543,7 +543,8 @@ bool lrzip_run(Lrzip *lr)
|
||||||
lr->control->infile = lr->infilenames[0];
|
lr->control->infile = lr->infilenames[0];
|
||||||
else {
|
else {
|
||||||
lr->control->inFILE = lr->infiles[0];
|
lr->control->inFILE = lr->infiles[0];
|
||||||
control->flags |= FLAG_STDIN;
|
if ( lr->infiles[0] == stdin )
|
||||||
|
control->flags |= FLAG_STDIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!STDOUT) && (!lr->control->msgout)) lr->control->msgout = stdout;
|
if ((!STDOUT) && (!lr->control->msgout)) lr->control->msgout = stdout;
|
||||||
|
|
|
||||||
38
lrzip.c
38
lrzip.c
|
|
@ -684,7 +684,7 @@ bool decompress_file(rzip_control *control)
|
||||||
i64 expected_size = 0, free_space;
|
i64 expected_size = 0, free_space;
|
||||||
struct statvfs fbuf;
|
struct statvfs fbuf;
|
||||||
|
|
||||||
if (!STDIN) {
|
if (!STDIN && !IS_FROM_FILE) {
|
||||||
struct stat fdin_stat;
|
struct stat fdin_stat;
|
||||||
|
|
||||||
stat(control->infile, &fdin_stat);
|
stat(control->infile, &fdin_stat);
|
||||||
|
|
@ -734,7 +734,10 @@ bool decompress_file(rzip_control *control)
|
||||||
print_progress("Output filename is: %s\n", control->outfile);
|
print_progress("Output filename is: %s\n", control->outfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STDIN) {
|
if ( IS_FROM_FILE ) {
|
||||||
|
fd_in = fileno(control->inFILE);
|
||||||
|
}
|
||||||
|
else if (STDIN) {
|
||||||
fd_in = open_tmpinfile(control);
|
fd_in = open_tmpinfile(control);
|
||||||
read_tmpinmagic(control);
|
read_tmpinmagic(control);
|
||||||
if (ENCRYPT)
|
if (ENCRYPT)
|
||||||
|
|
@ -850,7 +853,9 @@ bool decompress_file(rzip_control *control)
|
||||||
if (unlikely(!STDIN && !STDOUT && !TEST_ONLY && !preserve_times(control, fd_in)))
|
if (unlikely(!STDIN && !STDOUT && !TEST_ONLY && !preserve_times(control, fd_in)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
close(fd_in);
|
if ( ! IS_FROM_FILE ) {
|
||||||
|
close(fd_in);
|
||||||
|
}
|
||||||
|
|
||||||
if (!KEEP_FILES && !STDIN) {
|
if (!KEEP_FILES && !STDIN) {
|
||||||
if (unlikely(unlink(control->infile)))
|
if (unlikely(unlink(control->infile)))
|
||||||
|
|
@ -947,7 +952,9 @@ bool get_fileinfo(rzip_control *control)
|
||||||
infilecopy = strdupa(control->infile);
|
infilecopy = strdupa(control->infile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STDIN)
|
if ( IS_FROM_FILE )
|
||||||
|
fd_in = fileno(control->inFILE);
|
||||||
|
else if (STDIN)
|
||||||
fd_in = 0;
|
fd_in = 0;
|
||||||
else {
|
else {
|
||||||
fd_in = open(infilecopy, O_RDONLY);
|
fd_in = open(infilecopy, O_RDONLY);
|
||||||
|
|
@ -966,7 +973,8 @@ bool get_fileinfo(rzip_control *control)
|
||||||
|
|
||||||
if (ENCRYPT) {
|
if (ENCRYPT) {
|
||||||
print_output("Encrypted lrzip archive. No further information available\n");
|
print_output("Encrypted lrzip archive. No further information available\n");
|
||||||
if (!STDIN) close(fd_in);
|
if (!STDIN && !IS_FROM_FILE)
|
||||||
|
close(fd_in);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1130,14 +1138,15 @@ done:
|
||||||
print_output("\n");
|
print_output("\n");
|
||||||
} else
|
} else
|
||||||
print_output("CRC32 used for integrity testing\n");
|
print_output("CRC32 used for integrity testing\n");
|
||||||
if (unlikely(close(fd_in)))
|
if ( !IS_FROM_FILE )
|
||||||
fatal_return(("Failed to close fd_in in get_fileinfo\n"), false);
|
if (unlikely(close(fd_in)))
|
||||||
|
fatal_return(("Failed to close fd_in in get_fileinfo\n"), false);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free(control->outfile);
|
free(control->outfile);
|
||||||
return true;
|
return true;
|
||||||
error:
|
error:
|
||||||
if (!STDIN) close(fd_in);
|
if (!STDIN && ! IS_FROM_FILE) close(fd_in);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1159,17 +1168,20 @@ bool compress_file(rzip_control *control)
|
||||||
return false;
|
return false;
|
||||||
memset(header, 0, sizeof(header));
|
memset(header, 0, sizeof(header));
|
||||||
|
|
||||||
if (!STDIN) {
|
if ( IS_FROM_FILE )
|
||||||
/* is extension at end of infile? */
|
fd_in = fileno(control->inFILE);
|
||||||
|
else if (!STDIN) {
|
||||||
|
/* is extension at end of infile? */
|
||||||
if ((tmp = strrchr(control->infile, '.')) && !strcmp(tmp, control->suffix)) {
|
if ((tmp = strrchr(control->infile, '.')) && !strcmp(tmp, control->suffix)) {
|
||||||
print_err("%s: already has %s suffix. Skipping...\n", control->infile, control->suffix);
|
print_err("%s: already has %s suffix. Skipping...\n", control->infile, control->suffix);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd_in = open(control->infile, O_RDONLY);
|
fd_in = open(control->infile, O_RDONLY);
|
||||||
if (unlikely(fd_in == -1))
|
if (unlikely(fd_in == -1))
|
||||||
fatal_return(("Failed to open %s\n", control->infile), false);
|
fatal_return(("Failed to open %s\n", control->infile), false);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
fd_in = 0;
|
fd_in = 0;
|
||||||
|
|
||||||
if (!STDOUT) {
|
if (!STDOUT) {
|
||||||
|
|
@ -1269,7 +1281,7 @@ bool compress_file(rzip_control *control)
|
||||||
free(control->outfile);
|
free(control->outfile);
|
||||||
return true;
|
return true;
|
||||||
error:
|
error:
|
||||||
if (STDIN && (fd_in > 0))
|
if (! IS_FROM_FILE && STDIN && (fd_in > 0))
|
||||||
close(fd_in);
|
close(fd_in);
|
||||||
if ((!STDOUT) && (fd_out > 0))
|
if ((!STDOUT) && (fd_out > 0))
|
||||||
close(fd_out);
|
close(fd_out);
|
||||||
|
|
|
||||||
|
|
@ -308,6 +308,8 @@ typedef sem_t cksem_t;
|
||||||
#define TMP_INBUF (control->flags & FLAG_TMP_INBUF)
|
#define TMP_INBUF (control->flags & FLAG_TMP_INBUF)
|
||||||
#define ENCRYPT (control->flags & FLAG_ENCRYPT)
|
#define ENCRYPT (control->flags & FLAG_ENCRYPT)
|
||||||
|
|
||||||
|
#define IS_FROM_FILE ( !!(control->inFILE) && !STDIN )
|
||||||
|
|
||||||
|
|
||||||
/* Structure to save state of computation between the single steps. */
|
/* Structure to save state of computation between the single steps. */
|
||||||
struct md5_ctx
|
struct md5_ctx
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue