diff options
author | Damien George <damien.p.george@gmail.com> | 2020-03-04 12:39:55 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-03-04 12:39:55 +1100 |
commit | 3e0b46b9af8b7a6934b7ac68671ef8f55be2b848 (patch) | |
tree | e40459dfda7c52d9209228057a9efd4c32fd842d | |
parent | 9c07c973c18fbe2f44ae98cd51a4a6c532b600c7 (diff) |
unix/file: Don't raise OSError(EINVAL) on sys.stdin/out/err.flush().
sys.stdout.flush() is needed on CPython to flush the output, and the change
in this commit makes such an expression also work on MicroPython (although
MicroPython doesn't actual need to do any flushing).
-rw-r--r-- | ports/unix/file.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/ports/unix/file.c b/ports/unix/file.c index 0fe4f9878..ed05fe733 100644 --- a/ports/unix/file.c +++ b/ports/unix/file.c @@ -126,6 +126,13 @@ STATIC mp_uint_t fdfile_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, i int ret = fsync(o->fd); MP_THREAD_GIL_ENTER(); if (ret == -1) { + if (errno == EINVAL + && (o->fd == STDIN_FILENO || o->fd == STDOUT_FILENO || o->fd == STDERR_FILENO)) { + // fsync(stdin/stdout/stderr) may fail with EINVAL, but don't propagate that + // error out. Because data is not buffered by us, and stdin/out/err.flush() + // should just be a no-op. + return 0; + } *errcode = errno; return MP_STREAM_ERROR; } |