diff -Naur ocaml-unix-4.00.1/otherlibs/unix/accept.c ocaml-unix-4.01.0/otherlibs/unix/accept.c
--- ocaml-unix-4.00.1/otherlibs/unix/accept.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/accept.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: accept.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/access.c ocaml-unix-4.01.0/otherlibs/unix/access.c
--- ocaml-unix-4.00.1/otherlibs/unix/access.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/access.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: access.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/addrofstr.c ocaml-unix-4.01.0/otherlibs/unix/addrofstr.c
--- ocaml-unix-4.00.1/otherlibs/unix/addrofstr.c        2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/addrofstr.c        2012-10-15 19:50:56.000000000 +0200
@@ -11,9 +11,8 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: addrofstr.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
+#include <memory.h>
 #include <fail.h>
 #include "unixsupport.h"

@@ -24,6 +23,39 @@
 CAMLprim value unix_inet_addr_of_string(value s)
 {
 #if defined(HAS_IPV6)
+#ifdef _WIN32
+  CAMLparam1(s);
+  CAMLlocal1(vres);
+  struct addrinfo hints;
+  struct addrinfo * res;
+  int retcode;
+  memset(&hints, 0, sizeof(hints));
+  hints.ai_family = AF_UNSPEC;
+  hints.ai_flags = AI_NUMERICHOST;
+  retcode = getaddrinfo(String_val(s), NULL, &hints, &res);
+  if (retcode != 0) failwith("inet_addr_of_string");
+  switch (res->ai_addr->sa_family) {
+  case AF_INET:
+    {
+      vres =
+        alloc_inet_addr(&((struct sockaddr_in *) res->ai_addr)->sin_addr);
+      break;
+    }
+  case AF_INET6:
+    {
+      vres =
+        alloc_inet6_addr(&((struct sockaddr_in6 *) res->ai_addr)->sin6_addr);
+      break;
+    }
+  default:
+    {
+      freeaddrinfo(res);
+      failwith("inet_addr_of_string");
+    }
+  }
+  freeaddrinfo(res);
+  CAMLreturn (vres);
+#else
   struct in_addr address;
   struct in6_addr address6;
   if (inet_pton(AF_INET, String_val(s), &address) > 0)
@@ -32,6 +64,7 @@
     return alloc_inet6_addr(&address6);
   else
     failwith("inet_addr_of_string");
+#endif
 #elif defined(HAS_INET_ATON)
   struct in_addr address;
   if (inet_aton(String_val(s), &address) == 0)
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/alarm.c ocaml-unix-4.01.0/otherlibs/unix/alarm.c
--- ocaml-unix-4.00.1/otherlibs/unix/alarm.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/alarm.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: alarm.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/bind.c ocaml-unix-4.01.0/otherlibs/unix/bind.c
--- ocaml-unix-4.00.1/otherlibs/unix/bind.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/bind.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: bind.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <fail.h>
 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/chdir.c ocaml-unix-4.01.0/otherlibs/unix/chdir.c
--- ocaml-unix-4.00.1/otherlibs/unix/chdir.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/chdir.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: chdir.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/chmod.c ocaml-unix-4.01.0/otherlibs/unix/chmod.c
--- ocaml-unix-4.00.1/otherlibs/unix/chmod.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/chmod.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: chmod.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/chown.c ocaml-unix-4.01.0/otherlibs/unix/chown.c
--- ocaml-unix-4.00.1/otherlibs/unix/chown.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/chown.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: chown.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/chroot.c ocaml-unix-4.01.0/otherlibs/unix/chroot.c
--- ocaml-unix-4.00.1/otherlibs/unix/chroot.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/chroot.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: chroot.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/close.c ocaml-unix-4.01.0/otherlibs/unix/close.c
--- ocaml-unix-4.00.1/otherlibs/unix/close.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/close.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: close.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/closedir.c ocaml-unix-4.01.0/otherlibs/unix/closedir.c
--- ocaml-unix-4.00.1/otherlibs/unix/closedir.c 2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/closedir.c 2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: closedir.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"
 #include <errno.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/connect.c ocaml-unix-4.01.0/otherlibs/unix/connect.c
--- ocaml-unix-4.00.1/otherlibs/unix/connect.c  2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/connect.c  2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: connect.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <fail.h>
 #include <mlvalues.h>
 #include <signals.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/cst2constr.c ocaml-unix-4.01.0/otherlibs/unix/cst2constr.c
--- ocaml-unix-4.00.1/otherlibs/unix/cst2constr.c       2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/cst2constr.c       2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: cst2constr.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <fail.h>
 #include "cst2constr.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/cst2constr.h ocaml-unix-4.01.0/otherlibs/unix/cst2constr.h
--- ocaml-unix-4.00.1/otherlibs/unix/cst2constr.h       2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/cst2constr.h       2012-10-15 19:50:56.000000000 +0200
@@ -11,6 +11,4 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: cst2constr.h 11156 2011-07-27 14:17:02Z doligez $ */
-
 extern value cst_to_constr(int n, int * tbl, int size, int deflt);
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/cstringv.c ocaml-unix-4.01.0/otherlibs/unix/cstringv.c
--- ocaml-unix-4.00.1/otherlibs/unix/cstringv.c 2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/cstringv.c 2013-02-25 04:01:31.000000000 +0100
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: cstringv.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <memory.h>
 #include "unixsupport.h"
@@ -23,7 +21,7 @@
   mlsize_t size, i;

   size = Wosize_val(arg);
-  res = (char **) stat_alloc((size + 1) * sizeof(char *));
+  res = (char **) caml_stat_alloc((size + 1) * sizeof(char *));
   for (i = 0; i < size; i++) res[i] = String_val(Field(arg, i));
   res[size] = NULL;
   return res;
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/.depend ocaml-unix-4.01.0/otherlibs/unix/.depend
--- ocaml-unix-4.00.1/otherlibs/unix/.depend    2012-07-25 15:39:21.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/.depend    2013-08-15 18:13:16.000000000 +0200
@@ -12,7 +12,9 @@
 addrofstr.o: addrofstr.c ../../byterun/mlvalues.h \
   ../../byterun/compatibility.h ../../byterun/config.h \
   ../../byterun/../config/m.h ../../byterun/../config/s.h \
-  ../../byterun/misc.h ../../byterun/fail.h ../../byterun/mlvalues.h \
+  ../../byterun/misc.h ../../byterun/memory.h ../../byterun/gc.h \
+  ../../byterun/mlvalues.h ../../byterun/major_gc.h \
+  ../../byterun/freelist.h ../../byterun/minor_gc.h ../../byterun/fail.h \
   unixsupport.h socketaddr.h ../../byterun/misc.h
 alarm.o: alarm.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
   ../../byterun/config.h ../../byterun/../config/m.h \
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/dup2.c ocaml-unix-4.01.0/otherlibs/unix/dup2.c
--- ocaml-unix-4.00.1/otherlibs/unix/dup2.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/dup2.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: dup2.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/dup.c ocaml-unix-4.01.0/otherlibs/unix/dup.c
--- ocaml-unix-4.00.1/otherlibs/unix/dup.c      2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/dup.c      2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: dup.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/envir.c ocaml-unix-4.01.0/otherlibs/unix/envir.c
--- ocaml-unix-4.00.1/otherlibs/unix/envir.c    2011-09-05 11:25:26.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/envir.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: envir.c 11176 2011-09-05 09:25:26Z xclerc $ */
-
 #include <mlvalues.h>
 #include <alloc.h>

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/errmsg.c ocaml-unix-4.01.0/otherlibs/unix/errmsg.c
--- ocaml-unix-4.00.1/otherlibs/unix/errmsg.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/errmsg.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: errmsg.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <errno.h>
 #include <string.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/execv.c ocaml-unix-4.01.0/otherlibs/unix/execv.c
--- ocaml-unix-4.00.1/otherlibs/unix/execv.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/execv.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: execv.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <memory.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/execve.c ocaml-unix-4.01.0/otherlibs/unix/execve.c
--- ocaml-unix-4.00.1/otherlibs/unix/execve.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/execve.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: execve.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <memory.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/execvp.c ocaml-unix-4.01.0/otherlibs/unix/execvp.c
--- ocaml-unix-4.00.1/otherlibs/unix/execvp.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/execvp.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: execvp.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <memory.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/exit.c ocaml-unix-4.01.0/otherlibs/unix/exit.c
--- ocaml-unix-4.00.1/otherlibs/unix/exit.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/exit.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: exit.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/fchmod.c ocaml-unix-4.01.0/otherlibs/unix/fchmod.c
--- ocaml-unix-4.00.1/otherlibs/unix/fchmod.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/fchmod.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: fchmod.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fail.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/fchown.c ocaml-unix-4.01.0/otherlibs/unix/fchown.c
--- ocaml-unix-4.00.1/otherlibs/unix/fchown.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/fchown.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: fchown.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <fail.h>
 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/fcntl.c ocaml-unix-4.01.0/otherlibs/unix/fcntl.c
--- ocaml-unix-4.00.1/otherlibs/unix/fcntl.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/fcntl.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: fcntl.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <fail.h>
 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/fork.c ocaml-unix-4.01.0/otherlibs/unix/fork.c
--- ocaml-unix-4.00.1/otherlibs/unix/fork.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/fork.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: fork.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <debugger.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/ftruncate.c ocaml-unix-4.01.0/otherlibs/unix/ftruncate.c
--- ocaml-unix-4.00.1/otherlibs/unix/ftruncate.c        2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/ftruncate.c        2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: ftruncate.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <sys/types.h>
 #include <fail.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getaddrinfo.c ocaml-unix-4.01.0/otherlibs/unix/getaddrinfo.c
--- ocaml-unix-4.00.1/otherlibs/unix/getaddrinfo.c      2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getaddrinfo.c      2013-02-25 04:01:31.000000000 +0100
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getaddrinfo.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <string.h>
 #include <mlvalues.h>
 #include <alloc.h>
@@ -69,7 +67,7 @@
   if (len == 0) {
     node = NULL;
   } else {
-    node = stat_alloc(len + 1);
+    node = caml_stat_alloc(len + 1);
     strcpy(node, String_val(vnode));
   }
   /* Extract "service" parameter */
@@ -77,7 +75,7 @@
   if (len == 0) {
     serv = NULL;
   } else {
-    serv = stat_alloc(len + 1);
+    serv = caml_stat_alloc(len + 1);
     strcpy(serv, String_val(vserv));
   }
   /* Parse options, set hints */
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getcwd.c ocaml-unix-4.01.0/otherlibs/unix/getcwd.c
--- ocaml-unix-4.00.1/otherlibs/unix/getcwd.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getcwd.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getcwd.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getegid.c ocaml-unix-4.01.0/otherlibs/unix/getegid.c
--- ocaml-unix-4.00.1/otherlibs/unix/getegid.c  2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getegid.c  2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getegid.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/geteuid.c ocaml-unix-4.01.0/otherlibs/unix/geteuid.c
--- ocaml-unix-4.00.1/otherlibs/unix/geteuid.c  2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/geteuid.c  2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: geteuid.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getgid.c ocaml-unix-4.01.0/otherlibs/unix/getgid.c
--- ocaml-unix-4.00.1/otherlibs/unix/getgid.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getgid.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getgid.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getgr.c ocaml-unix-4.01.0/otherlibs/unix/getgr.c
--- ocaml-unix-4.00.1/otherlibs/unix/getgr.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getgr.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getgr.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <fail.h>
 #include <alloc.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getgroups.c ocaml-unix-4.01.0/otherlibs/unix/getgroups.c
--- ocaml-unix-4.00.1/otherlibs/unix/getgroups.c        2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getgroups.c        2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getgroups.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/gethost.c ocaml-unix-4.01.0/otherlibs/unix/gethost.c
--- ocaml-unix-4.00.1/otherlibs/unix/gethost.c  2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/gethost.c  2013-02-25 04:01:31.000000000 +0100
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: gethost.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <string.h>
 #include <mlvalues.h>
 #include <alloc.h>
@@ -129,7 +127,7 @@
   char * hostname;

 #if HAS_GETHOSTBYNAME_R || GETHOSTBYNAME_IS_REENTRANT
-  hostname = stat_alloc(string_length(name) + 1);
+  hostname = caml_stat_alloc(string_length(name) + 1);
   strcpy(hostname, String_val(name));
 #else
   hostname = String_val(name);
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/gethostname.c ocaml-unix-4.01.0/otherlibs/unix/gethostname.c
--- ocaml-unix-4.00.1/otherlibs/unix/gethostname.c      2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/gethostname.c      2012-10-15 19:50:56.000000000 +0200
@@ -11,14 +11,10 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: gethostname.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
-#if defined (_WIN32)
-#include <winsock.h>
-#else
+#ifndef _WIN32
 #include <sys/param.h>
 #endif
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getlogin.c ocaml-unix-4.01.0/otherlibs/unix/getlogin.c
--- ocaml-unix-4.00.1/otherlibs/unix/getlogin.c 2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getlogin.c 2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getlogin.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getnameinfo.c ocaml-unix-4.01.0/otherlibs/unix/getnameinfo.c
--- ocaml-unix-4.00.1/otherlibs/unix/getnameinfo.c      2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getnameinfo.c      2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getnameinfo.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <string.h>
 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getpeername.c ocaml-unix-4.01.0/otherlibs/unix/getpeername.c
--- ocaml-unix-4.00.1/otherlibs/unix/getpeername.c      2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getpeername.c      2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getpeername.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <fail.h>
 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getpid.c ocaml-unix-4.01.0/otherlibs/unix/getpid.c
--- ocaml-unix-4.00.1/otherlibs/unix/getpid.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getpid.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getpid.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getppid.c ocaml-unix-4.01.0/otherlibs/unix/getppid.c
--- ocaml-unix-4.00.1/otherlibs/unix/getppid.c  2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getppid.c  2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getppid.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getproto.c ocaml-unix-4.01.0/otherlibs/unix/getproto.c
--- ocaml-unix-4.00.1/otherlibs/unix/getproto.c 2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getproto.c 2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getproto.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
@@ -23,8 +21,6 @@

 #ifndef _WIN32
 #include <netdb.h>
-#else
-#include <winsock.h>
 #endif

 static value alloc_proto_entry(struct protoent *entry)
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getpw.c ocaml-unix-4.01.0/otherlibs/unix/getpw.c
--- ocaml-unix-4.00.1/otherlibs/unix/getpw.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getpw.c    2013-01-13 14:05:37.000000000 +0100
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getpw.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <memory.h>
@@ -29,7 +27,7 @@
   Begin_roots5 (name, passwd, gecos, dir, shell);
     name = copy_string(entry->pw_name);
     passwd = copy_string(entry->pw_passwd);
-#ifndef __BEOS__
+#if !defined(__BEOS__) && !defined(__ANDROID__)
     gecos = copy_string(entry->pw_gecos);
 #else
     gecos = copy_string("");
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getserv.c ocaml-unix-4.01.0/otherlibs/unix/getserv.c
--- ocaml-unix-4.00.1/otherlibs/unix/getserv.c  2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getserv.c  2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getserv.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
@@ -27,8 +25,6 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netdb.h>
-#else
-#include <winsock.h>
 #endif

 static value alloc_service_entry(struct servent *entry)
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getsockname.c ocaml-unix-4.01.0/otherlibs/unix/getsockname.c
--- ocaml-unix-4.00.1/otherlibs/unix/getsockname.c      2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getsockname.c      2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getsockname.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <fail.h>
 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/gettimeofday.c ocaml-unix-4.01.0/otherlibs/unix/gettimeofday.c
--- ocaml-unix-4.00.1/otherlibs/unix/gettimeofday.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/gettimeofday.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: gettimeofday.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/getuid.c ocaml-unix-4.01.0/otherlibs/unix/getuid.c
--- ocaml-unix-4.00.1/otherlibs/unix/getuid.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/getuid.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getuid.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/gmtime.c ocaml-unix-4.01.0/otherlibs/unix/gmtime.c
--- ocaml-unix-4.00.1/otherlibs/unix/gmtime.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/gmtime.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: gmtime.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/initgroups.c ocaml-unix-4.01.0/otherlibs/unix/initgroups.c
--- ocaml-unix-4.00.1/otherlibs/unix/initgroups.c       2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/initgroups.c       2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: initgroups.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/isatty.c ocaml-unix-4.01.0/otherlibs/unix/isatty.c
--- ocaml-unix-4.00.1/otherlibs/unix/isatty.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/isatty.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: isatty.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/itimer.c ocaml-unix-4.01.0/otherlibs/unix/itimer.c
--- ocaml-unix-4.00.1/otherlibs/unix/itimer.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/itimer.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: itimer.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/kill.c ocaml-unix-4.01.0/otherlibs/unix/kill.c
--- ocaml-unix-4.00.1/otherlibs/unix/kill.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/kill.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: kill.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <fail.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/link.c ocaml-unix-4.01.0/otherlibs/unix/link.c
--- ocaml-unix-4.00.1/otherlibs/unix/link.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/link.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: link.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/listen.c ocaml-unix-4.01.0/otherlibs/unix/listen.c
--- ocaml-unix-4.00.1/otherlibs/unix/listen.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/listen.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: listen.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <fail.h>
 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/lockf.c ocaml-unix-4.01.0/otherlibs/unix/lockf.c
--- ocaml-unix-4.00.1/otherlibs/unix/lockf.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/lockf.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: lockf.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <errno.h>
 #include <fcntl.h>
 #include <fail.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/lseek.c ocaml-unix-4.01.0/otherlibs/unix/lseek.c
--- ocaml-unix-4.00.1/otherlibs/unix/lseek.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/lseek.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: lseek.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <errno.h>
 #include <sys/types.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/Makefile ocaml-unix-4.01.0/otherlibs/unix/Makefile
--- ocaml-unix-4.00.1/otherlibs/unix/Makefile   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/Makefile   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 #                                                                       #
 #########################################################################

-# $Id: Makefile 11156 2011-07-27 14:17:02Z doligez $
-
 # Makefile for the Unix interface library

 LIBNAME=unix
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/mkdir.c ocaml-unix-4.01.0/otherlibs/unix/mkdir.c
--- ocaml-unix-4.00.1/otherlibs/unix/mkdir.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/mkdir.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: mkdir.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/mkfifo.c ocaml-unix-4.01.0/otherlibs/unix/mkfifo.c
--- ocaml-unix-4.00.1/otherlibs/unix/mkfifo.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/mkfifo.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: mkfifo.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fail.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/nice.c ocaml-unix-4.01.0/otherlibs/unix/nice.c
--- ocaml-unix-4.00.1/otherlibs/unix/nice.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/nice.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: nice.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"
 #include <errno.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/open.c ocaml-unix-4.01.0/otherlibs/unix/open.c
--- ocaml-unix-4.00.1/otherlibs/unix/open.c     2011-12-13 17:18:13.000000000 +0100
+++ ocaml-unix-4.01.0/otherlibs/unix/open.c     2013-08-01 14:13:56.000000000 +0200
@@ -11,14 +11,15 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: open.c 11304 2011-12-13 16:18:13Z frisch $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <memory.h>
 #include <signals.h>
 #include "unixsupport.h"
 #include <string.h>
+#ifdef HAS_UNISTD
+#include <unistd.h>
+#endif
 #include <fcntl.h>

 #ifndef O_NONBLOCK
@@ -33,26 +34,49 @@
 #ifndef O_RSYNC
 #define O_RSYNC 0
 #endif
+#ifndef O_CLOEXEC
+#define NEED_CLOEXEC_EMULATION
+#define O_CLOEXEC 0
+#endif

-static int open_flag_table[] = {
+static int open_flag_table[14] = {
   O_RDONLY, O_WRONLY, O_RDWR, O_NONBLOCK, O_APPEND, O_CREAT, O_TRUNC, O_EXCL,
-  O_NOCTTY, O_DSYNC, O_SYNC, O_RSYNC, 0
+  O_NOCTTY, O_DSYNC, O_SYNC, O_RSYNC,
+  0, /* O_SHARE_DELETE, Windows-only */
+  O_CLOEXEC
 };

+#ifdef NEED_CLOEXEC_EMULATION
+static int open_cloexec_table[14] = {
+  0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0,
+  0,
+  1
+};
+#endif
+
 CAMLprim value unix_open(value path, value flags, value perm)
 {
   CAMLparam3(path, flags, perm);
-  int ret, cv_flags;
+  int fd, cv_flags;
   char * p;

   cv_flags = convert_flag_list(flags, open_flag_table);
-  p = stat_alloc(string_length(path) + 1);
+  p = caml_stat_alloc(string_length(path) + 1);
   strcpy(p, String_val(path));
   /* open on a named FIFO can block (PR#1533) */
   enter_blocking_section();
-  ret = open(p, cv_flags, Int_val(perm));
+  fd = open(p, cv_flags, Int_val(perm));
   leave_blocking_section();
   stat_free(p);
-  if (ret == -1) uerror("open", path);
-  CAMLreturn (Val_int(ret));
+  if (fd == -1) uerror("open", path);
+#if defined(NEED_CLOEXEC_EMULATION) && defined(FD_CLOEXEC)
+  if (convert_flag_list(flags, open_cloexec_table) != 0) {
+    int flags = fcntl(fd, F_GETFD, 0);
+    if (flags == -1 ||
+        fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
+      uerror("open", path);
+  }
+#endif
+  CAMLreturn (Val_int(fd));
 }
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/opendir.c ocaml-unix-4.01.0/otherlibs/unix/opendir.c
--- ocaml-unix-4.00.1/otherlibs/unix/opendir.c  2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/opendir.c  2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: opendir.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/pipe.c ocaml-unix-4.01.0/otherlibs/unix/pipe.c
--- ocaml-unix-4.00.1/otherlibs/unix/pipe.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/pipe.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: pipe.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/putenv.c ocaml-unix-4.01.0/otherlibs/unix/putenv.c
--- ocaml-unix-4.00.1/otherlibs/unix/putenv.c   2012-03-08 20:52:03.000000000 +0100
+++ ocaml-unix-4.01.0/otherlibs/unix/putenv.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: putenv.c 12210 2012-03-08 19:52:03Z doligez $ */
-
 #include <stdlib.h>
 #include <string.h>

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/read.c ocaml-unix-4.01.0/otherlibs/unix/read.c
--- ocaml-unix-4.00.1/otherlibs/unix/read.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/read.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: read.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <string.h>
 #include <mlvalues.h>
 #include <memory.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/readdir.c ocaml-unix-4.01.0/otherlibs/unix/readdir.c
--- ocaml-unix-4.00.1/otherlibs/unix/readdir.c  2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/readdir.c  2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: readdir.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <fail.h>
 #include <alloc.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/readlink.c ocaml-unix-4.01.0/otherlibs/unix/readlink.c
--- ocaml-unix-4.00.1/otherlibs/unix/readlink.c 2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/readlink.c 2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: readlink.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/rename.c ocaml-unix-4.01.0/otherlibs/unix/rename.c
--- ocaml-unix-4.00.1/otherlibs/unix/rename.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/rename.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: rename.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <stdio.h>
 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/rewinddir.c ocaml-unix-4.01.0/otherlibs/unix/rewinddir.c
--- ocaml-unix-4.00.1/otherlibs/unix/rewinddir.c        2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/rewinddir.c        2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: rewinddir.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <fail.h>
 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/rmdir.c ocaml-unix-4.01.0/otherlibs/unix/rmdir.c
--- ocaml-unix-4.00.1/otherlibs/unix/rmdir.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/rmdir.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: rmdir.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/select.c ocaml-unix-4.01.0/otherlibs/unix/select.c
--- ocaml-unix-4.00.1/otherlibs/unix/select.c   2012-09-24 13:25:32.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/select.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: select.c 12947 2012-09-24 11:25:32Z xleroy $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/sendrecv.c ocaml-unix-4.01.0/otherlibs/unix/sendrecv.c
--- ocaml-unix-4.00.1/otherlibs/unix/sendrecv.c 2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/sendrecv.c 2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: sendrecv.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <string.h>
 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/setgid.c ocaml-unix-4.01.0/otherlibs/unix/setgid.c
--- ocaml-unix-4.00.1/otherlibs/unix/setgid.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/setgid.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: setgid.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/setgroups.c ocaml-unix-4.01.0/otherlibs/unix/setgroups.c
--- ocaml-unix-4.00.1/otherlibs/unix/setgroups.c        2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/setgroups.c        2013-02-25 04:01:31.000000000 +0100
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: setgroups.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
@@ -35,7 +33,7 @@
   int n;

   size = Wosize_val(groups);
-  gidset = (gid_t *) stat_alloc(size * sizeof(gid_t));
+  gidset = (gid_t *) caml_stat_alloc(size * sizeof(gid_t));
   for (i = 0; i < size; i++) gidset[i] = Int_val(Field(groups, i));

   n = setgroups(size, gidset);
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/setsid.c ocaml-unix-4.01.0/otherlibs/unix/setsid.c
--- ocaml-unix-4.00.1/otherlibs/unix/setsid.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/setsid.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: setsid.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <fail.h>
 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/setuid.c ocaml-unix-4.01.0/otherlibs/unix/setuid.c
--- ocaml-unix-4.00.1/otherlibs/unix/setuid.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/setuid.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: setuid.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/shutdown.c ocaml-unix-4.01.0/otherlibs/unix/shutdown.c
--- ocaml-unix-4.00.1/otherlibs/unix/shutdown.c 2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/shutdown.c 2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: shutdown.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <fail.h>
 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/signals.c ocaml-unix-4.01.0/otherlibs/unix/signals.c
--- ocaml-unix-4.00.1/otherlibs/unix/signals.c  2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/signals.c  2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: signals.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <errno.h>
 #include <signal.h>

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/sleep.c ocaml-unix-4.01.0/otherlibs/unix/sleep.c
--- ocaml-unix-4.00.1/otherlibs/unix/sleep.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/sleep.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: sleep.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <signals.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/socketaddr.c ocaml-unix-4.01.0/otherlibs/unix/socketaddr.c
--- ocaml-unix-4.00.1/otherlibs/unix/socketaddr.c       2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/socketaddr.c       2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: socketaddr.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <string.h>
 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/socketaddr.h ocaml-unix-4.01.0/otherlibs/unix/socketaddr.h
--- ocaml-unix-4.00.1/otherlibs/unix/socketaddr.h       2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/socketaddr.h       2012-10-15 19:50:56.000000000 +0200
@@ -11,9 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: socketaddr.h 11156 2011-07-27 14:17:02Z doligez $ */
-
-#include <misc.h>
+#include "misc.h"
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/socket.c ocaml-unix-4.01.0/otherlibs/unix/socket.c
--- ocaml-unix-4.00.1/otherlibs/unix/socket.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/socket.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: socket.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <fail.h>
 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/socketpair.c ocaml-unix-4.01.0/otherlibs/unix/socketpair.c
--- ocaml-unix-4.00.1/otherlibs/unix/socketpair.c       2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/socketpair.c       2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: socketpair.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/sockopt.c ocaml-unix-4.01.0/otherlibs/unix/sockopt.c
--- ocaml-unix-4.00.1/otherlibs/unix/sockopt.c  2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/sockopt.c  2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: sockopt.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <memory.h>
 #include <alloc.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/stat.c ocaml-unix-4.01.0/otherlibs/unix/stat.c
--- ocaml-unix-4.00.1/otherlibs/unix/stat.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/stat.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: stat.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <errno.h>
 #include <mlvalues.h>
 #include <memory.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/strofaddr.c ocaml-unix-4.01.0/otherlibs/unix/strofaddr.c
--- ocaml-unix-4.00.1/otherlibs/unix/strofaddr.c        2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/strofaddr.c        2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: strofaddr.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
@@ -26,6 +24,29 @@
 {
   char * res;
 #ifdef HAS_IPV6
+#ifdef _WIN32
+  char buffer[64];
+  union sock_addr_union sa;
+  int len;
+  int retcode;
+  if (string_length(a) == 16) {
+    memset(&sa.s_inet6, 0, sizeof(struct sockaddr_in6));
+    sa.s_inet6.sin6_family = AF_INET6;
+    sa.s_inet6.sin6_addr = GET_INET6_ADDR(a);
+    len = sizeof(struct sockaddr_in6);
+  } else {
+    memset(&sa.s_inet, 0, sizeof(struct sockaddr_in));
+    sa.s_inet.sin_family = AF_INET;
+    sa.s_inet.sin_addr = GET_INET_ADDR(a);
+    len = sizeof(struct sockaddr_in);
+  }
+  retcode = getnameinfo
+    (&sa.s_gen, len, buffer, sizeof(buffer), NULL, 0, NI_NUMERICHOST);
+  if (retcode != 0)
+    res = NULL;
+  else
+    res = buffer;
+#else
   char buffer[64];
   if (string_length(a) == 16)
     res = (char *)
@@ -35,6 +56,7 @@
     res = (char *)
       inet_ntop(AF_INET, (const void *) &GET_INET_ADDR(a),
                 buffer, sizeof(buffer));
+#endif
 #else
   res = inet_ntoa(GET_INET_ADDR(a));
 #endif
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/symlink.c ocaml-unix-4.01.0/otherlibs/unix/symlink.c
--- ocaml-unix-4.00.1/otherlibs/unix/symlink.c  2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/symlink.c  2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: symlink.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <fail.h>
 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/termios.c ocaml-unix-4.01.0/otherlibs/unix/termios.c
--- ocaml-unix-4.00.1/otherlibs/unix/termios.c  2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/termios.c  2013-01-13 14:05:37.000000000 +0100
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: termios.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
@@ -265,11 +263,16 @@
   return Val_unit;
 }

+#if defined(__ANDROID__)
+CAMLprim value unix_tcdrain(value fd)
+{ invalid_argument("tcdrain not implemented"); }
+#else
 CAMLprim value unix_tcdrain(value fd)
 {
   if (tcdrain(Int_val(fd)) == -1) uerror("tcdrain", Nothing);
   return Val_unit;
 }
+#endif

 static int queue_flag_table[] = {
   TCIFLUSH, TCOFLUSH, TCIOFLUSH
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/time.c ocaml-unix-4.01.0/otherlibs/unix/time.c
--- ocaml-unix-4.00.1/otherlibs/unix/time.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/time.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: time.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <time.h>
 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/times.c ocaml-unix-4.01.0/otherlibs/unix/times.c
--- ocaml-unix-4.00.1/otherlibs/unix/times.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/times.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: times.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <memory.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/truncate.c ocaml-unix-4.01.0/otherlibs/unix/truncate.c
--- ocaml-unix-4.00.1/otherlibs/unix/truncate.c 2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/truncate.c 2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: truncate.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <sys/types.h>
 #include <mlvalues.h>
 #include <fail.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/umask.c ocaml-unix-4.01.0/otherlibs/unix/umask.c
--- ocaml-unix-4.00.1/otherlibs/unix/umask.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/umask.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: umask.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/unixLabels.ml ocaml-unix-4.01.0/otherlibs/unix/unixLabels.ml
--- ocaml-unix-4.00.1/otherlibs/unix/unixLabels.ml      2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/unixLabels.ml      2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 (*                                                                     *)
 (***********************************************************************)

-(* $Id: unixLabels.ml 11156 2011-07-27 14:17:02Z doligez $ *)
-
 (* Module [UnixLabels]: labelled Unix module *)

 include Unix
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/unixLabels.mli ocaml-unix-4.01.0/otherlibs/unix/unixLabels.mli
--- ocaml-unix-4.00.1/otherlibs/unix/unixLabels.mli     2011-12-13 18:59:10.000000000 +0100
+++ ocaml-unix-4.01.0/otherlibs/unix/unixLabels.mli     2013-08-01 14:13:56.000000000 +0200
@@ -11,8 +11,6 @@
 (*                                                                     *)
 (***********************************************************************)

-(* $Id: unixLabels.mli 11307 2011-12-13 17:59:10Z frisch $ *)
-
 (** Interface to the Unix system.
    To use as replacement to default {!Unix} module,
    add [module Unix = UnixLabels] in your implementation.
@@ -185,7 +183,8 @@
    and termination status. *)

 val waitpid : mode:wait_flag list -> int -> int * process_status
-(** Same as {!UnixLabels.wait}, but waits for the child process whose pid is given.
+(** Same as {!UnixLabels.wait}, but waits for the child process whose pid
+   is given.
    A pid of [-1] means wait for any child.
    A pid of [0] means wait for any child in the same process group
    as the current process.
@@ -241,6 +240,8 @@
   | O_SYNC                      (** Writes complete as `Synchronised I/O file integrity completion' *)
   | O_RSYNC                     (** Reads complete as writes (depending on O_SYNC/O_DSYNC) *)
   | O_SHARE_DELETE              (** Windows only: allow the file to be deleted while still open *)
+  | O_CLOEXEC                   (** Set the close-on-exec flag on the
+                                   descriptor returned by {!openfile} *)
 (** The flags to {!UnixLabels.openfile}. *)


@@ -305,7 +306,8 @@


 val lseek : file_descr -> int -> mode:seek_command -> int
-(** Set the current position for a file descriptor *)
+(** Set the current position for a file descriptor, and return the resulting
+    offset (from the beginning of the file). *)

 val truncate : string -> len:int -> unit
 (** Truncates the named file to the given size. *)
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/unix.ml ocaml-unix-4.01.0/otherlibs/unix/unix.ml
--- ocaml-unix-4.00.1/otherlibs/unix/unix.ml    2012-01-18 10:28:05.000000000 +0100
+++ ocaml-unix-4.01.0/otherlibs/unix/unix.ml    2013-08-01 14:13:56.000000000 +0200
@@ -11,8 +11,6 @@
 (*                                                                     *)
 (***********************************************************************)

-(* $Id: unix.ml 12038 2012-01-18 09:28:05Z protzenk $ *)
-
 type error =
     E2BIG
   | EACCES
@@ -91,6 +89,83 @@

 external error_message : error -> string = "unix_error_message"

+let () =
+  Printexc.register_printer
+    (function
+      | Unix_error (e, s, s') ->
+          let msg = match e with
+          | E2BIG -> "E2BIG"
+          | EACCES -> "EACCES"
+          | EAGAIN -> "EAGAIN"
+          | EBADF -> "EBADF"
+          | EBUSY -> "EBUSY"
+          | ECHILD -> "ECHILD"
+          | EDEADLK -> "EDEADLK"
+          | EDOM -> "EDOM"
+          | EEXIST -> "EEXIST"
+          | EFAULT -> "EFAULT"
+          | EFBIG -> "EFBIG"
+          | EINTR -> "EINTR"
+          | EINVAL -> "EINVAL"
+          | EIO -> "EIO"
+          | EISDIR -> "EISDIR"
+          | EMFILE -> "EMFILE"
+          | EMLINK -> "EMLINK"
+          | ENAMETOOLONG -> "ENAMETOOLONG"
+          | ENFILE -> "ENFILE"
+          | ENODEV -> "ENODEV"
+          | ENOENT -> "ENOENT"
+          | ENOEXEC -> "ENOEXEC"
+          | ENOLCK -> "ENOLCK"
+          | ENOMEM -> "ENOMEM"
+          | ENOSPC -> "ENOSPC"
+          | ENOSYS -> "ENOSYS"
+          | ENOTDIR -> "ENOTDIR"
+          | ENOTEMPTY -> "ENOTEMPTY"
+          | ENOTTY -> "ENOTTY"
+          | ENXIO -> "ENXIO"
+          | EPERM -> "EPERM"
+          | EPIPE -> "EPIPE"
+          | ERANGE -> "ERANGE"
+          | EROFS -> "EROFS"
+          | ESPIPE -> "ESPIPE"
+          | ESRCH -> "ESRCH"
+          | EXDEV -> "EXDEV"
+          | EWOULDBLOCK -> "EWOULDBLOCK"
+          | EINPROGRESS -> "EINPROGRESS"
+          | EALREADY -> "EALREADY"
+          | ENOTSOCK -> "ENOTSOCK"
+          | EDESTADDRREQ -> "EDESTADDRREQ"
+          | EMSGSIZE -> "EMSGSIZE"
+          | EPROTOTYPE -> "EPROTOTYPE"
+          | ENOPROTOOPT -> "ENOPROTOOPT"
+          | EPROTONOSUPPORT -> "EPROTONOSUPPORT"
+          | ESOCKTNOSUPPORT -> "ESOCKTNOSUPPORT"
+          | EOPNOTSUPP -> "EOPNOTSUPP"
+          | EPFNOSUPPORT -> "EPFNOSUPPORT"
+          | EAFNOSUPPORT -> "EAFNOSUPPORT"
+          | EADDRINUSE -> "EADDRINUSE"
+          | EADDRNOTAVAIL -> "EADDRNOTAVAIL"
+          | ENETDOWN -> "ENETDOWN"
+          | ENETUNREACH -> "ENETUNREACH"
+          | ENETRESET -> "ENETRESET"
+          | ECONNABORTED -> "ECONNABORTED"
+          | ECONNRESET -> "ECONNRESET"
+          | ENOBUFS -> "ENOBUFS"
+          | EISCONN -> "EISCONN"
+          | ENOTCONN -> "ENOTCONN"
+          | ESHUTDOWN -> "ESHUTDOWN"
+          | ETOOMANYREFS -> "ETOOMANYREFS"
+          | ETIMEDOUT -> "ETIMEDOUT"
+          | ECONNREFUSED -> "ECONNREFUSED"
+          | EHOSTDOWN -> "EHOSTDOWN"
+          | EHOSTUNREACH -> "EHOSTUNREACH"
+          | ELOOP -> "ELOOP"
+          | EOVERFLOW -> "EOVERFLOW"
+          | EUNKNOWNERR x -> Printf.sprintf "EUNKNOWNERR %d" x in
+          Some (Printf.sprintf "Unix.Unix_error(Unix.%s, %S, %S)" msg s s')
+      | _ -> None)
+
 let handle_unix_error f arg =
   try
     f arg
@@ -127,7 +202,8 @@
 external execvpe : string -> string array -> string array -> 'a = "unix_execvpe"
 external fork : unit -> int = "unix_fork"
 external wait : unit -> int * process_status = "unix_wait"
-external waitpid : wait_flag list -> int -> int * process_status = "unix_waitpid"
+external waitpid : wait_flag list -> int -> int * process_status
+   = "unix_waitpid"
 external getpid : unit -> int = "unix_getpid"
 external getppid : unit -> int = "unix_getppid"
 external nice : int -> int = "unix_nice"
@@ -152,6 +228,7 @@
   | O_SYNC
   | O_RSYNC
   | O_SHARE_DELETE
+  | O_CLOEXEC

 type file_perm = int

@@ -162,7 +239,8 @@
 external close : file_descr -> unit = "unix_close"
 external unsafe_read : file_descr -> string -> int -> int -> int = "unix_read"
 external unsafe_write : file_descr -> string -> int -> int -> int = "unix_write"
-external unsafe_single_write : file_descr -> string -> int -> int -> int = "unix_single_write"
+external unsafe_single_write : file_descr -> string -> int -> int -> int
+   = "unix_single_write"

 let read fd buf ofs len =
   if ofs < 0 || len < 0 || ofs > String.length buf - len
@@ -231,7 +309,8 @@

 module LargeFile =
   struct
-    external lseek : file_descr -> int64 -> seek_command -> int64 = "unix_lseek_64"
+    external lseek : file_descr -> int64 -> seek_command -> int64
+       = "unix_lseek_64"
     external truncate : string -> int64 -> unit = "unix_truncate_64"
     external ftruncate : file_descr -> int64 -> unit = "unix_ftruncate_64"
     type stats =
@@ -762,6 +841,10 @@

 (* High-level process management (system, popen) *)

+let rec waitpid_non_intr pid =
+  try waitpid [] pid
+  with Unix_error (EINTR, _, _) -> waitpid_non_intr pid
+
 let system cmd =
   match fork() with
      0 -> begin try
@@ -769,7 +852,7 @@
           with _ ->
             exit 127
           end
-  | id -> snd(waitpid [] id)
+  | id -> snd(waitpid_non_intr id)

 let rec safe_dup fd =
   let new_fd = dup fd in
@@ -922,10 +1005,6 @@
   with Not_found ->
     raise(Unix_error(EBADF, fun_name, ""))

-let rec waitpid_non_intr pid =
-  try waitpid [] pid
-  with Unix_error (EINTR, _, _) -> waitpid_non_intr pid
-
 let close_process_in inchan =
   let pid = find_proc_id "close_process_in" (Process_in inchan) in
   close_in inchan;
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/unix.mli ocaml-unix-4.01.0/otherlibs/unix/unix.mli
--- ocaml-unix-4.00.1/otherlibs/unix/unix.mli   2012-02-07 17:41:02.000000000 +0100
+++ ocaml-unix-4.01.0/otherlibs/unix/unix.mli   2013-08-01 14:13:56.000000000 +0200
@@ -11,8 +11,6 @@
 (*                                                                     *)
 (***********************************************************************)

-(* $Id: unix.mli 12140 2012-02-07 16:41:02Z doligez $ *)
-
 (** Interface to the Unix system *)


@@ -189,7 +187,8 @@
    as the current process.
    Negative pid arguments represent process groups.
    The list of options indicates whether [waitpid] should return
-   immediately without waiting, or also report stopped children. *)
+   immediately without waiting, and whether it should report stopped
+   children. *)

 val system : string -> process_status
 (** Execute the given command, wait until it terminates, and return
@@ -243,6 +242,9 @@
                                    O_SYNC/O_DSYNC) *)
   | O_SHARE_DELETE              (** Windows only: allow the file to be deleted
                                    while still open *)
+  | O_CLOEXEC                   (** Set the close-on-exec flag on the
+                                   descriptor returned by {!openfile} *)
+
 (** The flags to {!Unix.openfile}. *)


@@ -251,9 +253,9 @@
     read for group, none for others *)

 val openfile : string -> open_flag list -> file_perm -> file_descr
-(** Open the named file with the given flags. Third argument is
-   the permissions to give to the file if it is created. Return
-   a file descriptor on the named file. *)
+(** Open the named file with the given flags. Third argument is the
+   permissions to give to the file if it is created (see
+   {!umask}). Return a file descriptor on the named file. *)

 val close : file_descr -> unit
 (** Close a file descriptor. *)
@@ -307,7 +309,8 @@


 val lseek : file_descr -> int -> seek_command -> int
-(** Set the current position for a file descriptor *)
+(** Set the current position for a file descriptor, and return the resulting
+    offset (from the beginning of the file). *)

 val truncate : string -> int -> unit
 (** Truncates the named file to the given size. *)
@@ -480,7 +483,7 @@


 val mkdir : string -> file_perm -> unit
-(** Create a directory with the given permissions. *)
+(** Create a directory with the given permissions (see {!umask}). *)

 val rmdir : string -> unit
 (** Remove an empty directory. *)
@@ -521,7 +524,7 @@
    opened for writing, that's the entrance to the pipe. *)

 val mkfifo : string -> file_perm -> unit
-(** Create a named pipe with the given permissions. *)
+(** Create a named pipe with the given permissions (see {!umask}). *)


 (** {6 High-level process and redirection management} *)
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/unixsupport.c ocaml-unix-4.01.0/otherlibs/unix/unixsupport.c
--- ocaml-unix-4.00.1/otherlibs/unix/unixsupport.c      2011-12-21 14:08:48.000000000 +0100
+++ ocaml-unix-4.01.0/otherlibs/unix/unixsupport.c      2013-08-02 16:21:40.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: unixsupport.c 11915 2011-12-21 13:08:48Z protzenk $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <callback.h>
@@ -272,6 +270,15 @@
   return err;
 }

+extern int code_of_unix_error (value error)
+{
+  if (Is_block(error)) {
+    return Int_val(Field(error, 0));
+  } else {
+    return error_table[Int_val(error)];
+  }
+}
+
 void unix_error(int errcode, char *cmdname, value cmdarg)
 {
   value res;
@@ -284,7 +291,8 @@
     if (unix_error_exn == NULL) {
       unix_error_exn = caml_named_value("Unix.Unix_error");
       if (unix_error_exn == NULL)
-        invalid_argument("Exception Unix.Unix_error not initialized, please link unix.cma");
+        invalid_argument("Exception Unix.Unix_error not initialized,"
+                         " please link unix.cma");
     }
     res = alloc_small(4, 0);
     Field(res, 0) = *unix_error_exn;
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/unixsupport.h ocaml-unix-4.01.0/otherlibs/unix/unixsupport.h
--- ocaml-unix-4.00.1/otherlibs/unix/unixsupport.h      2012-05-28 13:31:30.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/unixsupport.h      2013-08-02 16:21:40.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: unixsupport.h 12488 2012-05-28 11:31:30Z frisch $ */
-
 #ifdef HAS_UNISTD
 #include <unistd.h>
 #endif
@@ -20,6 +18,7 @@
 #define Nothing ((value) 0)

 extern value unix_error_of_code (int errcode);
+extern int code_of_unix_error (value error);
 extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
 extern void uerror (char * cmdname, value arg) Noreturn;

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/unlink.c ocaml-unix-4.01.0/otherlibs/unix/unlink.c
--- ocaml-unix-4.00.1/otherlibs/unix/unlink.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/unlink.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: unlink.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/unix/utimes.c ocaml-unix-4.01.0/otherlibs/unix/utimes.c
--- ocaml-unix-4.00.1/otherlibs/unix/utimes.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/utimes.c   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: utimes.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <fail.h>
 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/wait.c ocaml-unix-4.01.0/otherlibs/unix/wait.c
--- ocaml-unix-4.00.1/otherlibs/unix/wait.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/wait.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: wait.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <fail.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/unix/write.c ocaml-unix-4.01.0/otherlibs/unix/write.c
--- ocaml-unix-4.00.1/otherlibs/unix/write.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/unix/write.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: write.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <errno.h>
 #include <string.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/accept.c ocaml-unix-4.01.0/otherlibs/win32unix/accept.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/accept.c      2012-05-24 18:40:59.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/accept.c      2013-06-14 13:50:12.000000000 +0200
@@ -11,13 +11,12 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: accept.c 12480 2012-05-24 16:40:59Z xleroy $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <memory.h>
 #include <signals.h>
 #include "unixsupport.h"
+#include <mswsock.h>   // for SO_OPENTYPE and SO_SYNCHRONOUS_NONALERT
 #include "socketaddr.h"

 CAMLprim value unix_accept(sock)
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/bind.c ocaml-unix-4.01.0/otherlibs/win32unix/bind.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/bind.c        2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/bind.c        2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: bind.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"
 #include "socketaddr.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/channels.c ocaml-unix-4.01.0/otherlibs/win32unix/channels.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/channels.c    2011-12-21 17:31:01.000000000 +0100
+++ ocaml-unix-4.01.0/otherlibs/win32unix/channels.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: channels.c 11927 2011-12-21 16:31:01Z xleroy $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <io.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/close.c ocaml-unix-4.01.0/otherlibs/win32unix/close.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/close.c       2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/close.c       2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: close.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"
 #include <io.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/close_on.c ocaml-unix-4.01.0/otherlibs/win32unix/close_on.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/close_on.c    2012-07-30 20:59:07.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/close_on.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,11 +11,9 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: close_on.c 12800 2012-07-30 18:59:07Z doligez $ */
-
 #include <mlvalues.h>
-#include <windows.h>
 #include "unixsupport.h"
+#include <windows.h>

 int win_set_inherit(value fd, BOOL inherit)
 {
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/connect.c ocaml-unix-4.01.0/otherlibs/win32unix/connect.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/connect.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/connect.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: connect.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <signals.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/createprocess.c ocaml-unix-4.01.0/otherlibs/win32unix/createprocess.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/createprocess.c       2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/createprocess.c       2012-10-15 19:50:56.000000000 +0200
@@ -11,12 +11,10 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: createprocess.c 11156 2011-07-27 14:17:02Z doligez $ */
-
-#include <windows.h>
 #include <mlvalues.h>
-#include <osdeps.h>
 #include "unixsupport.h"
+#include <windows.h>
+#include <osdeps.h>

 static int win_has_console(void);

diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/dup2.c ocaml-unix-4.01.0/otherlibs/win32unix/dup2.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/dup2.c        2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/dup2.c        2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: dup2.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/dup.c ocaml-unix-4.01.0/otherlibs/win32unix/dup.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/dup.c 2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/dup.c 2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: dup.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/errmsg.c ocaml-unix-4.01.0/otherlibs/win32unix/errmsg.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/errmsg.c      2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/errmsg.c      2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: errmsg.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/getpeername.c ocaml-unix-4.01.0/otherlibs/win32unix/getpeername.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/getpeername.c 2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/getpeername.c 2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getpeername.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"
 #include "socketaddr.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/getpid.c ocaml-unix-4.01.0/otherlibs/win32unix/getpid.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/getpid.c      2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/getpid.c      2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getpid.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/getsockname.c ocaml-unix-4.01.0/otherlibs/win32unix/getsockname.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/getsockname.c 2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/getsockname.c 2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getsockname.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"
 #include "socketaddr.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/gettimeofday.c ocaml-unix-4.01.0/otherlibs/win32unix/gettimeofday.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/gettimeofday.c        2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/gettimeofday.c        2012-10-15 19:50:56.000000000 +0200
@@ -11,23 +11,41 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: gettimeofday.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <time.h>

 #include "unixsupport.h"

+#ifdef HAS_MKTIME
+static double initial_time = 0; /* 0 means uninitialized */
+#else
 static time_t initial_time = 0; /* 0 means uninitialized */
+#endif
 static DWORD initial_tickcount;

 CAMLprim value unix_gettimeofday(value unit)
 {
   DWORD tickcount = GetTickCount();
+  SYSTEMTIME st;
+  struct tm tm;
   if (initial_time == 0 || tickcount < initial_tickcount) {
     initial_tickcount = tickcount;
+#ifdef HAS_MKTIME
+    GetLocalTime(&st);
+    tm.tm_sec = st.wSecond;
+    tm.tm_min = st.wMinute;
+    tm.tm_hour = st.wHour;
+    tm.tm_mday = st.wDay;
+    tm.tm_mon = st.wMonth - 1;
+    tm.tm_year = st.wYear - 1900;
+    tm.tm_wday = 0;
+    tm.tm_yday = 0;
+    tm.tm_isdst = -1;
+    initial_time = ((double) mktime(&tm) + (double) st.wMilliseconds * 1e-3);
+#else
     initial_time = time(NULL);
+#endif
     return copy_double((double) initial_time);
   } else {
     return copy_double((double) initial_time +
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/.ignore ocaml-unix-4.01.0/otherlibs/win32unix/.ignore
--- ocaml-unix-4.00.1/otherlibs/win32unix/.ignore       2011-07-20 17:37:36.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/.ignore       2013-04-29 20:20:56.000000000 +0200
@@ -12,9 +12,11 @@
 execve.c
 execvp.c
 exit.c
+getaddrinfo.c
 getcwd.c
 gethost.c
 gethostname.c
+getnameinfo.c
 getproto.c
 getserv.c
 gmtime.c
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/link.c ocaml-unix-4.01.0/otherlibs/win32unix/link.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/link.c        2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/link.c        2012-10-15 19:50:56.000000000 +0200
@@ -11,12 +11,10 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: link.c 11156 2011-07-27 14:17:02Z doligez $ */
-
-#include <windows.h>
 #include <mlvalues.h>
 #include <fail.h>
 #include "unixsupport.h"
+#include <windows.h>

 typedef
 BOOL (WINAPI *tCreateHardLink)(
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/listen.c ocaml-unix-4.01.0/otherlibs/win32unix/listen.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/listen.c      2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/listen.c      2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: listen.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/lockf.c ocaml-unix-4.01.0/otherlibs/win32unix/lockf.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/lockf.c       2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/lockf.c       2013-07-23 16:48:47.000000000 +0200
@@ -13,8 +13,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: lockf.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <errno.h>
 #include <fcntl.h>
 #include <mlvalues.h>
@@ -64,7 +62,8 @@

   version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
   if(GetVersionEx(&version) == 0) {
-    invalid_argument("lockf only supported on WIN32_NT platforms: could not determine current platform.");
+    invalid_argument("lockf only supported on WIN32_NT platforms:"
+                     " could not determine current platform.");
   }
   if(version.dwPlatformId != VER_PLATFORM_WIN32_NT) {
     invalid_argument("lockf only supported on WIN32_NT platforms");
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/lseek.c ocaml-unix-4.01.0/otherlibs/win32unix/lseek.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/lseek.c       2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/lseek.c       2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: lseek.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/Makefile.nt ocaml-unix-4.01.0/otherlibs/win32unix/Makefile.nt
--- ocaml-unix-4.00.1/otherlibs/win32unix/Makefile.nt   2011-12-21 10:43:13.000000000 +0100
+++ ocaml-unix-4.01.0/otherlibs/win32unix/Makefile.nt   2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 #                                                                       #
 #########################################################################

-# $Id: Makefile.nt 11912 2011-12-21 09:43:13Z protzenk $
-
 # Files in this directory
 WIN_FILES = accept.c bind.c channels.c close.c \
   close_on.c connect.c createprocess.c dup.c dup2.c errmsg.c \
@@ -27,7 +25,8 @@
 # Files from the ../unix directory
 UNIX_FILES = access.c addrofstr.c chdir.c chmod.c cst2constr.c \
   cstringv.c envir.c execv.c execve.c execvp.c \
-  exit.c getcwd.c gethost.c gethostname.c getproto.c \
+  exit.c getaddrinfo.c getcwd.c gethost.c gethostname.c \
+  getnameinfo.c getproto.c \
   getserv.c gmtime.c putenv.c rmdir.c \
   socketaddr.c strofaddr.c time.c unlink.c utimes.c

diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/mkdir.c ocaml-unix-4.01.0/otherlibs/win32unix/mkdir.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/mkdir.c       2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/mkdir.c       2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: mkdir.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/nonblock.c ocaml-unix-4.01.0/otherlibs/win32unix/nonblock.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/nonblock.c    2011-10-15 11:02:22.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/nonblock.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: nonblock.c 11223 2011-10-15 09:02:22Z xleroy $ */
-
 #include <mlvalues.h>
 #include <signals.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/open.c ocaml-unix-4.01.0/otherlibs/win32unix/open.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/open.c        2011-12-13 17:21:10.000000000 +0100
+++ ocaml-unix-4.01.0/otherlibs/win32unix/open.c        2013-08-01 14:13:56.000000000 +0200
@@ -11,34 +11,37 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: open.c 11305 2011-12-13 16:21:10Z frisch $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include "unixsupport.h"
 #include <fcntl.h>

-static int open_access_flags[13] = {
+static int open_access_flags[14] = {
   GENERIC_READ, GENERIC_WRITE, GENERIC_READ|GENERIC_WRITE,
-  0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+static int open_create_flags[14] = {
+  0, 0, 0, 0, 0, O_CREAT, O_TRUNC, O_EXCL, 0, 0, 0, 0, 0, 0
 };

-static int open_create_flags[13] = {
-  0, 0, 0, 0, 0, O_CREAT, O_TRUNC, O_EXCL, 0, 0, 0, 0, 0
+static int open_share_flags[14] = {
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FILE_SHARE_DELETE, 0
 };

-static int open_share_flags[13] = {
-  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FILE_SHARE_DELETE
+static int open_cloexec_flags[14] = {
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
 };

 CAMLprim value unix_open(value path, value flags, value perm)
 {
-  int fileaccess, createflags, fileattrib, filecreate, sharemode;
+  int fileaccess, createflags, fileattrib, filecreate, sharemode, cloexec;
   SECURITY_ATTRIBUTES attr;
   HANDLE h;

   fileaccess = convert_flag_list(flags, open_access_flags);
-  sharemode = FILE_SHARE_READ | FILE_SHARE_WRITE | convert_flag_list(flags, open_share_flags);
+  sharemode = FILE_SHARE_READ | FILE_SHARE_WRITE
+              | convert_flag_list(flags, open_share_flags);

   createflags = convert_flag_list(flags, open_create_flags);
   if ((createflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
@@ -57,9 +60,10 @@
   else
     fileattrib = FILE_ATTRIBUTE_NORMAL;

+  cloexec = convert_flag_list(flags, open_cloexec_flags);
   attr.nLength = sizeof(attr);
   attr.lpSecurityDescriptor = NULL;
-  attr.bInheritHandle = TRUE;
+  attr.bInheritHandle = cloexec ? FALSE : TRUE;

   h = CreateFile(String_val(path), fileaccess,
                  sharemode, &attr,
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/pipe.c ocaml-unix-4.01.0/otherlibs/win32unix/pipe.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/pipe.c        2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/pipe.c        2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: pipe.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <memory.h>
 #include <alloc.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/read.c ocaml-unix-4.01.0/otherlibs/win32unix/read.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/read.c        2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/read.c        2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: read.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <string.h>
 #include <mlvalues.h>
 #include <memory.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/rename.c ocaml-unix-4.01.0/otherlibs/win32unix/rename.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/rename.c      2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/rename.c      2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: rename.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <stdio.h>
 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/select.c ocaml-unix-4.01.0/otherlibs/win32unix/select.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/select.c      2012-07-30 20:59:07.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/select.c      2012-10-15 19:50:56.000000000 +0200
@@ -11,19 +11,14 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: select.c 12800 2012-07-30 18:59:07Z doligez $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <memory.h>
 #include <fail.h>
 #include <signals.h>
-#include <winsock2.h>
-#include <windows.h>
+#include "winworker.h"
 #include <stdio.h>
-#include "unixsupport.h"
 #include "windbug.h"
-#include "winworker.h"
 #include "winlist.h"

 /* This constant define the maximum number of objects that
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/sendrecv.c ocaml-unix-4.01.0/otherlibs/win32unix/sendrecv.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/sendrecv.c    2011-12-20 13:37:52.000000000 +0100
+++ ocaml-unix-4.01.0/otherlibs/win32unix/sendrecv.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: sendrecv.c 11896 2011-12-20 12:37:52Z xleroy $ */
-
 #include <mlvalues.h>
 #include <alloc.h>
 #include <memory.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/shutdown.c ocaml-unix-4.01.0/otherlibs/win32unix/shutdown.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/shutdown.c    2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/shutdown.c    2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: shutdown.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/sleep.c ocaml-unix-4.01.0/otherlibs/win32unix/sleep.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/sleep.c       2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/sleep.c       2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: sleep.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <signals.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/socketaddr.h ocaml-unix-4.01.0/otherlibs/win32unix/socketaddr.h
--- ocaml-unix-4.00.1/otherlibs/win32unix/socketaddr.h  2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/socketaddr.h  2012-10-15 19:50:56.000000000 +0200
@@ -11,13 +11,14 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: socketaddr.h 11156 2011-07-27 14:17:02Z doligez $ */
-
-#include <misc.h>
+#include "misc.h"

 union sock_addr_union {
   struct sockaddr s_gen;
   struct sockaddr_in s_inet;
+#ifdef HAS_IPV6
+  struct sockaddr_in6 s_inet6;
+#endif
 };

 extern union sock_addr_union sock_addr;
@@ -35,3 +36,8 @@
                       socklen_param_type addr_len, int close_on_error);
 CAMLprim value alloc_inet_addr (struct in_addr * inaddr);
 #define GET_INET_ADDR(v) (*((struct in_addr *) (v)))
+
+#ifdef HAS_IPV6
+CAMLexport value alloc_inet6_addr (struct in6_addr * inaddr);
+#define GET_INET6_ADDR(v) (*((struct in6_addr *) (v)))
+#endif
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/socket.c ocaml-unix-4.01.0/otherlibs/win32unix/socket.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/socket.c      2012-05-24 18:40:59.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/socket.c      2013-06-14 13:50:12.000000000 +0200
@@ -11,13 +11,17 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: socket.c 12480 2012-05-24 16:40:59Z xleroy $ */
-
 #include <mlvalues.h>
 #include "unixsupport.h"
+#include <mswsock.h>   // for SO_OPENTYPE and SO_SYNCHRONOUS_NONALERT

 int socket_domain_table[] = {
-  PF_UNIX, PF_INET /*, PF_INET6 */
+  PF_UNIX, PF_INET,
+#if defined(HAS_IPV6)
+  PF_INET6
+#else
+  0
+#endif
 };

 int socket_type_table[] = {
@@ -30,11 +34,14 @@
   SOCKET s;
   int oldvalue, oldvaluelen, newvalue, retcode;

+  #ifndef HAS_IPV6
   /* IPv6 requires WinSock2, we must raise an error on PF_INET6 */
   if (Int_val(domain) >= sizeof(socket_domain_table)/sizeof(int)) {
     win32_maperr(WSAEPFNOSUPPORT);
     uerror("socket", Nothing);
   }
+  #endif
+
   oldvaluelen = sizeof(oldvalue);
   retcode = getsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
                        (char *) &oldvalue, &oldvaluelen);
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/sockopt.c ocaml-unix-4.01.0/otherlibs/win32unix/sockopt.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/sockopt.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/sockopt.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: sockopt.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <errno.h>
 #include <mlvalues.h>
 #include <memory.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/startup.c ocaml-unix-4.01.0/otherlibs/win32unix/startup.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/startup.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/startup.c     2012-09-26 06:18:08.000000000 +0200
@@ -15,7 +15,6 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <mlvalues.h>
-#include "unixsupport.h"
 #include "winworker.h"
 #include "windbug.h"

diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/stat.c ocaml-unix-4.01.0/otherlibs/win32unix/stat.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/stat.c        2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/stat.c        2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: stat.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <errno.h>
 #include <mlvalues.h>
 #include <memory.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/system.c ocaml-unix-4.01.0/otherlibs/win32unix/system.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/system.c      2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/system.c      2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: system.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <memory.h>
 #include <alloc.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/times.c ocaml-unix-4.01.0/otherlibs/win32unix/times.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/times.c       2012-07-30 20:59:07.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/times.c       2012-09-26 06:18:08.000000000 +0200
@@ -1,6 +1,20 @@
-#include <windows.h>
+/***********************************************************************/
+/*                                                                     */
+/*                                OCaml                                */
+/*                                                                     */
+/*                 File contributed by Josh Berdine                    */
+/*                                                                     */
+/*  Copyright 2011 Institut National de Recherche en Informatique et   */
+/*  en Automatique.  All rights reserved.  This file is distributed    */
+/*  under the terms of the GNU Library General Public License, with    */
+/*  the special exception on linking described in file ../../LICENSE.  */
+/*                                                                     */
+/***********************************************************************/
+
 #include <mlvalues.h>
+#include <alloc.h>
 #include "unixsupport.h"
+#include <windows.h>


 double to_sec(FILETIME ft) {
@@ -16,11 +30,11 @@


 value unix_times(value unit) {
-
   value res;
   FILETIME creation, exit, stime, utime;

-  if (!(GetProcessTimes(GetCurrentProcess(), &creation, &exit, &stime, &utime))) {
+  if (!(GetProcessTimes(GetCurrentProcess(), &creation, &exit, &stime,
+                        &utime))) {
     win32_maperr(GetLastError());
     uerror("times", Nothing);
   }
@@ -31,5 +45,4 @@
   Store_double_field(res, 2, 0);
   Store_double_field(res, 3, 0);
   return res;
-
 }
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/unix.ml ocaml-unix-4.01.0/otherlibs/win32unix/unix.ml
--- ocaml-unix-4.00.1/otherlibs/win32unix/unix.ml       2011-12-21 10:43:13.000000000 +0100
+++ ocaml-unix-4.01.0/otherlibs/win32unix/unix.ml       2013-08-01 14:13:56.000000000 +0200
@@ -11,8 +11,6 @@
 (*                                                                     *)
 (***********************************************************************)

-(* $Id: unix.ml 11912 2011-12-21 09:43:13Z protzenk $ *)
-
 (* Initialization *)

 external startup: unit -> unit = "win_startup"
@@ -171,6 +169,7 @@
   | O_SYNC
   | O_RSYNC
   | O_SHARE_DELETE
+  | O_CLOEXEC

 type file_perm = int

@@ -199,10 +198,14 @@

 (* Interfacing with the standard input/output library *)

-external in_channel_of_descr: file_descr -> in_channel = "win_inchannel_of_filedescr"
-external out_channel_of_descr: file_descr -> out_channel = "win_outchannel_of_filedescr"
-external descr_of_in_channel : in_channel -> file_descr = "win_filedescr_of_channel"
-external descr_of_out_channel : out_channel -> file_descr = "win_filedescr_of_channel"
+external in_channel_of_descr: file_descr -> in_channel
+   = "win_inchannel_of_filedescr"
+external out_channel_of_descr: file_descr -> out_channel
+   = "win_outchannel_of_filedescr"
+external descr_of_in_channel : in_channel -> file_descr
+   = "win_filedescr_of_channel"
+external descr_of_out_channel : out_channel -> file_descr
+   = "win_filedescr_of_channel"

 (* Seeking and truncating *)

@@ -257,9 +260,12 @@

 module LargeFile =
   struct
-    external lseek : file_descr -> int64 -> seek_command -> int64 = "unix_lseek_64"
-    let truncate name len = invalid_arg "Unix.LargeFile.truncate not implemented"
-    let ftruncate name len = invalid_arg "Unix.LargeFile.ftruncate not implemented"
+    external lseek : file_descr -> int64 -> seek_command -> int64
+       = "unix_lseek_64"
+    let truncate name len =
+      invalid_arg "Unix.LargeFile.truncate not implemented"
+    let ftruncate name len =
+      invalid_arg "Unix.LargeFile.ftruncate not implemented"
     type stats =
       { st_dev : int;
         st_ino : int;
@@ -658,7 +664,11 @@
   | AI_CANONNAME
   | AI_PASSIVE

-let getaddrinfo node service opts =
+external getaddrinfo_system
+  : string -> string -> getaddrinfo_option list -> addr_info list
+  = "unix_getaddrinfo"
+
+let getaddrinfo_emulation node service opts =
   (* Parse options *)
   let opt_socktype = ref None
   and opt_protocol = ref 0
@@ -720,6 +730,12 @@
           addresses)
       ports)

+let getaddrinfo node service opts =
+  try
+    List.rev(getaddrinfo_system node service opts)
+  with Invalid_argument _ ->
+    getaddrinfo_emulation node service opts
+
 type name_info =
   { ni_hostname : string;
     ni_service : string }
@@ -731,7 +747,11 @@
   | NI_NUMERICSERV
   | NI_DGRAM

-let getnameinfo addr opts =
+external getnameinfo_system
+  : sockaddr -> getnameinfo_option list -> name_info
+  = "unix_getnameinfo"
+
+let getnameinfo_emulation addr opts =
   match addr with
   | ADDR_UNIX f ->
       { ni_hostname = ""; ni_service = f } (* why not? *)
@@ -752,6 +772,12 @@
           string_of_int p in
       { ni_hostname = hostname; ni_service = service }

+let getnameinfo addr opts =
+  try
+    getnameinfo_system addr opts
+  with Invalid_argument _ ->
+    getnameinfo_emulation addr opts
+
 (* High-level process management (system, popen) *)

 external win_create_process : string -> string -> string option ->
@@ -874,12 +900,14 @@
 (* High-level network functions *)

 let open_connection sockaddr =
-  let domain =
-    match sockaddr with ADDR_UNIX _ -> PF_UNIX | ADDR_INET(_,_) -> PF_INET in
   let sock =
-    socket domain SOCK_STREAM 0 in
-  connect sock sockaddr;
-  (in_channel_of_descr sock, out_channel_of_descr sock)
+    socket (domain_of_sockaddr sockaddr) SOCK_STREAM 0 in
+  try
+    connect sock sockaddr;
+    set_close_on_exec sock;
+    (in_channel_of_descr sock, out_channel_of_descr sock)
+  with exn ->
+    close sock; raise exn

 let shutdown_connection inchan =
   shutdown (descr_of_in_channel inchan) SHUTDOWN_SEND
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/unixsupport.c ocaml-unix-4.01.0/otherlibs/win32unix/unixsupport.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/unixsupport.c 2011-10-15 11:02:22.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/unixsupport.c 2013-07-23 16:48:47.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: unixsupport.c 11223 2011-10-15 09:02:22Z xleroy $ */
-
 #include <stddef.h>
 #include <mlvalues.h>
 #include <callback.h>
@@ -257,7 +255,8 @@
     if (unix_error_exn == NULL) {
       unix_error_exn = caml_named_value("Unix.Unix_error");
       if (unix_error_exn == NULL)
-        invalid_argument("Exception Unix.Unix_error not initialized, please link unix.cma");
+        invalid_argument("Exception Unix.Unix_error not initialized,"
+                         " please link unix.cma");
     }
     res = alloc_small(4, 0);
     Field(res, 0) = *unix_error_exn;
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/unixsupport.h ocaml-unix-4.01.0/otherlibs/win32unix/unixsupport.h
--- ocaml-unix-4.00.1/otherlibs/win32unix/unixsupport.h 2012-05-28 13:31:30.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/unixsupport.h 2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: unixsupport.h 12488 2012-05-28 11:31:30Z frisch $ */
-
 #define WIN32_LEAN_AND_MEAN
 #include <wtypes.h>
 #include <winbase.h>
@@ -20,7 +18,11 @@
 #include <direct.h>
 #include <process.h>
 #include <sys/types.h>
-#include <winsock.h>
+#include <winsock2.h>
+#ifdef HAS_IPV6
+#include <ws2tcpip.h>
+#include <wspiapi.h>
+#endif

 struct filedescr {
   union {
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/windbug.c ocaml-unix-4.01.0/otherlibs/win32unix/windbug.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/windbug.c     2012-07-30 20:59:07.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/windbug.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: windbug.c 12800 2012-07-30 18:59:07Z doligez $ */
-
 #include "windbug.h"

 int debug_test (void)
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/windbug.h ocaml-unix-4.01.0/otherlibs/win32unix/windbug.h
--- ocaml-unix-4.00.1/otherlibs/win32unix/windbug.h     2012-01-14 10:40:49.000000000 +0100
+++ ocaml-unix-4.01.0/otherlibs/win32unix/windbug.h     2013-07-23 16:48:47.000000000 +0200
@@ -11,21 +11,21 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: windbug.h 12023 2012-01-14 09:40:49Z xleroy $ */
-
 #ifdef DEBUG

 #include <stdio.h>
 #include <windows.h>

-/* According to MSDN, MSVC supports the gcc ## operator (to deal with empty argument lists)
+/* According to MSDN, MSVC supports the gcc ## operator (to deal with empty
+   argument lists)
  */
 #define DEBUG_PRINT(fmt, ...) \
   do \
   { \
     if (debug_test()) \
     { \
-      fprintf(stderr, "DBUG (pid:%ld, tid: %ld): ", GetCurrentProcessId(), GetCurrentThreadId()); \
+      fprintf(stderr, "DBUG (pid:%ld, tid: %ld): ", GetCurrentProcessId(), \
+              GetCurrentThreadId()); \
       fprintf(stderr, fmt, ##__VA_ARGS__); \
       fprintf(stderr, "\n"); \
       fflush(stderr); \
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/windir.c ocaml-unix-4.01.0/otherlibs/win32unix/windir.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/windir.c      2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/windir.c      2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: windir.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <mlvalues.h>
 #include <memory.h>
 #include <errno.h>
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/winlist.c ocaml-unix-4.01.0/otherlibs/win32unix/winlist.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/winlist.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/winlist.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: winlist.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 /* Basic list function in C. */

 #include "winlist.h"
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/winlist.h ocaml-unix-4.01.0/otherlibs/win32unix/winlist.h
--- ocaml-unix-4.00.1/otherlibs/win32unix/winlist.h     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/winlist.h     2012-10-15 19:50:56.000000000 +0200
@@ -11,7 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: winlist.h 11156 2011-07-27 14:17:02Z doligez $ */
 #ifndef _WINLIST_H
 #define _WINLIST_H

diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/winwait.c ocaml-unix-4.01.0/otherlibs/win32unix/winwait.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/winwait.c     2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/winwait.c     2012-10-15 19:50:56.000000000 +0200
@@ -11,15 +11,13 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: winwait.c 11156 2011-07-27 14:17:02Z doligez $ */
-
-#include <windows.h>
 #include <mlvalues.h>
 #include <alloc.h>
 #include <memory.h>
+#include <signals.h>
 #include "unixsupport.h"
+#include <windows.h>
 #include <sys/types.h>
-#include <signals.h>

 static value alloc_process_status(HANDLE pid, int status)
 {
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/winworker.c ocaml-unix-4.01.0/otherlibs/win32unix/winworker.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/winworker.c   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/winworker.c   2013-07-23 16:48:47.000000000 +0200
@@ -11,14 +11,13 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: winworker.c 11156 2011-07-27 14:17:02Z doligez $ */
-
+#include <mlvalues.h>
+#include <alloc.h>
+#include <memory.h>
+#include <signals.h>
 #include "winworker.h"
 #include "winlist.h"
 #include "windbug.h"
-#include <mlvalues.h>
-#include <alloc.h>
-#include "unixsupport.h"

 typedef enum {
   WORKER_CMD_NONE = 0,
@@ -28,10 +27,11 @@

 struct _WORKER {
   LIST       lst;           /* This structure is used as a list. */
-  HANDLE     hJobStarted;   /* Event representing that the function has begun. */
-  HANDLE     hJobStop;      /* Event that can be used to notify the function that it
-                               should stop processing. */
-  HANDLE     hJobDone;      /* Event representing that the function has finished. */
+  HANDLE     hJobStarted;   /* Event representing that the function has begun.*/
+  HANDLE     hJobStop;      /* Event that can be used to notify the function
+                               that it should stop processing. */
+  HANDLE     hJobDone;      /* Event representing that the function has
+                               finished. */
   void      *lpJobUserData; /* User data for the job. */
   WORKERFUNC hJobFunc;      /* Function to be called during APC */
   HANDLE     hWorkerReady;  /* Worker is ready. */
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/winworker.h ocaml-unix-4.01.0/otherlibs/win32unix/winworker.h
--- ocaml-unix-4.00.1/otherlibs/win32unix/winworker.h   2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/winworker.h   2012-10-15 19:50:56.000000000 +0200
@@ -11,11 +11,11 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: winworker.h 11156 2011-07-27 14:17:02Z doligez $ */
 #ifndef _WINWORKER_H
 #define _WINWORKER_H

 #define _WIN32_WINNT 0x0400
+#include "unixsupport.h"
 #include <windows.h>

 /* Pool of worker threads.
diff -Naur ocaml-unix-4.00.1/otherlibs/win32unix/write.c ocaml-unix-4.01.0/otherlibs/win32unix/write.c
--- ocaml-unix-4.00.1/otherlibs/win32unix/write.c       2011-07-27 16:17:02.000000000 +0200
+++ ocaml-unix-4.01.0/otherlibs/win32unix/write.c       2012-10-15 19:50:56.000000000 +0200
@@ -11,8 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: write.c 11156 2011-07-27 14:17:02Z doligez $ */
-
 #include <errno.h>
 #include <string.h>
 #include <mlvalues.h>