diff --git a/py/stream.c b/py/stream.c
index f51f634b6fb6e73b085246a4b1e55d16352b31fb..393988d2c151553042c0b30933dbfef3100f8eb4 100644
--- a/py/stream.c
+++ b/py/stream.c
@@ -32,13 +32,6 @@
 #include "py/stream.h"
 #include "py/runtime.h"
 
-#if MICROPY_STREAMS_NON_BLOCK
-#include <errno.h>
-#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
-#define EWOULDBLOCK 140
-#endif
-#endif
-
 // This file defines generic Python stream read/write methods which
 // dispatch to the underlying stream interface of an object.
 
diff --git a/py/stream.h b/py/stream.h
index a7d8d08f1466ae3d462b82e628ea54981d412e7a..a1d1c4f8af73d1cfb77d6f122b8523305de1803b 100644
--- a/py/stream.h
+++ b/py/stream.h
@@ -107,7 +107,7 @@ int mp_stream_posix_fsync(mp_obj_t stream);
 #endif
 
 #if MICROPY_STREAMS_NON_BLOCK
-#define mp_is_nonblocking_error(errno) ((errno) == EAGAIN || (errno) == EWOULDBLOCK)
+#define mp_is_nonblocking_error(errno) ((errno) == MP_EAGAIN || (errno) == MP_EWOULDBLOCK)
 #else
 #define mp_is_nonblocking_error(errno) (0)
 #endif