[git commit master] tar: handle "tar fx TARFILE" etc

Denys Vlasenko vda.linux at googlemail.com
Sat Oct 24 23:32:45 UTC 2009


commit: http://git.busybox.net/busybox/commit/?id=f645037ffb156dbca22296c1453f0b45383ff8ce
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
tar_main                                             702     751     +49

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 archival/tar.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/archival/tar.c b/archival/tar.c
index bd8e5dc..3c0ceb7 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -841,6 +841,33 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
 #if ENABLE_FEATURE_TAR_LONG_OPTIONS
 	applet_long_options = tar_longopts;
 #endif
+#if ENABLE_DESKTOP
+	if (argv[1][0] != '-') {
+		/* Compat:
+		 * 1st argument without dash handles options with parameters
+		 * differently from dashed one: it takes *next argv[i]*
+		 * as paramenter even if there are more chars in 1st argument:
+		 *  "tar fx TARFILE" - "x" is not taken as f's param
+		 *  but is interpreted as -x option
+		 *  "tar -xf TARFILE" - dashed equivalent of the above
+		 *  "tar -fx ..." - "x" is taken as f's param
+		 * getopt32 wouldn't handle 1st command correctly.
+		 * Unfortunately, people do use such commands.
+		 * We massage argv[1] to work around it by moving 'f'
+		 * to the end of the string.
+		 * More contrived "tar fCx TARFILE DIR" still fails,
+		 * but such commands are much less likely to be used.
+		 */
+		char *f = strchr(argv[1], 'f');
+		if (f) {
+			while (f[1] != '\0') {
+				*f = f[1];
+				f++;
+			}
+			*f = 'f';
+		}
+	}
+#endif
 	opt = getopt32(argv,
 		"txC:f:Opvk"
 		IF_FEATURE_TAR_CREATE(   "ch"  )
-- 
1.6.3.3



More information about the busybox-cvs mailing list