X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=tar.c;h=7d440f451c7c51ac426751100e8bc0c3a9976cd5;hb=36fe1a30b1958351de2b8065cb19d3d1b8ed1b33;hp=0177d5188b51e18114505f3a3d7688c6154b40e5;hpb=1d1d95051a288b6bf64498aac9fb20047f384b7d;p=oweals%2Fbusybox.git diff --git a/tar.c b/tar.c index 0177d5188..7d440f451 100644 --- a/tar.c +++ b/tar.c @@ -49,7 +49,6 @@ #include #include #include -#include /* for PATH_MAX */ static const char tar_usage[] = @@ -61,8 +60,9 @@ static const char tar_usage[] = #if defined BB_FEATURE_TAR_EXCLUDE "[--exclude File] " #endif - "[-f tarFile] [FILE] ...\n\n" - "Create, extract, or list files from a tar file. Note that\n" + "[-f tarFile] [FILE] ...\n" +#ifndef BB_FEATURE_TRIVIAL_HELP + "\nCreate, extract, or list files from a tar file. Note that\n" "this version of tar treats hard links as separate files.\n\n" "Main operation mode:\n" #ifdef BB_FEATURE_TAR_CREATE @@ -78,6 +78,7 @@ static const char tar_usage[] = #endif "\nInformative output:\n" "\tv\t\tverbosely list files processed\n" +#endif ; /* Tar file constants */ @@ -172,7 +173,7 @@ extern int tar_main(int argc, char **argv) #if defined BB_FEATURE_TAR_EXCLUDE int excludeListSize=0; #endif - const char *tarName=NULL; + const char *tarName="-"; int listFlag = FALSE; int extractFlag = FALSE; int createFlag = FALSE; @@ -184,15 +185,15 @@ extern int tar_main(int argc, char **argv) usage(tar_usage); /* Parse any options */ - while (--argc > 0 && (**(++argv) != '\0')) { + while (--argc > 0 && strspn(*(++argv), "-cxt") >0 ) { stopIt=FALSE; - while (stopIt==FALSE && *(++(*argv))) { + while (stopIt==FALSE && *argv && **argv) { switch (**argv) { case 'f': if (--argc == 0) { fatalError( "Option requires an argument: No file specified\n"); } - if (tarName != NULL) + if (*tarName != '-') fatalError( "Only one 'f' option allowed\n"); tarName = *(++argv); if (tarName == NULL) @@ -251,6 +252,7 @@ extern int tar_main(int argc, char **argv) fatalError( "Unknown tar flag '%c'\n" "Try `tar --help' for more information\n", **argv); } + ++(*argv); } } @@ -264,7 +266,8 @@ extern int tar_main(int argc, char **argv) #else exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc, argv, excludeList)); #endif - } else { + } + if (listFlag == TRUE || extractFlag == TRUE) { exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag, excludeList)); }