Support tar -C, per bug #1176

-Erik
This commit is contained in:
Eric Andersen 2001-06-21 19:30:10 +00:00
parent 8a646dd293
commit 091781e20e
5 changed files with 42 additions and 19 deletions

View File

@ -1154,9 +1154,10 @@
"221 foobar closing connection\n" "221 foobar closing connection\n"
#define nslookup_trivial_usage \ #define nslookup_trivial_usage \
"[HOST]" "[HOST] [SERVER]"
#define nslookup_full_usage \ #define nslookup_full_usage \
"Queries the nameserver for the IP address of the given HOST" "Queries the nameserver for the IP address of the given HOST\n" \
"optionally using a specified DNS server"
#define nslookup_example_usage \ #define nslookup_example_usage \
"$ nslookup localhost\n" \ "$ nslookup localhost\n" \
"Server: default\n" \ "Server: default\n" \
@ -1469,10 +1470,10 @@
#define tar_trivial_usage \ #define tar_trivial_usage \
"-[" USAGE_TAR_CREATE("c") "xtvO] " \ "-[" USAGE_TAR_CREATE("c") "xtvO] " \
USAGE_TAR_EXCLUDE("[--exclude FILE] [-X FILE]") \ USAGE_TAR_EXCLUDE("[--exclude FILE] [-X FILE]") \
"[-f TARFILE] [FILE(s)] ..." "[-f TARFILE] [-C DIR] [FILE(s)] ..."
#define tar_full_usage \ #define tar_full_usage \
"Create, extract, or list files from a tar file.\n\n" \ "Create, extract, or list files from a tar file.\n\n" \
"Main operation mode:\n" \ "Options:\n" \
USAGE_TAR_CREATE("\tc\t\tcreate\n") \ USAGE_TAR_CREATE("\tc\t\tcreate\n") \
"\tx\t\textract\n" \ "\tx\t\textract\n" \
"\tt\t\tlist\n" \ "\tt\t\tlist\n" \
@ -1483,7 +1484,7 @@
"\texclude\t\tfile to exclude\n" \ "\texclude\t\tfile to exclude\n" \
"\tX\t\tfile with names to exclude\n" \ "\tX\t\tfile with names to exclude\n" \
) \ ) \
"\nInformative output:\n" \ "\tC\t\tchange to directory DIR before operation\n" \
"\tv\t\tverbosely list files processed" "\tv\t\tverbosely list files processed"
#define tar_example_usage \ #define tar_example_usage \
"$ zcat /tmp/tarball.tar.gz | tar -xf -\n" \ "$ zcat /tmp/tarball.tar.gz | tar -xf -\n" \

View File

@ -151,6 +151,7 @@ extern int tar_main(int argc, char **argv)
char** excludeList=NULL; char** excludeList=NULL;
char** extractList=NULL; char** extractList=NULL;
const char *tarName="-"; const char *tarName="-";
const char *cwd=NULL;
#if defined BB_FEATURE_TAR_EXCLUDE #if defined BB_FEATURE_TAR_EXCLUDE
int excludeListSize=0; int excludeListSize=0;
FILE *fileList; FILE *fileList;
@ -181,9 +182,9 @@ extern int tar_main(int argc, char **argv)
while ( while (
#ifndef BB_FEATURE_TAR_EXCLUDE #ifndef BB_FEATURE_TAR_EXCLUDE
(opt = getopt(argc, argv, "cxtzvOf:p")) (opt = getopt(argc, argv, "cxtzvOf:pC:"))
#else #else
(opt = getopt_long(argc, argv, "cxtzvOf:X:p", longopts, NULL)) (opt = getopt_long(argc, argv, "cxtzvOf:X:pC:", longopts, NULL))
#endif #endif
> 0) { > 0) {
switch (opt) { switch (opt) {
@ -240,6 +241,13 @@ extern int tar_main(int argc, char **argv)
#endif #endif
case 'p': case 'p':
break; break;
case 'C':
cwd = xgetcwd((char *)cwd);
if (chdir(optarg)) {
printf("cd: %s: %s\n", optarg, strerror(errno));
return EXIT_FAILURE;
}
break;
default: default:
show_usage(); show_usage();
} }
@ -292,6 +300,8 @@ extern int tar_main(int argc, char **argv)
#endif #endif
} }
if (cwd)
chdir(cwd);
if (status == TRUE) if (status == TRUE)
return EXIT_SUCCESS; return EXIT_SUCCESS;
else else

View File

@ -1154,9 +1154,10 @@
"221 foobar closing connection\n" "221 foobar closing connection\n"
#define nslookup_trivial_usage \ #define nslookup_trivial_usage \
"[HOST]" "[HOST] [SERVER]"
#define nslookup_full_usage \ #define nslookup_full_usage \
"Queries the nameserver for the IP address of the given HOST" "Queries the nameserver for the IP address of the given HOST\n" \
"optionally using a specified DNS server"
#define nslookup_example_usage \ #define nslookup_example_usage \
"$ nslookup localhost\n" \ "$ nslookup localhost\n" \
"Server: default\n" \ "Server: default\n" \
@ -1469,10 +1470,10 @@
#define tar_trivial_usage \ #define tar_trivial_usage \
"-[" USAGE_TAR_CREATE("c") "xtvO] " \ "-[" USAGE_TAR_CREATE("c") "xtvO] " \
USAGE_TAR_EXCLUDE("[--exclude FILE] [-X FILE]") \ USAGE_TAR_EXCLUDE("[--exclude FILE] [-X FILE]") \
"[-f TARFILE] [FILE(s)] ..." "[-f TARFILE] [-C DIR] [FILE(s)] ..."
#define tar_full_usage \ #define tar_full_usage \
"Create, extract, or list files from a tar file.\n\n" \ "Create, extract, or list files from a tar file.\n\n" \
"Main operation mode:\n" \ "Options:\n" \
USAGE_TAR_CREATE("\tc\t\tcreate\n") \ USAGE_TAR_CREATE("\tc\t\tcreate\n") \
"\tx\t\textract\n" \ "\tx\t\textract\n" \
"\tt\t\tlist\n" \ "\tt\t\tlist\n" \
@ -1483,7 +1484,7 @@
"\texclude\t\tfile to exclude\n" \ "\texclude\t\tfile to exclude\n" \
"\tX\t\tfile with names to exclude\n" \ "\tX\t\tfile with names to exclude\n" \
) \ ) \
"\nInformative output:\n" \ "\tC\t\tchange to directory DIR before operation\n" \
"\tv\t\tverbosely list files processed" "\tv\t\tverbosely list files processed"
#define tar_example_usage \ #define tar_example_usage \
"$ zcat /tmp/tarball.tar.gz | tar -xf -\n" \ "$ zcat /tmp/tarball.tar.gz | tar -xf -\n" \

14
tar.c
View File

@ -151,6 +151,7 @@ extern int tar_main(int argc, char **argv)
char** excludeList=NULL; char** excludeList=NULL;
char** extractList=NULL; char** extractList=NULL;
const char *tarName="-"; const char *tarName="-";
const char *cwd=NULL;
#if defined BB_FEATURE_TAR_EXCLUDE #if defined BB_FEATURE_TAR_EXCLUDE
int excludeListSize=0; int excludeListSize=0;
FILE *fileList; FILE *fileList;
@ -181,9 +182,9 @@ extern int tar_main(int argc, char **argv)
while ( while (
#ifndef BB_FEATURE_TAR_EXCLUDE #ifndef BB_FEATURE_TAR_EXCLUDE
(opt = getopt(argc, argv, "cxtzvOf:p")) (opt = getopt(argc, argv, "cxtzvOf:pC:"))
#else #else
(opt = getopt_long(argc, argv, "cxtzvOf:X:p", longopts, NULL)) (opt = getopt_long(argc, argv, "cxtzvOf:X:pC:", longopts, NULL))
#endif #endif
> 0) { > 0) {
switch (opt) { switch (opt) {
@ -240,6 +241,13 @@ extern int tar_main(int argc, char **argv)
#endif #endif
case 'p': case 'p':
break; break;
case 'C':
cwd = xgetcwd((char *)cwd);
if (chdir(optarg)) {
printf("cd: %s: %s\n", optarg, strerror(errno));
return EXIT_FAILURE;
}
break;
default: default:
show_usage(); show_usage();
} }
@ -292,6 +300,8 @@ extern int tar_main(int argc, char **argv)
#endif #endif
} }
if (cwd)
chdir(cwd);
if (status == TRUE) if (status == TRUE)
return EXIT_SUCCESS; return EXIT_SUCCESS;
else else

11
usage.h
View File

@ -1154,9 +1154,10 @@
"221 foobar closing connection\n" "221 foobar closing connection\n"
#define nslookup_trivial_usage \ #define nslookup_trivial_usage \
"[HOST]" "[HOST] [SERVER]"
#define nslookup_full_usage \ #define nslookup_full_usage \
"Queries the nameserver for the IP address of the given HOST" "Queries the nameserver for the IP address of the given HOST\n" \
"optionally using a specified DNS server"
#define nslookup_example_usage \ #define nslookup_example_usage \
"$ nslookup localhost\n" \ "$ nslookup localhost\n" \
"Server: default\n" \ "Server: default\n" \
@ -1469,10 +1470,10 @@
#define tar_trivial_usage \ #define tar_trivial_usage \
"-[" USAGE_TAR_CREATE("c") "xtvO] " \ "-[" USAGE_TAR_CREATE("c") "xtvO] " \
USAGE_TAR_EXCLUDE("[--exclude FILE] [-X FILE]") \ USAGE_TAR_EXCLUDE("[--exclude FILE] [-X FILE]") \
"[-f TARFILE] [FILE(s)] ..." "[-f TARFILE] [-C DIR] [FILE(s)] ..."
#define tar_full_usage \ #define tar_full_usage \
"Create, extract, or list files from a tar file.\n\n" \ "Create, extract, or list files from a tar file.\n\n" \
"Main operation mode:\n" \ "Options:\n" \
USAGE_TAR_CREATE("\tc\t\tcreate\n") \ USAGE_TAR_CREATE("\tc\t\tcreate\n") \
"\tx\t\textract\n" \ "\tx\t\textract\n" \
"\tt\t\tlist\n" \ "\tt\t\tlist\n" \
@ -1483,7 +1484,7 @@
"\texclude\t\tfile to exclude\n" \ "\texclude\t\tfile to exclude\n" \
"\tX\t\tfile with names to exclude\n" \ "\tX\t\tfile with names to exclude\n" \
) \ ) \
"\nInformative output:\n" \ "\tC\t\tchange to directory DIR before operation\n" \
"\tv\t\tverbosely list files processed" "\tv\t\tverbosely list files processed"
#define tar_example_usage \ #define tar_example_usage \
"$ zcat /tmp/tarball.tar.gz | tar -xf -\n" \ "$ zcat /tmp/tarball.tar.gz | tar -xf -\n" \