diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-05-27 14:52:08 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-05-30 17:49:40 +0200 |
commit | 4332c116b303e0f86aaac4ae0bf699db5744769d (patch) | |
tree | 045d3ec030ec16862c114ed31994c6cfd6bf9bb9 /bin/tar2sqfs/tar2sqfs.c | |
parent | 8aa0366b85ce621ec54637ab4f9d37ad1e636e8f (diff) |
Cleanup: try to split tar2sqfs.c in a reasonable way
This commit breaks tar2sqfs.c into multiple files:
- options.c contains the command line argument processing
- process_tarball.c contains the main tar repacking code
- tar2sqfs.c contains what is left (the main function)
- A header is added for gluing it all together.
No actual code is changed. The tar repacking code is slightly modified
to pass the sqfs writer and input file pointer around as argument rather
than using a global variable.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin/tar2sqfs/tar2sqfs.c')
-rw-r--r-- | bin/tar2sqfs/tar2sqfs.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/bin/tar2sqfs/tar2sqfs.c b/bin/tar2sqfs/tar2sqfs.c new file mode 100644 index 0000000..ae56e6b --- /dev/null +++ b/bin/tar2sqfs/tar2sqfs.c @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * tar2sqfs.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "tar2sqfs.h" + +int main(int argc, char **argv) +{ + int status = EXIT_FAILURE; + FILE *input_file = NULL; + sqfs_writer_t sqfs; + + process_args(argc, argv); + +#ifdef _WIN32 + _setmode(_fileno(stdin), _O_BINARY); + input_file = stdin; +#else + input_file = freopen(NULL, "rb", stdin); +#endif + + if (input_file == NULL) { + perror("changing stdin to binary mode"); + return EXIT_FAILURE; + } + + memset(&sqfs, 0, sizeof(sqfs)); + if (sqfs_writer_init(&sqfs, &cfg)) + return EXIT_FAILURE; + + if (process_tarball(input_file, &sqfs)) + goto out; + + if (fstree_post_process(&sqfs.fs)) + goto out; + + if (sqfs_writer_finish(&sqfs, &cfg)) + goto out; + + status = EXIT_SUCCESS; +out: + sqfs_writer_cleanup(&sqfs, status); + return status; +} |