Support tar -C, per bug #1176
-Erik
diff --git a/archival/tar.c b/archival/tar.c
index 8dec434..55fb12c 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -151,6 +151,7 @@
char** excludeList=NULL;
char** extractList=NULL;
const char *tarName="-";
+ const char *cwd=NULL;
#if defined BB_FEATURE_TAR_EXCLUDE
int excludeListSize=0;
FILE *fileList;
@@ -181,9 +182,9 @@
while (
#ifndef BB_FEATURE_TAR_EXCLUDE
- (opt = getopt(argc, argv, "cxtzvOf:p"))
+ (opt = getopt(argc, argv, "cxtzvOf:pC:"))
#else
- (opt = getopt_long(argc, argv, "cxtzvOf:X:p", longopts, NULL))
+ (opt = getopt_long(argc, argv, "cxtzvOf:X:pC:", longopts, NULL))
#endif
> 0) {
switch (opt) {
@@ -240,6 +241,13 @@
#endif
case 'p':
break;
+ case 'C':
+ cwd = xgetcwd((char *)cwd);
+ if (chdir(optarg)) {
+ printf("cd: %s: %s\n", optarg, strerror(errno));
+ return EXIT_FAILURE;
+ }
+ break;
default:
show_usage();
}
@@ -292,6 +300,8 @@
#endif
}
+ if (cwd)
+ chdir(cwd);
if (status == TRUE)
return EXIT_SUCCESS;
else