From 3ae6f64de52889a26eb1c39a7743a58690d63163 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Tue, 8 Jan 2019 21:42:16 -0500 Subject: [PATCH] Fix popen bug. --- src/core/io.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/io.c b/src/core/io.c index 7baa39ce..221a3ce3 100644 --- a/src/core/io.c +++ b/src/core/io.c @@ -112,16 +112,18 @@ static Janet janet_io_popen(int32_t argc, Janet *argv) { janet_arity(argc, 1, 2); const uint8_t *fname = janet_getstring(argv, 0); const uint8_t *fmode = NULL; + int flags; if (argc == 2) { fmode = janet_getkeyword(argv, 1); if (janet_string_length(fmode) != 1 || !(fmode[0] == 'r' || fmode[0] == 'w')) { janet_panicf("invalid file mode :%S, expected :r or :w", fmode); } + flags = IO_PIPED | (fmode[0] == 'r' ? IO_READ : IO_WRITE); + } else { + fmode = (const uint8_t *)"r"; + flags = IO_PIPED | IO_READ; } - int flags = (fmode && fmode[0] == '2') - ? IO_PIPED | IO_WRITE - : IO_PIPED | IO_READ; #ifdef JANET_WINDOWS #define popen _popen #endif