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,6 +543,7 @@ bool lrzip_run(Lrzip *lr)
|
|||
lr->control->infile = lr->infilenames[0];
|
||||
else {
|
||||
lr->control->inFILE = lr->infiles[0];
|
||||
if ( lr->infiles[0] == stdin )
|
||||
control->flags |= FLAG_STDIN;
|
||||
}
|
||||
|
||||
|
|
|
|||
28
lrzip.c
28
lrzip.c
|
|
@ -684,7 +684,7 @@ bool decompress_file(rzip_control *control)
|
|||
i64 expected_size = 0, free_space;
|
||||
struct statvfs fbuf;
|
||||
|
||||
if (!STDIN) {
|
||||
if (!STDIN && !IS_FROM_FILE) {
|
||||
struct stat 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);
|
||||
}
|
||||
|
||||
if (STDIN) {
|
||||
if ( IS_FROM_FILE ) {
|
||||
fd_in = fileno(control->inFILE);
|
||||
}
|
||||
else if (STDIN) {
|
||||
fd_in = open_tmpinfile(control);
|
||||
read_tmpinmagic(control);
|
||||
if (ENCRYPT)
|
||||
|
|
@ -850,7 +853,9 @@ bool decompress_file(rzip_control *control)
|
|||
if (unlikely(!STDIN && !STDOUT && !TEST_ONLY && !preserve_times(control, fd_in)))
|
||||
return false;
|
||||
|
||||
if ( ! IS_FROM_FILE ) {
|
||||
close(fd_in);
|
||||
}
|
||||
|
||||
if (!KEEP_FILES && !STDIN) {
|
||||
if (unlikely(unlink(control->infile)))
|
||||
|
|
@ -947,7 +952,9 @@ bool get_fileinfo(rzip_control *control)
|
|||
infilecopy = strdupa(control->infile);
|
||||
}
|
||||
|
||||
if (STDIN)
|
||||
if ( IS_FROM_FILE )
|
||||
fd_in = fileno(control->inFILE);
|
||||
else if (STDIN)
|
||||
fd_in = 0;
|
||||
else {
|
||||
fd_in = open(infilecopy, O_RDONLY);
|
||||
|
|
@ -966,7 +973,8 @@ bool get_fileinfo(rzip_control *control)
|
|||
|
||||
if (ENCRYPT) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -1130,6 +1138,7 @@ done:
|
|||
print_output("\n");
|
||||
} else
|
||||
print_output("CRC32 used for integrity testing\n");
|
||||
if ( !IS_FROM_FILE )
|
||||
if (unlikely(close(fd_in)))
|
||||
fatal_return(("Failed to close fd_in in get_fileinfo\n"), false);
|
||||
|
||||
|
|
@ -1137,7 +1146,7 @@ out:
|
|||
free(control->outfile);
|
||||
return true;
|
||||
error:
|
||||
if (!STDIN) close(fd_in);
|
||||
if (!STDIN && ! IS_FROM_FILE) close(fd_in);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -1159,7 +1168,9 @@ bool compress_file(rzip_control *control)
|
|||
return false;
|
||||
memset(header, 0, sizeof(header));
|
||||
|
||||
if (!STDIN) {
|
||||
if ( IS_FROM_FILE )
|
||||
fd_in = fileno(control->inFILE);
|
||||
else if (!STDIN) {
|
||||
/* is extension at end of infile? */
|
||||
if ((tmp = strrchr(control->infile, '.')) && !strcmp(tmp, control->suffix)) {
|
||||
print_err("%s: already has %s suffix. Skipping...\n", control->infile, control->suffix);
|
||||
|
|
@ -1169,7 +1180,8 @@ bool compress_file(rzip_control *control)
|
|||
fd_in = open(control->infile, O_RDONLY);
|
||||
if (unlikely(fd_in == -1))
|
||||
fatal_return(("Failed to open %s\n", control->infile), false);
|
||||
} else
|
||||
}
|
||||
else
|
||||
fd_in = 0;
|
||||
|
||||
if (!STDOUT) {
|
||||
|
|
@ -1269,7 +1281,7 @@ bool compress_file(rzip_control *control)
|
|||
free(control->outfile);
|
||||
return true;
|
||||
error:
|
||||
if (STDIN && (fd_in > 0))
|
||||
if (! IS_FROM_FILE && STDIN && (fd_in > 0))
|
||||
close(fd_in);
|
||||
if ((!STDOUT) && (fd_out > 0))
|
||||
close(fd_out);
|
||||
|
|
|
|||
|
|
@ -308,6 +308,8 @@ typedef sem_t cksem_t;
|
|||
#define TMP_INBUF (control->flags & FLAG_TMP_INBUF)
|
||||
#define ENCRYPT (control->flags & FLAG_ENCRYPT)
|
||||
|
||||
#define IS_FROM_FILE ( !!(control->inFILE) && !STDIN )
|
||||
|
||||
|
||||
/* Structure to save state of computation between the single steps. */
|
||||
struct md5_ctx
|
||||
|
|
|
|||
Loading…
Reference in a new issue