Issue 4804.  Add a function to test the validity of file descriptors on Windows, and stop using global runtime settings to silence the warnings / assertions.
diff --git a/Include/fileobject.h b/Include/fileobject.h
index 56cf40a..1fed47b 100644
--- a/Include/fileobject.h
+++ b/Include/fileobject.h
@@ -68,6 +68,17 @@
 */
 int _PyFile_SanitizeMode(char *mode);
 
+#if defined _MSC_VER && _MSC_VER >= 1400
+/* A routine to check if a file descriptor is valid on Windows.  Returns 0
+ * and sets errno to EBADF if it isn't.  This is to avoid Assertions
+ * from various functions in the Windows CRT beginning with
+ * Visual Studio 2005
+ */
+int _PyVerify_fd(int fd);
+#else
+#define _PyVerify_fd(A) (1) /* dummy */
+#endif
+
 #ifdef __cplusplus
 }
 #endif