Add check mode for io.open. #57

This commit is contained in:
Enyby
2019-10-19 20:53:56 +03:00
parent dbab0aed01
commit 5609d8c92b

View File

@@ -583,6 +583,17 @@ public class IoLib extends TwoArgFunction {
} }
private File rawopenfile(int filetype, String filename, String mode) throws IOException { private File rawopenfile(int filetype, String filename, String mode) throws IOException {
int len = mode.length();
for (int i = 0; i < len; i++) { // [rwa][+]?b*
char ch = mode.charAt(i);
if (i == 0 && "rwa".indexOf(ch) >= 0) continue;
if (i == 1 && ch == '+') continue;
if (i >= 1 && ch == 'b') continue;
len = -1;
break;
}
if (len <= 0) argerror(2, "invalid mode: '" + mode + "'");
switch (filetype) { switch (filetype) {
case FTYPE_STDIN: return wrapStdin(); case FTYPE_STDIN: return wrapStdin();
case FTYPE_STDOUT: return wrapStdout(); case FTYPE_STDOUT: return wrapStdout();