Long options handling (getopt32 vs getopt32long) is done in libb.h, no need to
care here of the same logic. This cleans the code a bit.

Also, --no-create was grouped as a SUSv3 option, where as the short -c was not.
Even if it is part of SUS, leave it out as was the short option.

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

diff --git a/coreutils/touch.c b/coreutils/touch.c
index db5076f1..28dcca51 100644
--- a/coreutils/touch.c
+++ b/coreutils/touch.c
@@ -97,23 +97,18 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
         OPT_m = (1 << 5) * ENABLE_FEATURE_TOUCH_SUSV3,
         OPT_h = (1 << 6) * ENABLE_FEATURE_TOUCH_NODEREF,
     };
-#if ENABLE_FEATURE_TOUCH_SUSV3
     /* NULL = use current time */
     const struct timeval *newtime = NULL;
-# if ENABLE_LONG_OPTS
+#if ENABLE_LONG_OPTS
     static const char touch_longopts[] ALIGN1 =
         /* name, has_arg, val */
         "no-create\0"         No_argument       "c"
-        "reference\0"         Required_argument "r"
-        "date\0"              Required_argument "d"
+        IF_FEATURE_TOUCH_SUSV3("reference\0"        Required_argument "r")
+        IF_FEATURE_TOUCH_SUSV3("date\0"             Required_argument "d")
         IF_FEATURE_TOUCH_NODEREF("no-dereference\0" No_argument "h")
     ;
-#  define GETOPT32 getopt32long
-#  define LONGOPTS ,touch_longopts
-# else
-#  define GETOPT32 getopt32
-#  define LONGOPTS
-# endif
+#endif
+#if ENABLE_FEATURE_TOUCH_SUSV3
     char *reference_file = NULL;
     char *date_str = NULL;
     /* timebuf[0] is atime, timebuf[1] is mtime */
@@ -123,17 +118,15 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
 # define reference_file NULL
 # define date_str       NULL
 # define timebuf        ((struct timeval*)NULL)
-# define GETOPT32 getopt32
-# define LONGOPTS
 #endif

     /* -d and -t both set time. In coreutils,
      * accepted data format differs a bit between -d and -t.
      * We accept the same formats for both */
-    opts = GETOPT32(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:am")
+    opts = getopt32long(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:am")
                 IF_FEATURE_TOUCH_NODEREF("h")
-                /*ignored:*/ "f"
-                LONGOPTS
+                /*ignored:*/ "f",
+                touch_longopts
                 IF_FEATURE_TOUCH_SUSV3(, &reference_file)
                 IF_FEATURE_TOUCH_SUSV3(, &date_str)
                 IF_FEATURE_TOUCH_SUSV3(, &date_str)
--
2.30.2
From 3b3ed3edf0bfc2f29a166570c563f24b6572730c Mon Sep 17 00:00:00 2001
From: Xabier Oneca <[email protected]>
Date: Thu, 8 Apr 2021 02:38:54 +0200
Subject: [PATCH 3/3] touch: remove unneeded GETOPT32 defines

Long options handling (getopt32 vs getopt32long) is done in libb.h, no need to
care here of the same logic. This cleans the code a bit.

Also, --no-create was grouped as a SUSv3 option, where as the short -c was not.
Even if it is part of SUS, leave it out as was the short option.

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

diff --git a/coreutils/touch.c b/coreutils/touch.c
index db5076f1..28dcca51 100644
--- a/coreutils/touch.c
+++ b/coreutils/touch.c
@@ -97,23 +97,18 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
 		OPT_m = (1 << 5) * ENABLE_FEATURE_TOUCH_SUSV3,
 		OPT_h = (1 << 6) * ENABLE_FEATURE_TOUCH_NODEREF,
 	};
-#if ENABLE_FEATURE_TOUCH_SUSV3
 	/* NULL = use current time */
 	const struct timeval *newtime = NULL;
-# if ENABLE_LONG_OPTS
+#if ENABLE_LONG_OPTS
 	static const char touch_longopts[] ALIGN1 =
 		/* name, has_arg, val */
 		"no-create\0"         No_argument       "c"
-		"reference\0"         Required_argument "r"
-		"date\0"              Required_argument "d"
+		IF_FEATURE_TOUCH_SUSV3("reference\0"        Required_argument "r")
+		IF_FEATURE_TOUCH_SUSV3("date\0"             Required_argument "d")
 		IF_FEATURE_TOUCH_NODEREF("no-dereference\0" No_argument "h")
 	;
-#  define GETOPT32 getopt32long
-#  define LONGOPTS ,touch_longopts
-# else
-#  define GETOPT32 getopt32
-#  define LONGOPTS
-# endif
+#endif
+#if ENABLE_FEATURE_TOUCH_SUSV3
 	char *reference_file = NULL;
 	char *date_str = NULL;
 	/* timebuf[0] is atime, timebuf[1] is mtime */
@@ -123,17 +118,15 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
 # define reference_file NULL
 # define date_str       NULL
 # define timebuf        ((struct timeval*)NULL)
-# define GETOPT32 getopt32
-# define LONGOPTS
 #endif
 
 	/* -d and -t both set time. In coreutils,
 	 * accepted data format differs a bit between -d and -t.
 	 * We accept the same formats for both */
-	opts = GETOPT32(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:am")
+	opts = getopt32long(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:am")
 				IF_FEATURE_TOUCH_NODEREF("h")
-				/*ignored:*/ "f"
-				LONGOPTS
+				/*ignored:*/ "f",
+				touch_longopts
 				IF_FEATURE_TOUCH_SUSV3(, &reference_file)
 				IF_FEATURE_TOUCH_SUSV3(, &date_str)
 				IF_FEATURE_TOUCH_SUSV3(, &date_str)
-- 
2.30.2

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

Reply via email to