coreutils forbids this combination.

Signed-off-by: Xabier Oneca <[email protected]>
---
 coreutils/touch.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/coreutils/touch.c b/coreutils/touch.c
index a00ee0ba4..6a4ffb400 100644
--- a/coreutils/touch.c
+++ b/coreutils/touch.c
@@ -124,14 +124,18 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
      * accepted data format differs a bit between -d and -t.
      * We accept the same formats for both
      */
-    opts = getopt32long(argv, "c" IF_FEATURE_TOUCH_NODEREF("h")
-                IF_FEATURE_TOUCH_SUSV3("r:d:t:am")
-                /*ignored:*/ "f" IF_NOT_FEATURE_TOUCH_SUSV3("am"),
-                touch_longopts
+    opts = getopt32long(argv, "^"
+        "c" IF_FEATURE_TOUCH_NODEREF("h")
+        IF_FEATURE_TOUCH_SUSV3("r:d:t:am")
+        /*ignored:*/ "f" IF_NOT_FEATURE_TOUCH_SUSV3("am")
+        "\0" /* opt_complementary: */
+        /* coreutils forbids -r and -t at once: */
IF_FEATURE_TOUCH_SUSV3("r--t:t--r")
+        /* but allows these combinations: "r--d:d--r:t--d:d--t" */,
+        touch_longopts
 #if ENABLE_FEATURE_TOUCH_SUSV3
-                , &reference_file
-                , &date_str
-                , &date_str
+        , &reference_file
+        , &date_str
+        , &date_str
 #endif
     );

--
2.30.2
From 42c43242d362ae8c62afc15226a641e35c2c00d2 Mon Sep 17 00:00:00 2001
From: Xabier Oneca <[email protected]>
Date: Sat, 10 Apr 2021 00:11:46 +0200
Subject: [PATCH 2/3] touch: prevent usage of -r and -t at once

coreutils forbids this combination.

Signed-off-by: Xabier Oneca <[email protected]>
---
 coreutils/touch.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/coreutils/touch.c b/coreutils/touch.c
index a00ee0ba4..6a4ffb400 100644
--- a/coreutils/touch.c
+++ b/coreutils/touch.c
@@ -124,14 +124,18 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
 	 * accepted data format differs a bit between -d and -t.
 	 * We accept the same formats for both
 	 */
-	opts = getopt32long(argv, "c" IF_FEATURE_TOUCH_NODEREF("h")
-				IF_FEATURE_TOUCH_SUSV3("r:d:t:am")
-				/*ignored:*/ "f" IF_NOT_FEATURE_TOUCH_SUSV3("am"),
-				touch_longopts
+	opts = getopt32long(argv, "^"
+		"c" IF_FEATURE_TOUCH_NODEREF("h")
+		IF_FEATURE_TOUCH_SUSV3("r:d:t:am")
+		/*ignored:*/ "f" IF_NOT_FEATURE_TOUCH_SUSV3("am")
+		"\0" /* opt_complementary: */
+		/* coreutils forbids -r and -t at once: */ IF_FEATURE_TOUCH_SUSV3("r--t:t--r")
+		/* but allows these combinations: "r--d:d--r:t--d:d--t" */,
+		touch_longopts
 #if ENABLE_FEATURE_TOUCH_SUSV3
-				, &reference_file
-				, &date_str
-				, &date_str
+		, &reference_file
+		, &date_str
+		, &date_str
 #endif
 	);
 
-- 
2.30.2

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to