Ports of lib9, libbio and libmach to Windows.

R=rsc
https://golang.org/cl/157159
diff --git a/include/libc.h b/include/libc.h
index 2eceaea..7b86399 100644
--- a/include/libc.h
+++ b/include/libc.h
@@ -137,12 +137,9 @@
 #define	ORDWR	2	/* read and write */
 #define	OEXEC	3	/* execute, == read but check execute permission */
 #define	OTRUNC	16	/* or'ed in (except for exec), truncate file first */
-#define	OCEXEC	32	/* or'ed in, close on exec */
 #define	ORCLOSE	64	/* or'ed in, remove on close */
 #define	ODIRECT	128	/* or'ed in, direct access */
-#define	ONONBLOCK 256	/* or'ed in, non-blocking call */
 #define	OEXCL	0x1000	/* or'ed in, exclusive use (create only) */
-#define	OLOCK	0x2000	/* or'ed in, lock after opening */
 #define	OAPPEND	0x4000	/* or'ed in, append only */
 
 #define	AEXIST	0	/* accessible: exists */
@@ -279,7 +276,6 @@
 extern	int	notifyoff(char*);
 extern	int	p9open(char*, int);
 extern	int	fd2path(int, char*, int);
-extern	int	p9pipe(int*);
 extern	long	readn(int, void*, long);
 extern	int	remove(const char*);
 extern	vlong	p9seek(int, vlong, int);
@@ -290,6 +286,18 @@
 extern	int	p9waitpid(void);
 extern	ulong	rendezvous(ulong, ulong);
 
+#ifdef __MINGW32__
+extern int fork();
+extern int pread(int fd, void *buf, int n, int off);
+extern int pwrite(int fd, void *buf, int n, int off);
+#define execvp(prog, argv) execvp(prog, (const char**)(argv))
+#define lseek(fd, n, base) _lseeki64(fd, n, base)
+#define mkdir(path, perm) mkdir(path)
+#define pipe(fd) _pipe(fd, 512, O_BINARY)
+#else
+#define O_BINARY 0
+#endif
+
 #ifndef NOPLAN9DEFINES
 #define alarm		p9alarm
 #define	dup		p9dup
@@ -303,7 +311,6 @@
 #define create		p9create
 #undef open
 #define open		p9open
-#define pipe		p9pipe
 #define	waitfor		p9waitfor
 #endif
 
diff --git a/include/u.h b/include/u.h
index 1b19628..6dd55a0 100644
--- a/include/u.h
+++ b/include/u.h
@@ -77,6 +77,9 @@
 #define _NEEDUINT 1
 #define _NEEDULONG 1
 
+#ifdef __MINGW32__
+typedef jmp_buf sigjmp_buf;
+#endif
 typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
 
 #if defined(__linux__)
@@ -135,6 +138,7 @@
 #	undef _NEEDUSHORT
 #	undef _NEEDUINT
 #	undef _NEEDULONG
+#elif defined(__MINGW32__)
 #else
 	/* No idea what system this is -- try some defaults */
 #	include <pthread.h>
@@ -199,7 +203,7 @@
  */
 #if defined(__GNUC__)
 #	undef strcmp	/* causes way too many warnings */
-#	if __GNUC__ >= 4 || (__GNUC__==3 && !defined(__APPLE_CC__))
+#	if __GNUC__ >= 4 || (__GNUC__==3 && !defined(__APPLE_CC__) && !defined(__MINGW32__))
 #		undef AUTOLIB
 #		define AUTOLIB(x) int __p9l_autolib_ ## x __attribute__ ((weak));
 #		undef AUTOFRAMEWORK