summaryrefslogtreecommitdiff
path: root/system/dash/posix-dashes.patch
blob: b852ec20c758a4e77b9d97ccbee8e2dff4ccf418 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
From 54485578e01017534dae30731f7682abadb38a09 Mon Sep 17 00:00:00 2001
From: наб <nabijaczleweli@nabijaczleweli.xyz>
Date: Wed, 4 Jan 2023 12:33:45 +0100
Subject: builtin: Ignore first -- in getopts per POSIX
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Issue 7, XCU, getopts, OPTIONS reads "None.",
and getopts isn't a special built-in listed in sexion 2.14 ‒
this means that XCU, 1. Introduction, 1.4 Utility Description Defaults,
OPTIONS, Default Behavior applies:
  Default Behavior: When this section is listed as "None.", it means
  that the implementation need not support any options. Standard
  utilities that do not accept options, but that do accept operands,
  shall recognize "--" as a first argument to be discarded.

Test with: getopts -- d: a
Correct output is no output, exit 1
Wrong output errors out with d: being an invalid argument name

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
 src/options.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/options.c b/src/options.c
index 3158498..2d4bd3b 100644
--- a/src/options.c
+++ b/src/options.c
@@ -409,6 +409,9 @@ getoptscmd(int argc, char **argv)
 {
 	char **optbase;
 
+	nextopt(nullstr);
+	argc -= argptr - argv - 1;
+	argv = argptr - 1;
 	if (argc < 3)
 		sh_error("Usage: getopts optstring var [arg...]");
 	else if (argc == 3) {
-- 
cgit 

From ba57b84b305dd16f9d3e0d798835a7e9e15454ae Mon Sep 17 00:00:00 2001
From: наб <nabijaczleweli@nabijaczleweli.xyz>
Date: Wed, 4 Jan 2023 12:35:13 +0100
Subject: builtin: Ignore first -- in type for consistency
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This appears to be the only remaining built-in that doesn't use
nextopt() to parse its arguments (and isn't forbidden from doing so) ‒
users expect to be able to do this, and it's nice to be consistent here.

Test with: type -- ls --
Correct output lists ls=/bin/ls, then --=ENOENT
Wrong output lists --=ENOENT, ls=/bin/ls, --=ENOENT

Fixes: https://bugs.debian.org/870317
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
 src/exec.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/exec.c b/src/exec.c
index d7a1f53..83cba94 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -766,11 +766,11 @@ unsetfunc(const char *name)
 int
 typecmd(int argc, char **argv)
 {
-	int i;
 	int err = 0;
 
-	for (i = 1; i < argc; i++) {
-		err |= describe_command(out1, argv[i], NULL, 1);
+	nextopt(nullstr);
+	while (*argptr) {
+		err |= describe_command(out1, *argptr++, NULL, 1);
 	}
 	return err;
 }
-- 
cgit