+
+#define TAR_OPT_UNCOMPRESS (1 << (TAR_OPT_AFTER_GZIP))
+#ifdef CONFIG_FEATURE_TAR_COMPRESS
+# define TAR_OPT_STR_COMPRESS "Z"
+# define TAR_OPT_AFTER_COMPRESS TAR_OPT_AFTER_GZIP + 1
+#else
+# define TAR_OPT_STR_COMPRESS ""
+# define TAR_OPT_AFTER_COMPRESS TAR_OPT_AFTER_GZIP
+#endif
+
+#define TAR_OPT_NOPRESERVE_OWN (1 << (TAR_OPT_AFTER_COMPRESS))
+#define TAR_OPT_NOPRESERVE_PERM (1 << (TAR_OPT_AFTER_COMPRESS + 1))
+#define TAR_OPT_STR_NOPRESERVE "\203\213"
+#define TAR_OPT_AFTER_NOPRESERVE TAR_OPT_AFTER_COMPRESS + 2
+
+static const char tar_options[]="txC:f:Opvk" \
+ TAR_OPT_STR_CREATE \
+ TAR_OPT_STR_BZIP2 \
+ TAR_OPT_STR_LZMA \
+ TAR_OPT_STR_FROM \
+ TAR_OPT_STR_GZIP \
+ TAR_OPT_STR_COMPRESS \
+ TAR_OPT_STR_NOPRESERVE;
+
+#ifdef CONFIG_FEATURE_TAR_LONG_OPTIONS
+static const struct option tar_long_options[] = {
+ { "list", 0, NULL, 't' },
+ { "extract", 0, NULL, 'x' },
+ { "directory", 1, NULL, 'C' },
+ { "file", 1, NULL, 'f' },
+ { "to-stdout", 0, NULL, 'O' },
+ { "same-permissions", 0, NULL, 'p' },
+ { "verbose", 0, NULL, 'v' },
+ { "keep-old", 0, NULL, 'k' },
+ { "no-same-owner", 0, NULL, '\203' },
+ { "no-same-permissions",0, NULL, '\213' },
+# ifdef CONFIG_FEATURE_TAR_CREATE
+ { "create", 0, NULL, 'c' },
+ { "dereference", 0, NULL, 'h' },
+# endif
+# ifdef CONFIG_FEATURE_TAR_BZIP2
+ { "bzip2", 0, NULL, 'j' },
+# endif
+# ifdef CONFIG_FEATURE_TAR_LZMA
+ { "lzma", 0, NULL, 'a' },
+# endif
+# ifdef CONFIG_FEATURE_TAR_FROM
+ { "files-from", 1, NULL, 'T' },
+ { "exclude-from", 1, NULL, 'X' },
+ { "exclude", 1, NULL, '\n' },
+# endif
+# ifdef CONFIG_FEATURE_TAR_GZIP
+ { "gzip", 0, NULL, 'z' },
+# endif
+# ifdef CONFIG_FEATURE_TAR_COMPRESS
+ { "compress", 0, NULL, 'Z' },
+# endif
+ { 0, 0, 0, 0 }
+};
+#else
+#define tar_long_options 0
+#endif
+
+int tar_main(int argc, char **argv)
+{
+ char (*get_header_ptr)(archive_handle_t *) = get_header_tar;
+ archive_handle_t *tar_handle;
+ char *base_dir = NULL;
+ const char *tar_filename = "-";
+ unsigned long opt;
+ llist_t *excludes = NULL;
+
+ /* Initialise default values */
+ tar_handle = init_handle();
+ tar_handle->flags = ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
+
+ /* Prepend '-' to the first argument if required */
+ bb_opt_complementally = ENABLE_FEATURE_TAR_CREATE ?
+ "--:X::T::\n::c:t:x:?:c--tx:t--cx:x--ct" :
+ "--:X::T::\n::t:x:?:t--x:x--t";
+ if (ENABLE_FEATURE_TAR_LONG_OPTIONS)
+ bb_applet_long_options = tar_long_options;
+ opt = bb_getopt_ulflags(argc, argv, tar_options,
+ &base_dir, /* Change to dir <optarg> */
+ &tar_filename /* archive filename */
+#ifdef CONFIG_FEATURE_TAR_FROM
+ , &(tar_handle->accept),
+ &(tar_handle->reject),
+ &excludes