shithub: scc

Download patch

ref: 38016d871780c343aeba12f9ab10f9c59224b5e4
parent: bb3a3db29db8b3c84e54aa820fe3f37b2b979794
author: Hiltjo Posthuma <hiltjo@codemadness.org>
date: Mon Feb 26 08:48:24 EST 2018

libc: fopen(), allow for example r+b and rb+

--- a/lib/c/_fpopen.c
+++ b/lib/c/_fpopen.c
@@ -14,14 +14,25 @@
 
 	flags = rw = bin = 0;
 
-	if (mode[0] == '\0)
+	if (mode[0] == '\0')
 		goto einval;
-	if (mode[i = 1] == '+')
-		i++, rw = 1;
-	if (mode[i] == 'b')
-		i++, bin = 1;
-	if (mode[i] != '\0')
-		goto einval;
+
+	for (i = 1; mode[i]; ++i) {
+		switch (mode[i]) {
+		case '+':
+			if (rw)
+				goto einval;
+			rw = 1;
+			break;
+		case 'b':
+			if (bin)
+				goto einval;
+			bin = 1;
+			break;
+		default:
+			goto einval;
+		}
+	}
 
 	switch (mode[0]) {
 	case 'a':