Updated stdin/stdout treatment to match that of gnu tar.

This commit is contained in:
Matt Kraai 2000-09-15 22:47:34 +00:00
parent 6fc2a7d04d
commit b2f36af157
2 changed files with 12 additions and 18 deletions

View File

@ -133,8 +133,8 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
#ifdef BB_FEATURE_TAR_CREATE #ifdef BB_FEATURE_TAR_CREATE
/* Local procedures to save files into a tar file. */ /* Local procedures to save files into a tar file. */
static int writeTarFile(const char* tarName, int tostdoutFlag, static int writeTarFile(const char* tarName, int verboseFlag, int argc,
int verboseFlag, int argc, char **argv, char** excludeList); char **argv, char** excludeList);
#endif #endif
static struct option longopts[] = static struct option longopts[] =
@ -185,14 +185,11 @@ extern int tar_main(int argc, char **argv)
break; break;
case 'O': case 'O':
tostdoutFlag = TRUE; tostdoutFlag = TRUE;
tarName = "-";
break; break;
case 'f': case 'f':
if (*tarName != '-') if (*tarName != '-')
fatalError( "Only one 'f' option allowed\n"); fatalError( "Only one 'f' option allowed\n");
tarName = optarg; tarName = optarg;
if (!strcmp(tarName, "-") && createFlag == TRUE)
tostdoutFlag = TRUE;
break; break;
#if defined BB_FEATURE_TAR_EXCLUDE #if defined BB_FEATURE_TAR_EXCLUDE
case 'e': case 'e':
@ -218,7 +215,7 @@ extern int tar_main(int argc, char **argv)
#ifndef BB_FEATURE_TAR_CREATE #ifndef BB_FEATURE_TAR_CREATE
fatalError( "This version of tar was not compiled with tar creation support.\n"); fatalError( "This version of tar was not compiled with tar creation support.\n");
#else #else
exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc-optind, &argv[optind], excludeList)); exit(writeTarFile(tarName, verboseFlag, argc-optind, &argv[optind], excludeList));
#endif #endif
} }
if (listFlag == TRUE || extractFlag == TRUE) { if (listFlag == TRUE || extractFlag == TRUE) {
@ -922,8 +919,8 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
return( TRUE); return( TRUE);
} }
static int writeTarFile(const char* tarName, int tostdoutFlag, static int writeTarFile(const char* tarName, int verboseFlag, int argc,
int verboseFlag, int argc, char **argv, char** excludeList) char **argv, char** excludeList)
{ {
int tarFd=-1; int tarFd=-1;
int errorFlag=FALSE; int errorFlag=FALSE;
@ -936,7 +933,7 @@ static int writeTarFile(const char* tarName, int tostdoutFlag,
fatalError("Cowardly refusing to create an empty archive\n"); fatalError("Cowardly refusing to create an empty archive\n");
/* Open the tar file for writing. */ /* Open the tar file for writing. */
if (tostdoutFlag == TRUE) if (strcmp(tarName, "-") == 0)
tbInfo.tarFd = fileno(stdout); tbInfo.tarFd = fileno(stdout);
else else
tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644); tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644);

15
tar.c
View File

@ -133,8 +133,8 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
#ifdef BB_FEATURE_TAR_CREATE #ifdef BB_FEATURE_TAR_CREATE
/* Local procedures to save files into a tar file. */ /* Local procedures to save files into a tar file. */
static int writeTarFile(const char* tarName, int tostdoutFlag, static int writeTarFile(const char* tarName, int verboseFlag, int argc,
int verboseFlag, int argc, char **argv, char** excludeList); char **argv, char** excludeList);
#endif #endif
static struct option longopts[] = static struct option longopts[] =
@ -185,14 +185,11 @@ extern int tar_main(int argc, char **argv)
break; break;
case 'O': case 'O':
tostdoutFlag = TRUE; tostdoutFlag = TRUE;
tarName = "-";
break; break;
case 'f': case 'f':
if (*tarName != '-') if (*tarName != '-')
fatalError( "Only one 'f' option allowed\n"); fatalError( "Only one 'f' option allowed\n");
tarName = optarg; tarName = optarg;
if (!strcmp(tarName, "-") && createFlag == TRUE)
tostdoutFlag = TRUE;
break; break;
#if defined BB_FEATURE_TAR_EXCLUDE #if defined BB_FEATURE_TAR_EXCLUDE
case 'e': case 'e':
@ -218,7 +215,7 @@ extern int tar_main(int argc, char **argv)
#ifndef BB_FEATURE_TAR_CREATE #ifndef BB_FEATURE_TAR_CREATE
fatalError( "This version of tar was not compiled with tar creation support.\n"); fatalError( "This version of tar was not compiled with tar creation support.\n");
#else #else
exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc-optind, &argv[optind], excludeList)); exit(writeTarFile(tarName, verboseFlag, argc-optind, &argv[optind], excludeList));
#endif #endif
} }
if (listFlag == TRUE || extractFlag == TRUE) { if (listFlag == TRUE || extractFlag == TRUE) {
@ -922,8 +919,8 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
return( TRUE); return( TRUE);
} }
static int writeTarFile(const char* tarName, int tostdoutFlag, static int writeTarFile(const char* tarName, int verboseFlag, int argc,
int verboseFlag, int argc, char **argv, char** excludeList) char **argv, char** excludeList)
{ {
int tarFd=-1; int tarFd=-1;
int errorFlag=FALSE; int errorFlag=FALSE;
@ -936,7 +933,7 @@ static int writeTarFile(const char* tarName, int tostdoutFlag,
fatalError("Cowardly refusing to create an empty archive\n"); fatalError("Cowardly refusing to create an empty archive\n");
/* Open the tar file for writing. */ /* Open the tar file for writing. */
if (tostdoutFlag == TRUE) if (strcmp(tarName, "-") == 0)
tbInfo.tarFd = fileno(stdout); tbInfo.tarFd = fileno(stdout);
else else
tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644); tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644);