diff --git a/Makefile.am b/Makefile.am
index 6fee462..cea857c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -34,7 +34,6 @@ lrztar_SCRIPTS = lrztar
noinst_LTLIBRARIES = libtmplrzip.la
libtmplrzip_la_SOURCES = \
lrzip_private.h \
- liblrzip_private.h \
lrzip.c \
lrzip_core.h \
rzip.h \
@@ -57,13 +56,6 @@ libtmplrzip_la_SOURCES = \
libtmplrzip_la_LIBADD = lzma/C/liblzma.la
-lib_LTLIBRARIES = liblrzip.la
-liblrzip_la_SOURCES = \
- liblrzip.c \
- liblrzip_private.h
-nodist_EXTRA_liblrzip_la_SOURCES = dummy.cxx
-liblrzip_la_LIBADD = libtmplrzip.la
-
bin_PROGRAMS = lrzip
lrzip_SOURCES = \
main.c
@@ -74,13 +66,6 @@ if STATIC
lrzip_LDFLAGS = -all-static
endif
-noinst_PROGRAMS = decompress_demo liblrzip_demo
-decompress_demo_SOURCES = decompress_demo.c
-decompress_demo_LDADD = liblrzip.la
-
-liblrzip_demo_SOURCES = liblrzip_demo.c
-liblrzip_demo_LDADD = liblrzip.la
-
dist_doc_DATA = \
AUTHORS \
BUGS \
diff --git a/liblrzip.c b/liblrzip.c
deleted file mode 100644
index 67d6bba..0000000
--- a/liblrzip.c
+++ /dev/null
@@ -1,742 +0,0 @@
-/*
- Copyright (C) 2012-2016,2018 Con Kolivas
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-*/
-
-#include
-
-#ifdef HAVE_SYS_TIME_H
-# include
-#endif
-#ifdef HAVE_SYS_RESOURCE_H
-# include
-#endif
-#ifdef HAVE_SYS_TYPES_H
-# include
-#endif
-#ifdef HAVE_SYS_STAT_H
-# include
-#endif
-
-/* needed for CRC routines */
-#include "lzma/C/7zCrc.h"
-#include "util.h"
-#include "lrzip_core.h"
-#include "rzip.h"
-
-#if defined(__APPLE__) || defined(__FreeBSD__)
-# define fmemopen(s, len, modes) fake_fmemopen((s), (len), (modes))
-static FILE *fake_fmemopen(void *buf, size_t buflen, const char *mode)
-{
- FILE *in;
-
- in = tmpfile();
- if (!in)
- return NULL;
- if (fwrite(buf, buflen, 1, in) != 1) {
- fclose(in);
- return NULL;
- }
- rewind(in);
- return in;
-}
-#endif
-
-static void liblrzip_index_update(size_t x, size_t *idx, void **queue)
-{
- for (; x < *idx; x++)
- queue[x] = queue[x + 1];
- (*idx)--;
-}
-
-static bool liblrzip_setup_flags(Lrzip *lr)
-{
- if (!lr)
- return false;
-#define MODE_CHECK(X) \
- case LRZIP_MODE_COMPRESS_##X: \
- lr->control->flags ^= FLAG_NOT_LZMA; \
- lr->control->flags |= FLAG_##X##_COMPRESS; \
- break
-
-
- switch (lr->mode) {
- case LRZIP_MODE_DECOMPRESS:
- lr->control->flags |= FLAG_DECOMPRESS;
- break;
- case LRZIP_MODE_TEST:
- lr->control->flags |= FLAG_TEST_ONLY;
- break;
- case LRZIP_MODE_INFO:
- lr->control->flags |= FLAG_INFO;
- break;
- case LRZIP_MODE_COMPRESS_NONE:
- lr->control->flags ^= FLAG_NOT_LZMA;
- lr->control->flags |= FLAG_NO_COMPRESS;
- break;
- case LRZIP_MODE_COMPRESS_LZMA:
- lr->control->flags ^= FLAG_NOT_LZMA;
- break;
- MODE_CHECK(LZO);
- MODE_CHECK(BZIP2);
- MODE_CHECK(ZLIB);
- MODE_CHECK(ZPAQ);
-#undef MODE_CHECK
- default:
- return false;
- }
- setup_overhead(lr->control);
- if (lr->flags & LRZIP_FLAG_VERIFY) {
- lr->control->flags |= FLAG_CHECK;
- lr->control->flags |= FLAG_HASH;
- }
- if (lr->flags & LRZIP_FLAG_REMOVE_DESTINATION)
- lr->control->flags |= FLAG_FORCE_REPLACE;
- if (lr->flags & LRZIP_FLAG_REMOVE_SOURCE)
- lr->control->flags &= ~FLAG_KEEP_FILES;
- if (lr->flags & LRZIP_FLAG_KEEP_BROKEN)
- lr->control->flags |= FLAG_KEEP_BROKEN;
- if (lr->flags & LRZIP_FLAG_DISABLE_LZO_CHECK)
- lr->control->flags &= ~FLAG_THRESHOLD;
- if (lr->flags & LRZIP_FLAG_UNLIMITED_RAM)
- lr->control->flags |= FLAG_UNLIMITED;
- if (lr->flags & LRZIP_FLAG_ENCRYPT)
- lr->control->flags |= FLAG_ENCRYPT;
- if (lr->control->log_level > 0) {
- lr->control->flags |= FLAG_SHOW_PROGRESS;
- if (lr->control->log_level > 1) {
- lr->control->flags |= FLAG_VERBOSITY;
- if (lr->control->log_level > 2)
- lr->control->flags |= FLAG_VERBOSITY_MAX;
- }
- } else lr->control->flags ^= (FLAG_VERBOSE | FLAG_SHOW_PROGRESS);
- return true;
-}
-
-
-bool lrzip_init(void)
-{
- /* generate crc table */
- CrcGenerateTable();
- return true;
-}
-
-void lrzip_config_env(Lrzip *lr)
-{
- const char *eptr;
- /* Get Preloaded Defaults from lrzip.conf
- * Look in ., $HOME/.lrzip/, /etc/lrzip.
- * If LRZIP=NOCONFIG is set, then ignore config
- */
- eptr = getenv("LRZIP");
- if (!eptr)
- read_config(lr->control);
- else if (!strstr(eptr,"NOCONFIG"))
- read_config(lr->control);
-}
-
-void lrzip_free(Lrzip *lr)
-{
- size_t x;
-
- if ((!lr) || (!lr->infilename_buckets))
- return;
- rzip_control_free(lr->control);
- for (x = 0; x < lr->infilename_idx; x++)
- dealloc(lr->infilenames[x]);
- dealloc(lr->infilenames);
- dealloc(lr->infiles);
- dealloc(lr);
-}
-
-Lrzip *lrzip_new(Lrzip_Mode mode)
-{
- Lrzip *lr;
-
- lr = calloc(1, sizeof(Lrzip));
- if (!lr)
- return NULL;
- lr->control = calloc(1, sizeof(rzip_control));
- if (!lr->control)
- goto error;
- if (!initialize_control(lr->control))
- goto error;
- lr->mode = mode;
- lr->control->library_mode = 1;
- return lr;
-error:
- lrzip_free(lr);
- return NULL;
-}
-
-Lrzip_Mode lrzip_mode_get(Lrzip *lr)
-{
- if (!lr)
- return LRZIP_MODE_NONE;
- return lr->mode;
-}
-
-bool lrzip_mode_set(Lrzip *lr, Lrzip_Mode mode)
-{
- if ((!lr) || (mode > LRZIP_MODE_COMPRESS_ZPAQ))
- return false;
- lr->mode = mode;
- return true;
-}
-
-bool lrzip_compression_level_set(Lrzip *lr, unsigned int level)
-{
- if ((!lr) || (!level) || (level > 9))
- return false;
- lr->control->compression_level = level;
- return true;
-}
-
-unsigned int lrzip_compression_level_get(Lrzip *lr)
-{
- if (!lr)
- return 0;
- return lr->control->compression_level;
-}
-
-void lrzip_flags_set(Lrzip *lr, unsigned int flags)
-{
- if (!lr)
- return;
- lr->flags = flags;
-}
-
-unsigned int lrzip_flags_get(Lrzip *lr)
-{
- if (!lr)
- return 0;
- return lr->flags;
-}
-
-void lrzip_nice_set(Lrzip *lr, int nice)
-{
- if ((!lr) || (nice < -19) || (nice > 20))
- return;
- lr->control->nice_val = nice;
-}
-
-int lrzip_nice_get(Lrzip *lr)
-{
- if (!lr)
- return 0;
- return lr->control->nice_val;
-}
-
-void lrzip_threads_set(Lrzip *lr, unsigned int threads)
-{
- if ((!lr) || (!threads))
- return;
- lr->control->threads = threads;
-}
-
-unsigned int lrzip_threads_get(Lrzip *lr)
-{
- if (!lr)
- return 0;
- return lr->control->threads;
-}
-
-void lrzip_compression_window_max_set(Lrzip *lr, int64_t size)
-{
- if (!lr)
- return;
- lr->control->window = size;
-}
-
-int64_t lrzip_compression_window_max_get(Lrzip *lr)
-{
- if (!lr)
- return -1;
- return lr->control->window;
-}
-
-unsigned int lrzip_files_count(Lrzip *lr)
-{
- if (!lr)
- return 0;
- return lr->infile_idx;
-}
-
-unsigned int lrzip_filenames_count(Lrzip *lr)
-{
- if (!lr)
- return 0;
- return lr->infilename_idx;
-}
-
-FILE **lrzip_files_get(Lrzip *lr)
-{
- if (!lr)
- return NULL;
- return lr->infiles;
-}
-
-char **lrzip_filenames_get(Lrzip *lr)
-{
- if (!lr)
- return NULL;
- return lr->infilenames;
-}
-
-bool lrzip_file_add(Lrzip *lr, FILE *file)
-{
- if ((!lr) || (!file))
- return false;
- if (lr->infilenames)
- return false;
- if (!lr->infile_buckets) {
- /* no files added */
- lr->infiles = calloc(INFILE_BUCKET_SIZE + 1, sizeof(void*));
- lr->infile_buckets++;
- } else if (lr->infile_idx == INFILE_BUCKET_SIZE * lr->infile_buckets + 1) {
- /* all buckets full, create new bucket */
- FILE **tmp;
-
- tmp = realloc(lr->infiles, (++lr->infile_buckets * INFILE_BUCKET_SIZE + 1) * sizeof(void*));
- if (!tmp)
- return false;
- lr->infiles = tmp;
- }
-
- lr->infiles[lr->infile_idx++] = file;
- return true;
-}
-
-bool lrzip_file_del(Lrzip *lr, FILE *file)
-{
- size_t x;
-
- if ((!lr) || (!file))
- return false;
- if (!lr->infile_buckets)
- return true;
-
- for (x = 0; x <= lr->infile_idx + 1; x++) {
- if (!lr->infiles[x])
- return true; /* not found */
- if (lr->infiles[x] != file)
- continue; /* not a match */
- break;
- }
- /* update index */
- liblrzip_index_update(x, &lr->infile_idx, (void**)lr->infiles);
- return true;
-}
-
-FILE *lrzip_file_pop(Lrzip *lr)
-{
- FILE *ret;
- if ((!lr) || (!lr->infile_buckets))
- return NULL;
- ret = lr->infiles[0];
- lrzip_file_del(lr, ret);
- return ret;
-}
-
-void lrzip_files_clear(Lrzip *lr)
-{
- if ((!lr) || (!lr->infile_buckets))
- return;
- dealloc(lr->infiles);
- lr->infiles = NULL;
-}
-
-bool lrzip_filename_add(Lrzip *lr, const char *file)
-{
- struct stat st;
-
- if ((!lr) || (!file) || (!file[0]) || (!strcmp(file, "-")))
- return false;
- if (lr->infiles)
- return false;
- if (stat(file, &st))
- return false;
- if (S_ISDIR(st.st_mode))
- return false;
-
- if (!lr->infilename_buckets) {
- /* no files added */
- lr->infilenames = calloc(INFILE_BUCKET_SIZE + 1, sizeof(void*));
- lr->infilename_buckets++;
- } else if (lr->infilename_idx == INFILE_BUCKET_SIZE * lr->infilename_buckets + 1) {
- /* all buckets full, create new bucket */
- char **tmp;
-
- tmp = realloc(lr->infilenames, (++lr->infilename_buckets * INFILE_BUCKET_SIZE + 1) * sizeof(void*));
- if (!tmp)
- return false;
- lr->infilenames = tmp;
- }
-
- lr->infilenames[lr->infilename_idx++] = strdup(file);
- return true;
-}
-
-bool lrzip_filename_del(Lrzip *lr, const char *file)
-{
- size_t x;
-
- if ((!lr) || (!file) || (!file[0]))
- return false;
- if (!lr->infilename_buckets)
- return true;
-
- for (x = 0; x <= lr->infilename_idx + 1; x++) {
- if (!lr->infilenames[x])
- return true; /* not found */
- if (strcmp(lr->infilenames[x], file))
- continue; /* not a match */
- dealloc(lr->infilenames[x]);
- break;
- }
- /* update index */
- liblrzip_index_update(x, &lr->infilename_idx, (void**)lr->infilenames);
- return true;
-}
-
-const char *lrzip_filename_pop(Lrzip *lr)
-{
- static char buf[4096];
- if ((!lr) || (!lr->infilename_buckets))
- return NULL;
- strcat(buf, lr->infilenames[0]);
- lrzip_filename_del(lr, buf);
- return &buf[0];
-}
-
-void lrzip_filenames_clear(Lrzip *lr)
-{
- size_t x;
- if ((!lr) || (!lr->infilename_buckets))
- return;
- for (x = 0; x < lr->infilename_idx; x++)
- dealloc(lr->infilenames[x]);
- dealloc(lr->infilenames);
- lr->infilenames = NULL;
-}
-
-void lrzip_suffix_set(Lrzip *lr, const char *suffix)
-{
- if ((!lr) || (!suffix) || (!suffix[0]))
- return;
- dealloc(lr->control->suffix);
- lr->control->suffix = strdup(suffix);
-}
-
-const char *lrzip_suffix_get(Lrzip *lr)
-{
- if (!lr)
- return NULL;
- return lr->control->suffix;
-}
-
-void lrzip_outdir_set(Lrzip *lr, const char *dir)
-{
- const char *slash;
- char *buf;
- size_t len;
- if ((!lr) || (!dir) || (!dir[0]))
- return;
- dealloc(lr->control->outdir);
- slash = strrchr(dir, '/');
- if (slash && (slash[1] == 0)) {
- lr->control->outdir = strdup(dir);
- return;
- }
- len = strlen(dir);
- buf = malloc(len + 2);
- if (!buf)
- return;
- memcpy(buf, dir, len);
- buf[len] = '/';
- buf[len + 1] = 0;
- lr->control->outdir = buf;
-}
-
-const char *lrzip_outdir_get(Lrzip *lr)
-{
- if (!lr)
- return NULL;
- return lr->control->outdir;
-}
-
-void lrzip_outfile_set(Lrzip *lr, FILE *file)
-{
- if ((!lr) || (file && (file == stderr)))
- return;
- if (lr->control->outname)
- return;
- lr->control->outFILE = file;
-}
-
-FILE *lrzip_outfile_get(Lrzip *lr)
-{
- if (!lr)
- return NULL;
- return lr->control->outFILE;
-}
-
-void lrzip_outfilename_set(Lrzip *lr, const char *file)
-{
- if ((!lr) || (file && (!file[0])))
- return;
- if (lr->control->outFILE)
- return;
- if (lr->control->outname && file && (!strcmp(lr->control->outname, file)))
- return;
- dealloc(lr->control->outname);
- lr->control->outname = file ? strdup(file) : NULL;
-}
-
-const char *lrzip_outfilename_get(Lrzip *lr)
-{
- if (!lr)
- return NULL;
- return lr->control->outname;
-}
-
-const unsigned char *lrzip_md5digest_get(Lrzip *lr)
-{
- if (!lr)
- return NULL;
- return lr->control->md5_resblock;
-}
-
-bool lrzip_run(Lrzip *lr)
-{
- struct timeval start_time, end_time;
- rzip_control *control;
- double seconds,total_time; // for timers
- int hours,minutes;
-
- if (!liblrzip_setup_flags(lr))
- return false;
- control = lr->control;
-
- if ((!lr->infile_idx) && (!lr->infilename_idx))
- return false;
- if (lr->control->outFILE) {
- if (lr->control->outFILE == lr->control->msgout)
- lr->control->msgout = stderr;
- lr->control->flags |= FLAG_STDOUT;
- register_outputfile(lr->control, lr->control->msgout);
- }
-
- if (lr->infilenames)
- lr->control->infile = lr->infilenames[0];
- else {
- lr->control->inFILE = lr->infiles[0];
- if ( lr->infiles[0] == stdin )
- control->flags |= FLAG_STDIN;
- }
-
- if ((!STDOUT) && (!lr->control->msgout)) lr->control->msgout = stdout;
- register_outputfile(lr->control, lr->control->msgout);
-
- setup_ram(lr->control);
-
- gettimeofday(&start_time, NULL);
-
- if (ENCRYPT && (!lr->control->pass_cb)) {
- print_err("No password callback set!\n");
- return false;
- }
-
- if (DECOMPRESS || TEST_ONLY) {
- if (!decompress_file(lr->control))
- return false;
- } else if (INFO) {
- if (!get_fileinfo(lr->control))
- return false;
- } else if (!compress_file(lr->control))
- return false;
-
- /* compute total time */
- gettimeofday(&end_time, NULL);
- total_time = (end_time.tv_sec + (double)end_time.tv_usec / 1000000) -
- (start_time.tv_sec + (double)start_time.tv_usec / 1000000);
- hours = (int)total_time / 3600;
- minutes = (int)(total_time / 60) % 60;
- seconds = total_time - hours * 3600 - minutes * 60;
- if (!INFO)
- print_progress("Total time: %02d:%02d:%05.2f\n", hours, minutes, seconds);
-
- return true;
-}
-
-void lrzip_log_level_set(Lrzip *lr, int level)
-{
- if (!lr)
- return;
- lr->control->log_level = level;
-}
-
-int lrzip_log_level_get(Lrzip *lr)
-{
- if (!lr)
- return 0;
- return lr->control->log_level;
-}
-
-void lrzip_log_cb_set(Lrzip *lr, Lrzip_Log_Cb cb, void *log_data)
-{
- if (!lr)
- return;
- lr->control->log_cb = cb;
- lr->control->log_data = log_data;
-}
-
-void lrzip_log_stdout_set(Lrzip *lr, FILE *out)
-{
- if (!lr)
- return;
- lr->control->msgout = out;
-}
-
-FILE *lrzip_log_stdout_get(Lrzip *lr)
-{
- if (!lr)
- return NULL;
- return lr->control->msgout;
-}
-
-void lrzip_log_stderr_set(Lrzip *lr, FILE *err)
-{
- if (!lr)
- return;
- lr->control->msgerr = err;
-}
-
-FILE *lrzip_log_stderr_get(Lrzip *lr)
-{
- if (!lr)
- return NULL;
- return lr->control->msgerr;
-}
-
-void lrzip_pass_cb_set(Lrzip *lr, Lrzip_Password_Cb cb, void *data)
-{
- if (!lr)
- return;
- lr->control->pass_cb = cb;
- lr->control->pass_data = data;
-}
-
-void lrzip_info_cb_set(Lrzip *lr, Lrzip_Info_Cb cb, void *data)
-{
- if (!lr)
- return;
- lr->control->info_cb = cb;
- lr->control->info_data = data;
-}
-
-bool lrzip_compress_full(void *dest, unsigned long *dest_len, const void *source, unsigned long source_len, Lrzip_Mode mode, int compress_level)
-{
- FILE *s = NULL, *d = NULL;
- Lrzip *lr = NULL;
- bool ret = false;
- struct stat st;
- int fd;
-
- if ((!dest) || (!dest_len) || (!source) || (!source_len) || (mode < LRZIP_MODE_COMPRESS_NONE))
- goto out;
-
- lrzip_init();
- if (!mode) mode = LRZIP_MODE_COMPRESS_LZMA;
- lr = lrzip_new(mode);
- if (!lr)
- goto out;
- lrzip_config_env(lr);
-
- s = fmemopen((void*)source, source_len, "r");
- d = tmpfile();
- if ((!s) || (!d))
- goto out;
-
- if (!lrzip_file_add(lr, s))
- goto out;
- lrzip_outfile_set(lr, d);
- if (!lrzip_compression_level_set(lr, compress_level))
- goto out;
- if (!lrzip_run(lr))
- goto out;
-
- fd = fileno(d);
- if (fstat(fd, &st))
- goto out;
- *dest_len = st.st_size;
- if (unlikely((i64)fread(dest, sizeof(char), st.st_size, d) != st.st_size))
- goto out;
- if (unlikely(ferror(d)))
- goto out;
- ret = true;
-
-out:
- if (s) fclose(s);
- if (d) fclose(d);
- lrzip_free(lr);
- return ret;
-}
-
-
-bool lrzip_decompress(void *dest, unsigned long *dest_len, const void *source, unsigned long source_len)
-{
- FILE *s = NULL, *d = NULL;
- Lrzip *lr = NULL;
- bool ret = false;
- struct stat st;
- int fd;
-
- if ((!dest) || (!dest_len) || (!source) || (!source_len))
- goto out;
-
- lrzip_init();
- lr = lrzip_new(LRZIP_MODE_DECOMPRESS);
- if (!lr)
- goto out;
- lrzip_config_env(lr);
-
- s = fmemopen((void*)source, source_len, "r");
- d = tmpfile();
- if ((!s) || (!d))
- goto out;
-
- if (!lrzip_file_add(lr, s))
- goto out;
- lrzip_outfile_set(lr, d);
- if (!lrzip_run(lr))
- goto out;
-
- fd = fileno(d);
- if (fstat(fd, &st))
- goto out;
- *dest_len = st.st_size;
- if (unlikely((i64)fread(dest, sizeof(char), st.st_size, d) != st.st_size))
- goto out;
- if (unlikely(ferror(d)))
- goto out;
- ret = true;
-
-out:
- if (s) fclose(s);
- if (d) fclose(d);
- lrzip_free(lr);
- return ret;
-}
diff --git a/liblrzip_demo.c b/liblrzip_demo.c
deleted file mode 100644
index 053439f..0000000
--- a/liblrzip_demo.c
+++ /dev/null
@@ -1,346 +0,0 @@
-/*
- Copyright (C) 2012 Con Kolivas
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-*/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-#undef NDEBUG
-#include
-#include
-#ifdef HAVE_STRING_H
-# include
-#endif
-#include
-#ifdef HAVE_ERRNO_H
-# include
-#else
-extern int errno;
-#endif
-#ifdef HAVE_UNISTD_H
-# include
-#endif
-#include
-#include
-
-#define failure(...) do { \
- fprintf(stderr, __VA_ARGS__); \
- exit(1); \
-} while (0)
-
-static void usage(void)
-{
- printf("lrzip version %s\n", PACKAGE_VERSION);
- printf("Copyright (C) Con Kolivas 2006-2011\n");
- printf("Based on rzip ");
- printf("Copyright (C) Andrew Tridgell 1998-2003\n\n");
- printf("Usage: lrzip [options] \n");
- printf("General options:\n");
- printf(" -c check integrity of file written on decompression\n");
- printf(" -d decompress\n");
- printf(" -e password protected sha512/aes128 encryption on compression\n");
- printf(" -h|-? show help\n");
- printf(" -H display md5 hash integrity information\n");
- printf(" -i show compressed file information\n");
- printf(" -q don't show compression progress\n");
- printf(" -t test compressed file integrity\n");
- printf(" -v[v] Increase verbosity\n");
- printf(" -V show version\n");
- printf("Options affecting output:\n");
- printf(" -D delete existing files\n");
- printf(" -f force overwrite of any existing files\n");
- printf(" -k keep broken or damaged output files\n");
- printf(" -o filename specify the output file name and/or path\n");
- printf(" -O directory specify the output directory when -o is not used\n");
- printf(" -S suffix specify compressed suffix (default '.lrz')\n");
- printf("Options affecting compression:\n");
- printf(" -b bzip2 compression\n");
- printf(" -g gzip compression using zlib\n");
- printf(" -l lzo compression (ultra fast)\n");
- printf(" -n no backend compression - prepare for other compressor\n");
- printf(" -z zpaq compression (best, extreme compression, extremely slow)\n");
- printf("Low level options:\n");
- printf(" -L level set lzma/bzip2/gzip compression level (1-9, default 7)\n");
- printf(" -N value Set nice value to value (default 19)\n");
- printf(" -p value Set processor count to override number of threads\n");
- printf(" -T Disable LZO compressibility testing\n");
- printf(" -U Use unlimited window size beyond ramsize (potentially much slower)\n");
- printf(" -w size maximum compression window in hundreds of MB\n");
- printf(" default chosen by heuristic dependent on ram and chosen compression\n");
- printf("\nLRZIP=NOCONFIG environment variable setting can be used to bypass lrzip.conf.\n");
- printf("TMP environment variable will be used for storage of temporary files when needed.\n");
- printf("TMPDIR may also be stored in lrzip.conf file.\n");
- printf("\nIf no filenames or \"-\" is specified, stdin/out will be used.\n");
-}
-
-static int get_pass(char *s, size_t slen)
-{
- int len;
-
- memset(s, 0, slen);
- if (!fgets(s, slen, stdin)) {
- fprintf(stderr, "Failed to retrieve passphrase\n");
- return -1;
- }
- len = strlen(s);
- if (len > 0 && ('\r' == s[len - 1] || '\n' == s[len - 1]))
- s[len - 1] = '\0';
- if (len > 1 && ('\r' == s[len - 2] || '\n' == s[len - 2]))
- s[len - 2] = '\0';
- len = strlen(s);
- if (!len) {
- fprintf(stderr, "Empty passphrase\n");
- return -1;
- }
- return len;
-}
-
-static void pass_cb(void *data __UNUSED__, char *pass_string, size_t pass_len)
-{
- int len;
- struct termios termios_p;
- /* Disable stdin echo to screen */
- tcgetattr(fileno(stdin), &termios_p);
- termios_p.c_lflag &= ~ECHO;
- tcsetattr(fileno(stdin), 0, &termios_p);
-
- printf("Enter passphrase: ");
- len = get_pass(pass_string, pass_len);
- printf("\n");
-
- if (len < 1) exit(1);
-
- termios_p.c_lflag |= ECHO;
- tcsetattr(fileno(stdin), 0, &termios_p);
-}
-
-static void mode_check(Lrzip *lr, Lrzip_Mode mode)
-{
- Lrzip_Mode current = lrzip_mode_get(lr);
- if (current && (current != mode))
- failure("Can only use one of -l, -b, -g, -z or -n\n");
- lrzip_mode_set(lr, mode);
-}
-
-int main(int argc, char *argv[])
-{
- Lrzip *lr;
- extern int optind;
- extern char *optarg;
- int64_t x;
- int c;
- bool get_hash = false;
-
- lrzip_init();
- lr = lrzip_new(LRZIP_MODE_NONE);
- assert(lr);
- lrzip_config_env(lr);
- lrzip_log_level_set(lr, LRZIP_LOG_LEVEL_PROGRESS);
- while ((c = getopt(argc, argv, "bcdDefghHiklL:nN:o:O:p:qS:tTUvVw:z?")) != -1) {
- switch (c) {
- case 'b':
- mode_check(lr, LRZIP_MODE_COMPRESS_BZIP2);
- break;
- case 'c':
- lrzip_flags_set(lr, lrzip_flags_get(lr) | LRZIP_FLAG_VERIFY);
- break;
- case 'd':
- mode_check(lr, LRZIP_MODE_DECOMPRESS);
- break;
- case 'D':
- lrzip_flags_set(lr, lrzip_flags_get(lr) | LRZIP_FLAG_REMOVE_SOURCE);
- break;
- case 'e':
- lrzip_flags_set(lr, lrzip_flags_get(lr) | LRZIP_FLAG_ENCRYPT);
- break;
- case 'f':
- lrzip_flags_set(lr, lrzip_flags_get(lr) | LRZIP_FLAG_REMOVE_DESTINATION);
- break;
- case 'g':
- mode_check(lr, LRZIP_MODE_COMPRESS_ZLIB);
- break;
- case 'h':
- case '?':
- usage();
- return -1;
- case 'H':
- get_hash = true;
- break;
- case 'i':
- mode_check(lr, LRZIP_MODE_INFO);
- break;
- case 'k':
- lrzip_flags_set(lr, lrzip_flags_get(lr) | LRZIP_FLAG_KEEP_BROKEN);
- break;
- case 'l':
- mode_check(lr, LRZIP_MODE_COMPRESS_LZO);
- break;
- case 'L':
- errno = 0;
- x = strtol(optarg, NULL, 10);
- if (errno || ((x < 1) || (x > 9)))
- failure("Invalid compression level (must be 1-9)\n");
- lrzip_compression_level_set(lr, (unsigned int)x);
- break;
- case 'n':
- mode_check(lr, LRZIP_MODE_COMPRESS_NONE);
- break;
- case 'N':
- errno = 0;
- x = strtol(optarg, NULL, 10);
- if (errno || (x < -20 || x > 19))
- failure("Invalid nice value (must be -20..19)\n");
- lrzip_nice_set(lr, x);
- break;
- case 'o':
- if (lrzip_outdir_get(lr))
- failure("Cannot have -o and -O together\n");
- if (!strcmp(optarg, "-"))
- lrzip_outfile_set(lr, stdout);
- else
- lrzip_outfilename_set(lr, optarg);
- break;
- case 'O':
- if (lrzip_outfilename_get(lr)) /* can't mix -o and -O */
- failure("Cannot have options -o and -O together\n");
- if (lrzip_outfile_get(lr))
- failure("Cannot specify an output directory when outputting to stdout\n");
- lrzip_outdir_set(lr, optarg);
- break;
- case 'p':
- errno = 0;
- x = strtol(optarg, NULL, 10);
- if (errno || (x < 1))
- failure("Must have at least one thread\n");
- lrzip_threads_set(lr, (unsigned int)x);
- break;
- case 'q':
- lrzip_log_level_set(lr, lrzip_log_level_get(lr) - 1);
- break;
- case 'S':
- if (lrzip_outfilename_get(lr))
- failure("Specified output filename already, can't specify an extension.\n");
- if (lrzip_outfile_get(lr))
- failure("Cannot specify a filename suffix when outputting to stdout\n");
- lrzip_suffix_set(lr, optarg);
- break;
- case 't':
- if (lrzip_outfilename_get(lr))
- failure("Cannot specify an output file name when just testing.\n");
- if (lrzip_flags_get(lr) & LRZIP_FLAG_REMOVE_SOURCE)
- failure("Doubt that you want to delete a file when just testing.\n");
- mode_check(lr, LRZIP_MODE_TEST);
- break;
- case 'T':
- lrzip_flags_set(lr, lrzip_flags_get(lr) | LRZIP_FLAG_DISABLE_LZO_CHECK);
- break;
- case 'U':
- lrzip_flags_set(lr, lrzip_flags_get(lr) | LRZIP_FLAG_UNLIMITED_RAM);
- break;
- case 'v':
- lrzip_log_level_set(lr, lrzip_log_level_get(lr) + 1);
- break;
- case 'V':
- printf("lrzip version %s\n", PACKAGE_VERSION);
- exit(0);
- break;
- case 'w':
- errno = 0;
- x = strtoll(optarg, NULL, 10);
- if (errno || (x < 1))
- failure("Invalid compression window '%s'!\n", optarg);
- lrzip_compression_window_max_set(lr, x);
- break;
- case 'z':
- mode_check(lr, LRZIP_MODE_COMPRESS_ZPAQ);
- break;
- }
- }
- /* LZMA is the default */
- if (!lrzip_mode_get(lr)) lrzip_mode_set(lr, LRZIP_MODE_COMPRESS_LZMA);
- argc -= optind, argv += optind;
-
- if (lrzip_outfilename_get(lr) && (argc > 1))
- failure("Cannot specify output filename with more than 1 file\n");
-
- if ((lrzip_flags_get(lr) & LRZIP_FLAG_UNLIMITED_RAM) && lrzip_compression_window_max_get(lr)) {
- fprintf(stderr, "If -U used, cannot specify a window size with -w.\n");
- lrzip_compression_window_max_set(lr, 0);
- }
-
- if (argc < 1) lrzip_file_add(lr, stdin);
-
- if ((lrzip_flags_get(lr) & LRZIP_FLAG_UNLIMITED_RAM) && lrzip_files_count(lr)) {
- fprintf(stderr, "Cannot have -U and stdin, unlimited mode disabled.\n");
- lrzip_flags_set(lr, lrzip_flags_get(lr) & ~LRZIP_FLAG_UNLIMITED_RAM);
- }
-
- /* If no output filename is specified, and we're using stdin,
- * use stdout */
- if (lrzip_files_count(lr) && (!lrzip_outfilename_get(lr)))
- lrzip_outfile_set(lr, stdout);
-
- if (lrzip_flags_get(lr) & LRZIP_FLAG_VERIFY) {
- if (lrzip_mode_get(lr) != LRZIP_MODE_DECOMPRESS) {
- fprintf(stderr, "Can only check file written on decompression.\n");
- lrzip_flags_set(lr, lrzip_flags_get(lr) & ~LRZIP_FLAG_VERIFY);
- } else if (lrzip_outfile_get(lr)) {
- fprintf(stderr, "Can't check file written when writing to stdout. Checking disabled.\n");
- lrzip_flags_set(lr, lrzip_flags_get(lr) & ~LRZIP_FLAG_VERIFY);
- }
- }
-
- for (x = 0; x < argc; x++) {
- if (argv[x][0] != '-') {
- assert(lrzip_filename_add(lr, argv[x]));
- continue;
- }
- if (argv[x][1] == 0) {
- assert(lrzip_file_add(lr, stdin));
- continue;
- }
- }
- if (argc == 1) {
- if (!lrzip_files_count(lr)) lrzip_file_add(lr, stdin);
- if (lrzip_filenames_count(lr)) {
- if (!lrzip_outfilename_get(lr)) {
- char *buf;
- const char *infile;
- size_t len;
-
- infile = lrzip_filenames_get(lr)[0];
- len = strlen(infile);
- buf = alloca(len + 8);
- if (!strcmp(infile + len - 4, ".lrz"))
- strcat(buf, infile);
- else
- sprintf(buf, "%s.out", infile);
- lrzip_outfilename_set(lr, buf);
- }
- } else if (!lrzip_outfile_get(lr)) lrzip_outfile_set(lr, stdout);
- }
- lrzip_log_stdout_set(lr, stdout);
- lrzip_log_stderr_set(lr, stderr);
- lrzip_pass_cb_set(lr, pass_cb, NULL);
- if (!lrzip_run(lr)) exit(1);
- if (get_hash) {
- const unsigned char *digest = lrzip_md5digest_get(lr);
- for (x = 0; x < 16; x++)
- fprintf(stdout, "%02x", digest[x] & 0xFF);
- }
- lrzip_free(lr);
- return 0;
-}
diff --git a/liblrzip_private.h b/liblrzip_private.h
deleted file mode 100644
index d3fa0de..0000000
--- a/liblrzip_private.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-#include
-#include
-
-#define INFILE_BUCKET_SIZE 10
-
-struct Lrzip
-{
- Lrzip_Mode mode;
- unsigned int flags;
- rzip_control *control;
-
- /* bucket allocation is used here to avoid frequent calls to realloc */
- char **infilenames;
- size_t infilename_idx;
- size_t infilename_buckets;
- FILE **infiles;
- size_t infile_idx;
- size_t infile_buckets;
-};