[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH v2 2/2] hush: implement -d DELIM option for `read`
From:       Johannes Schindelin <johannes.schindelin () gmx ! de>
Date:       2017-08-08 14:46:42
Message-ID: 3820e4a7354e5dc8166fa622a14e716c74a9b2dc.1502203583.git.johannes.schindelin () gmx ! de
[Download RAW message or body]

The POSIX standard only requires the `read` builtin to handle `-r`:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/read.html

However, Bash introduced the option `-d <DELIM>` to override IFS for
just one invocation, and it is quite useful.

We already support this in ash, let's add it to hush, too.

function                                             old     new   delta
builtin_read                                         263     284     +21
.rodata                                           163587  163589      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 23/0)               Total: 23 bytes

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 shell/hush.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/shell/hush.c b/shell/hush.c
index d4e647fc0..278b44a9c 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -352,6 +352,7 @@
 #define BASH_SOURCE        ENABLE_HUSH_BASH_COMPAT
 #define BASH_HOSTNAME_VAR  ENABLE_HUSH_BASH_COMPAT
 #define BASH_TEST2         (ENABLE_HUSH_BASH_COMPAT && ENABLE_HUSH_TEST)
+#define BASH_READ_D        ENABLE_HUSH_BASH_COMPAT
 
 
 /* Build knobs */
@@ -9434,13 +9435,27 @@ static int FAST_FUNC builtin_read(char **argv)
 	char *opt_p = NULL;
 	char *opt_t = NULL;
 	char *opt_u = NULL;
+#if BASH_READ_D
+	char *opt_d = NULL;
+#endif
 	const char *ifs;
 	int read_flags;
 
 	/* "!": do not abort on errors.
 	 * Option string must start with "sr" to match BUILTIN_READ_xxx
 	 */
-	read_flags = getopt32(argv, "!srn:p:t:u:", &opt_n, &opt_p, &opt_t, &opt_u);
+	read_flags = getopt32(argv,
+#if BASH_READ_D
+        "!srn:p:t:u:d:",
+#else
+        "!srn:p:t:u:",
+#endif
+        &opt_n, &opt_p, &opt_t,
+		&opt_u
+#if BASH_READ_D
+        , &opt_d
+#endif
+      );
 	if (read_flags == (uint32_t)-1)
 		return EXIT_FAILURE;
 	argv += optind;
@@ -9455,7 +9470,11 @@ static int FAST_FUNC builtin_read(char **argv)
 		opt_p,
 		opt_t,
 		opt_u,
+#if BASH_READ_D
+		opt_d
+#else
         NULL
+#endif
 	);
 
 	if ((uintptr_t)r == 1 && errno == EINTR) {
-- 
2.14.0.windows.1.2.g0f3342804fc
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic