[hackers] [PATCH] tar: if first argument doesn't have a leading dash, prepend one

From: Ethan Sommer <e5ten.arch_AT_gmail.com>
Date: Fri, 15 May 2020 20:24:23 -0400

this allows tar to be called in the common form "tar <key>" instead of only
allowing "tar -<key>"
---
 tar.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/tar.c b/tar.c
index 603e544..759402e 100644
--- a/tar.c
+++ b/tar.c
_AT_@ -520,6 +520,12 @@ main(int argc, char *argv[])
 	char *file = NULL, *dir = ".", mode = '\0';
 	int fd;
 
+	if (argc >= 2 && argv[1][0] != '-') {
+		char *argv1 = emalloc(strlen(argv[1] + 2));
+		sprintf(argv1, "-%s", argv[1]);
+		argv[1] = argv1;
+	}
+
 	ARGBEGIN {
 	case 'x':
 	case 'c':
-- 
2.24.1
Received on Sat May 16 2020 - 02:24:23 CEST

This archive was generated by hypermail 2.3.0 : Sat May 16 2020 - 02:36:37 CEST