diff -Naur ocaml-unix-3.12.1/otherlibs/unix/accept.c ocaml-unix-4.00.1/otherlibs/unix/accept.c
--- ocaml-unix-3.12.1/otherlibs/unix/accept.c   2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/accept.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: accept.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: accept.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/access.c ocaml-unix-4.00.1/otherlibs/unix/access.c
--- ocaml-unix-3.12.1/otherlibs/unix/access.c   2008-01-11 17:13:18.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/access.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: access.c 8768 2008-01-11 16:13:18Z doligez $ */
+/* $Id: access.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/addrofstr.c ocaml-unix-4.00.1/otherlibs/unix/addrofstr.c
--- ocaml-unix-3.12.1/otherlibs/unix/addrofstr.c        2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/addrofstr.c        2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: addrofstr.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: addrofstr.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <fail.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/alarm.c ocaml-unix-4.00.1/otherlibs/unix/alarm.c
--- ocaml-unix-3.12.1/otherlibs/unix/alarm.c    2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/alarm.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: alarm.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: alarm.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/bind.c ocaml-unix-4.00.1/otherlibs/unix/bind.c
--- ocaml-unix-3.12.1/otherlibs/unix/bind.c     2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/bind.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: bind.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: bind.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <fail.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/chdir.c ocaml-unix-4.00.1/otherlibs/unix/chdir.c
--- ocaml-unix-3.12.1/otherlibs/unix/chdir.c    2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/chdir.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: chdir.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: chdir.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/chmod.c ocaml-unix-4.00.1/otherlibs/unix/chmod.c
--- ocaml-unix-3.12.1/otherlibs/unix/chmod.c    2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/chmod.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: chmod.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: chmod.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <sys/types.h>
 #include <sys/stat.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/chown.c ocaml-unix-4.00.1/otherlibs/unix/chown.c
--- ocaml-unix-3.12.1/otherlibs/unix/chown.c    2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/chown.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: chown.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: chown.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/chroot.c ocaml-unix-4.00.1/otherlibs/unix/chroot.c
--- ocaml-unix-3.12.1/otherlibs/unix/chroot.c   2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/chroot.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: chroot.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: chroot.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/close.c ocaml-unix-4.00.1/otherlibs/unix/close.c
--- ocaml-unix-3.12.1/otherlibs/unix/close.c    2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/close.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: close.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: close.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/closedir.c ocaml-unix-4.00.1/otherlibs/unix/closedir.c
--- ocaml-unix-3.12.1/otherlibs/unix/closedir.c 2004-02-14 11:21:23.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/closedir.c 2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: closedir.c 6113 2004-02-14 10:21:23Z xleroy $ */
+/* $Id: closedir.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/connect.c ocaml-unix-4.00.1/otherlibs/unix/connect.c
--- ocaml-unix-3.12.1/otherlibs/unix/connect.c  2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/connect.c  2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: connect.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: connect.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <fail.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/cst2constr.c ocaml-unix-4.00.1/otherlibs/unix/cst2constr.c
--- ocaml-unix-3.12.1/otherlibs/unix/cst2constr.c       2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/cst2constr.c       2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: cst2constr.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: cst2constr.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <fail.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/cst2constr.h ocaml-unix-4.00.1/otherlibs/unix/cst2constr.h
--- ocaml-unix-3.12.1/otherlibs/unix/cst2constr.h       2004-04-09 15:25:23.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/unix/cst2constr.h       2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,6 +11,6 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: cst2constr.h 6193 2004-04-09 13:25:23Z xleroy $ */
+/* $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-3.12.1/otherlibs/unix/cstringv.c ocaml-unix-4.00.1/otherlibs/unix/cstringv.c
--- ocaml-unix-3.12.1/otherlibs/unix/cstringv.c 2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/cstringv.c 2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: cstringv.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: cstringv.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <memory.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/.depend ocaml-unix-4.00.1/otherlibs/unix/.depend
--- ocaml-unix-3.12.1/otherlibs/unix/.depend    2011-07-04 23:15:01.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/unix/.depend    2012-07-25 15:39:21.000000000 +0200
@@ -449,9 +449,9 @@
   ../../byterun/gc.h ../../byterun/mlvalues.h ../../byterun/major_gc.h \
   ../../byterun/freelist.h ../../byterun/minor_gc.h \
   ../../byterun/signals.h unixsupport.h
-unix.cmi:
-unixLabels.cmi: unix.cmi
-unix.cmo: unix.cmi
-unix.cmx: unix.cmi
-unixLabels.cmo: unix.cmi unixLabels.cmi
-unixLabels.cmx: unix.cmx unixLabels.cmi
+unix.cmi :
+unixLabels.cmi : unix.cmi
+unix.cmo : unix.cmi
+unix.cmx : unix.cmi
+unixLabels.cmo : unix.cmi unixLabels.cmi
+unixLabels.cmx : unix.cmx unixLabels.cmi
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/dup2.c ocaml-unix-4.00.1/otherlibs/unix/dup2.c
--- ocaml-unix-3.12.1/otherlibs/unix/dup2.c     2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/dup2.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: dup2.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: dup2.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/dup.c ocaml-unix-4.00.1/otherlibs/unix/dup.c
--- ocaml-unix-3.12.1/otherlibs/unix/dup.c      2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/dup.c      2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: dup.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: dup.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/envir.c ocaml-unix-4.00.1/otherlibs/unix/envir.c
--- ocaml-unix-3.12.1/otherlibs/unix/envir.c    2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/envir.c    2011-09-05 11:25:26.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: envir.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: envir.c 11176 2011-09-05 09:25:26Z xclerc $ */

 #include <mlvalues.h>
 #include <alloc.h>
@@ -22,5 +22,9 @@

 CAMLprim value unix_environment(value unit)
 {
-  return copy_string_array((const char**)environ);
+  if (environ != NULL) {
+    return copy_string_array((const char**)environ);
+  } else {
+    return Atom(0);
+  }
 }
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/errmsg.c ocaml-unix-4.00.1/otherlibs/unix/errmsg.c
--- ocaml-unix-3.12.1/otherlibs/unix/errmsg.c   2004-05-23 17:53:50.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/unix/errmsg.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: errmsg.c 6315 2004-05-23 15:53:50Z xleroy $ */
+/* $Id: errmsg.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <errno.h>
 #include <string.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/execv.c ocaml-unix-4.00.1/otherlibs/unix/execv.c
--- ocaml-unix-3.12.1/otherlibs/unix/execv.c    2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/execv.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: execv.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: execv.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <memory.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/execve.c ocaml-unix-4.00.1/otherlibs/unix/execve.c
--- ocaml-unix-3.12.1/otherlibs/unix/execve.c   2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/execve.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: execve.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: execve.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <memory.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/execvp.c ocaml-unix-4.00.1/otherlibs/unix/execvp.c
--- ocaml-unix-3.12.1/otherlibs/unix/execvp.c   2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/execvp.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: execvp.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: execvp.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <memory.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/exit.c ocaml-unix-4.00.1/otherlibs/unix/exit.c
--- ocaml-unix-3.12.1/otherlibs/unix/exit.c     2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/exit.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: exit.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: exit.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/fchmod.c ocaml-unix-4.00.1/otherlibs/unix/fchmod.c
--- ocaml-unix-3.12.1/otherlibs/unix/fchmod.c   2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/fchmod.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: fchmod.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: fchmod.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <sys/types.h>
 #include <sys/stat.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/fchown.c ocaml-unix-4.00.1/otherlibs/unix/fchown.c
--- ocaml-unix-3.12.1/otherlibs/unix/fchown.c   2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/fchown.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: fchown.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: fchown.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <fail.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/fcntl.c ocaml-unix-4.00.1/otherlibs/unix/fcntl.c
--- ocaml-unix-3.12.1/otherlibs/unix/fcntl.c    2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/fcntl.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: fcntl.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: fcntl.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <fail.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/fork.c ocaml-unix-4.00.1/otherlibs/unix/fork.c
--- ocaml-unix-3.12.1/otherlibs/unix/fork.c     2010-04-20 17:47:15.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/unix/fork.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: fork.c 10287 2010-04-20 15:47:15Z doligez $ */
+/* $Id: fork.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <debugger.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/ftruncate.c ocaml-unix-4.00.1/otherlibs/unix/ftruncate.c
--- ocaml-unix-3.12.1/otherlibs/unix/ftruncate.c        2007-02-09 14:31:15.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/ftruncate.c        2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: ftruncate.c 7849 2007-02-09 13:31:15Z doligez $ */
+/* $Id: ftruncate.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <sys/types.h>
 #include <fail.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getaddrinfo.c ocaml-unix-4.00.1/otherlibs/unix/getaddrinfo.c
--- ocaml-unix-3.12.1/otherlibs/unix/getaddrinfo.c      2005-08-13 22:59:37.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/unix/getaddrinfo.c      2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getaddrinfo.c 7019 2005-08-13 20:59:37Z doligez $ */
+/* $Id: getaddrinfo.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <string.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getcwd.c ocaml-unix-4.00.1/otherlibs/unix/getcwd.c
--- ocaml-unix-3.12.1/otherlibs/unix/getcwd.c   2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/getcwd.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getcwd.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: getcwd.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getegid.c ocaml-unix-4.00.1/otherlibs/unix/getegid.c
--- ocaml-unix-3.12.1/otherlibs/unix/getegid.c  2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/getegid.c  2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getegid.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: getegid.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/geteuid.c ocaml-unix-4.00.1/otherlibs/unix/geteuid.c
--- ocaml-unix-3.12.1/otherlibs/unix/geteuid.c  2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/geteuid.c  2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: geteuid.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: geteuid.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getgid.c ocaml-unix-4.00.1/otherlibs/unix/getgid.c
--- ocaml-unix-3.12.1/otherlibs/unix/getgid.c   2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/getgid.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getgid.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: getgid.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getgr.c ocaml-unix-4.00.1/otherlibs/unix/getgr.c
--- ocaml-unix-3.12.1/otherlibs/unix/getgr.c    2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/getgr.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getgr.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: getgr.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <fail.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getgroups.c ocaml-unix-4.00.1/otherlibs/unix/getgroups.c
--- ocaml-unix-3.12.1/otherlibs/unix/getgroups.c        2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/getgroups.c        2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getgroups.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: getgroups.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/gethost.c ocaml-unix-4.00.1/otherlibs/unix/gethost.c
--- ocaml-unix-3.12.1/otherlibs/unix/gethost.c  2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/gethost.c  2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: gethost.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: gethost.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <string.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/gethostname.c ocaml-unix-4.00.1/otherlibs/unix/gethostname.c
--- ocaml-unix-3.12.1/otherlibs/unix/gethostname.c      2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/gethostname.c      2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: gethostname.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: gethostname.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getlogin.c ocaml-unix-4.00.1/otherlibs/unix/getlogin.c
--- ocaml-unix-3.12.1/otherlibs/unix/getlogin.c 2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/getlogin.c 2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getlogin.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: getlogin.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getnameinfo.c ocaml-unix-4.00.1/otherlibs/unix/getnameinfo.c
--- ocaml-unix-3.12.1/otherlibs/unix/getnameinfo.c      2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/getnameinfo.c      2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getnameinfo.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: getnameinfo.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <string.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getpeername.c ocaml-unix-4.00.1/otherlibs/unix/getpeername.c
--- ocaml-unix-3.12.1/otherlibs/unix/getpeername.c      2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/getpeername.c      2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getpeername.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: getpeername.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <fail.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getpid.c ocaml-unix-4.00.1/otherlibs/unix/getpid.c
--- ocaml-unix-3.12.1/otherlibs/unix/getpid.c   2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/getpid.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getpid.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: getpid.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getppid.c ocaml-unix-4.00.1/otherlibs/unix/getppid.c
--- ocaml-unix-3.12.1/otherlibs/unix/getppid.c  2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/getppid.c  2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getppid.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: getppid.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getproto.c ocaml-unix-4.00.1/otherlibs/unix/getproto.c
--- ocaml-unix-3.12.1/otherlibs/unix/getproto.c 2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/getproto.c 2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getproto.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: getproto.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getpw.c ocaml-unix-4.00.1/otherlibs/unix/getpw.c
--- ocaml-unix-3.12.1/otherlibs/unix/getpw.c    2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/getpw.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getpw.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: getpw.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getserv.c ocaml-unix-4.00.1/otherlibs/unix/getserv.c
--- ocaml-unix-3.12.1/otherlibs/unix/getserv.c  2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/getserv.c  2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getserv.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: getserv.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getsockname.c ocaml-unix-4.00.1/otherlibs/unix/getsockname.c
--- ocaml-unix-3.12.1/otherlibs/unix/getsockname.c      2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/getsockname.c      2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getsockname.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: getsockname.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <fail.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/gettimeofday.c ocaml-unix-4.00.1/otherlibs/unix/gettimeofday.c
--- ocaml-unix-3.12.1/otherlibs/unix/gettimeofday.c     2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/gettimeofday.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: gettimeofday.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: gettimeofday.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/getuid.c ocaml-unix-4.00.1/otherlibs/unix/getuid.c
--- ocaml-unix-3.12.1/otherlibs/unix/getuid.c   2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/getuid.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getuid.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: getuid.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/gmtime.c ocaml-unix-4.00.1/otherlibs/unix/gmtime.c
--- ocaml-unix-3.12.1/otherlibs/unix/gmtime.c   2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/gmtime.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: gmtime.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: gmtime.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/initgroups.c ocaml-unix-4.00.1/otherlibs/unix/initgroups.c
--- ocaml-unix-3.12.1/otherlibs/unix/initgroups.c       2009-04-16 09:23:35.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/unix/initgroups.c       2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,8 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
+/*                                                                     */
+/*  Contributed by Stephane Glondu <steph@glondu.net>                  */
 /*                                                                     */
 /*  Copyright 2009 Institut National de Recherche en Informatique et   */
 /*  en Automatique.  All rights reserved.  This file is distributed    */
@@ -9,9 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* Contributed by Stephane Glondu <steph@glondu.net> */
-
-/* $Id: initgroups.c 9235 2009-04-16 07:23:35Z xleroy $ */
+/* $Id: initgroups.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/isatty.c ocaml-unix-4.00.1/otherlibs/unix/isatty.c
--- ocaml-unix-3.12.1/otherlibs/unix/isatty.c   2006-09-21 15:54:26.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/unix/isatty.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Gallium, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: isatty.c 7632 2006-09-21 13:54:26Z xleroy $ */
+/* $Id: isatty.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/itimer.c ocaml-unix-4.00.1/otherlibs/unix/itimer.c
--- ocaml-unix-3.12.1/otherlibs/unix/itimer.c   2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/itimer.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: itimer.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: itimer.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/kill.c ocaml-unix-4.00.1/otherlibs/unix/kill.c
--- ocaml-unix-3.12.1/otherlibs/unix/kill.c     2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/kill.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: kill.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: kill.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <fail.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/link.c ocaml-unix-4.00.1/otherlibs/unix/link.c
--- ocaml-unix-3.12.1/otherlibs/unix/link.c     2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/link.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: link.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: link.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/listen.c ocaml-unix-4.00.1/otherlibs/unix/listen.c
--- ocaml-unix-3.12.1/otherlibs/unix/listen.c   2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/listen.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: listen.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: listen.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <fail.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/lockf.c ocaml-unix-4.00.1/otherlibs/unix/lockf.c
--- ocaml-unix-3.12.1/otherlibs/unix/lockf.c    2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/lockf.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: lockf.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: lockf.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <errno.h>
 #include <fcntl.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/lseek.c ocaml-unix-4.00.1/otherlibs/unix/lseek.c
--- ocaml-unix-3.12.1/otherlibs/unix/lseek.c    2010-08-18 14:44:33.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/unix/lseek.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: lseek.c 10647 2010-08-18 12:44:33Z doligez $ */
+/* $Id: lseek.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <errno.h>
 #include <sys/types.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/Makefile ocaml-unix-4.00.1/otherlibs/unix/Makefile
--- ocaml-unix-3.12.1/otherlibs/unix/Makefile   2010-05-20 11:40:41.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/unix/Makefile   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 #########################################################################
 #                                                                       #
-#                            Objective Caml                             #
+#                                 OCaml                                 #
 #                                                                       #
 #            Xavier Leroy, projet Cristal, INRIA Rocquencourt           #
 #                                                                       #
@@ -11,7 +11,7 @@
 #                                                                       #
 #########################################################################

-# $Id: Makefile 10442 2010-05-20 09:40:41Z xleroy $
+# $Id: Makefile 11156 2011-07-27 14:17:02Z doligez $

 # Makefile for the Unix interface library

diff -Naur ocaml-unix-3.12.1/otherlibs/unix/mkdir.c ocaml-unix-4.00.1/otherlibs/unix/mkdir.c
--- ocaml-unix-3.12.1/otherlibs/unix/mkdir.c    2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/mkdir.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: mkdir.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: mkdir.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <sys/types.h>
 #include <sys/stat.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/mkfifo.c ocaml-unix-4.00.1/otherlibs/unix/mkfifo.c
--- ocaml-unix-3.12.1/otherlibs/unix/mkfifo.c   2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/mkfifo.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: mkfifo.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: mkfifo.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <sys/types.h>
 #include <sys/stat.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/nice.c ocaml-unix-4.00.1/otherlibs/unix/nice.c
--- ocaml-unix-3.12.1/otherlibs/unix/nice.c     2008-08-01 15:14:36.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/unix/nice.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: nice.c 8967 2008-08-01 13:14:36Z xleroy $ */
+/* $Id: nice.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/open.c ocaml-unix-4.00.1/otherlibs/unix/open.c
--- ocaml-unix-3.12.1/otherlibs/unix/open.c     2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/open.c     2011-12-13 17:18:13.000000000 +0100
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: open.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: open.c 11304 2011-12-13 16:18:13Z frisch $ */

 #include <mlvalues.h>
 #include <alloc.h>
@@ -36,7 +36,7 @@

 static int open_flag_table[] = {
   O_RDONLY, O_WRONLY, O_RDWR, O_NONBLOCK, O_APPEND, O_CREAT, O_TRUNC, O_EXCL,
-  O_NOCTTY, O_DSYNC, O_SYNC, O_RSYNC
+  O_NOCTTY, O_DSYNC, O_SYNC, O_RSYNC, 0
 };

 CAMLprim value unix_open(value path, value flags, value perm)
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/opendir.c ocaml-unix-4.00.1/otherlibs/unix/opendir.c
--- ocaml-unix-3.12.1/otherlibs/unix/opendir.c  2004-02-14 11:21:23.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/opendir.c  2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: opendir.c 6113 2004-02-14 10:21:23Z xleroy $ */
+/* $Id: opendir.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/pipe.c ocaml-unix-4.00.1/otherlibs/unix/pipe.c
--- ocaml-unix-3.12.1/otherlibs/unix/pipe.c     2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/pipe.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: pipe.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: pipe.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/putenv.c ocaml-unix-4.00.1/otherlibs/unix/putenv.c
--- ocaml-unix-3.12.1/otherlibs/unix/putenv.c   2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/putenv.c   2012-03-08 20:52:03.000000000 +0100
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: putenv.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: putenv.c 12210 2012-03-08 19:52:03Z doligez $ */

 #include <stdlib.h>
 #include <string.h>
@@ -28,13 +28,16 @@
 {
   mlsize_t namelen = string_length(name);
   mlsize_t vallen = string_length(val);
-  char * s = (char *) stat_alloc(namelen + 1 + vallen + 1);
+  char * s = (char *) caml_stat_alloc(namelen + 1 + vallen + 1);

   memmove (s, String_val(name), namelen);
   s[namelen] = '=';
   memmove (s + namelen + 1, String_val(val), vallen);
   s[namelen + 1 + vallen] = 0;
-  if (putenv(s) == -1) uerror("putenv", name);
+  if (putenv(s) == -1) {
+    caml_stat_free(s);
+    uerror("putenv", name);
+  }
   return Val_unit;
 }

diff -Naur ocaml-unix-3.12.1/otherlibs/unix/read.c ocaml-unix-4.00.1/otherlibs/unix/read.c
--- ocaml-unix-3.12.1/otherlibs/unix/read.c     2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/read.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: read.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: read.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <string.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/readdir.c ocaml-unix-4.00.1/otherlibs/unix/readdir.c
--- ocaml-unix-3.12.1/otherlibs/unix/readdir.c  2004-02-14 11:21:23.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/readdir.c  2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: readdir.c 6113 2004-02-14 10:21:23Z xleroy $ */
+/* $Id: readdir.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <fail.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/readlink.c ocaml-unix-4.00.1/otherlibs/unix/readlink.c
--- ocaml-unix-3.12.1/otherlibs/unix/readlink.c 2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/readlink.c 2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: readlink.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: readlink.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/rename.c ocaml-unix-4.00.1/otherlibs/unix/rename.c
--- ocaml-unix-3.12.1/otherlibs/unix/rename.c   2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/rename.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: rename.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: rename.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <stdio.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/rewinddir.c ocaml-unix-4.00.1/otherlibs/unix/rewinddir.c
--- ocaml-unix-3.12.1/otherlibs/unix/rewinddir.c        2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/rewinddir.c        2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: rewinddir.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: rewinddir.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <fail.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/rmdir.c ocaml-unix-4.00.1/otherlibs/unix/rmdir.c
--- ocaml-unix-3.12.1/otherlibs/unix/rmdir.c    2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/rmdir.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: rmdir.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: rmdir.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/select.c ocaml-unix-4.00.1/otherlibs/unix/select.c
--- ocaml-unix-3.12.1/otherlibs/unix/select.c   2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/select.c   2012-09-24 13:25:32.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: select.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: select.c 12947 2012-09-24 11:25:32Z xleroy $ */

 #include <mlvalues.h>
 #include <alloc.h>
@@ -29,18 +29,20 @@
 #endif
 #include <string.h>
 #include <unistd.h>
+#include <errno.h>

-typedef fd_set file_descr_set;
-
-static void fdlist_to_fdset(value fdlist, fd_set *fdset, int *maxfd)
+static int fdlist_to_fdset(value fdlist, fd_set *fdset, int *maxfd)
 {
   value l;
   FD_ZERO(fdset);
   for (l = fdlist; l != Val_int(0); l = Field(l, 1)) {
-    int fd = Int_val(Field(l, 0));
-    FD_SET(fd, fdset);
+    long fd = Long_val(Field(l, 0));
+    /* PR#5563: harden against bad fds */
+    if (fd < 0 || fd >= FD_SETSIZE) return -1;
+    FD_SET((int) fd, fdset);
     if (fd > *maxfd) *maxfd = fd;
   }
+  return 0;
 }

 static value fdset_to_fdlist(value fdlist, fd_set *fdset)
@@ -75,9 +77,11 @@

   Begin_roots3 (readfds, writefds, exceptfds);
     maxfd = -1;
-    fdlist_to_fdset(readfds, &read, &maxfd);
-    fdlist_to_fdset(writefds, &write, &maxfd);
-    fdlist_to_fdset(exceptfds, &except, &maxfd);
+    retcode  = fdlist_to_fdset(readfds, &read, &maxfd);
+    retcode += fdlist_to_fdset(writefds, &write, &maxfd);
+    retcode += fdlist_to_fdset(exceptfds, &except, &maxfd);
+    /* PR#5563: if a bad fd was encountered, report EINVAL error */
+    if (retcode != 0) unix_error(EINVAL, "select", Nothing);
     tm = Double_val(timeout);
     if (tm < 0.0)
       tvp = (struct timeval *) NULL;
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/sendrecv.c ocaml-unix-4.00.1/otherlibs/unix/sendrecv.c
--- ocaml-unix-3.12.1/otherlibs/unix/sendrecv.c 2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/sendrecv.c 2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: sendrecv.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: sendrecv.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <string.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/setgid.c ocaml-unix-4.00.1/otherlibs/unix/setgid.c
--- ocaml-unix-3.12.1/otherlibs/unix/setgid.c   2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/setgid.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: setgid.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: setgid.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/setgroups.c ocaml-unix-4.00.1/otherlibs/unix/setgroups.c
--- ocaml-unix-3.12.1/otherlibs/unix/setgroups.c        2009-04-01 18:50:10.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/unix/setgroups.c        2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,8 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
+/*                                                                     */
+/* Contributed by Stephane Glondu <steph@glondu.net>                   */
 /*                                                                     */
 /*  Copyright 2009 Institut National de Recherche en Informatique et   */
 /*  en Automatique.  All rights reserved.  This file is distributed    */
@@ -9,9 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* Contributed by Stephane Glondu <steph@glondu.net> */
-
-/* $Id: setgroups.c 9220 2009-04-01 16:50:10Z xleroy $ */
+/* $Id: setgroups.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/setsid.c ocaml-unix-4.00.1/otherlibs/unix/setsid.c
--- ocaml-unix-3.12.1/otherlibs/unix/setsid.c   2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/setsid.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: setsid.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: setsid.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <fail.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/setuid.c ocaml-unix-4.00.1/otherlibs/unix/setuid.c
--- ocaml-unix-3.12.1/otherlibs/unix/setuid.c   2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/setuid.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: setuid.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: setuid.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/shutdown.c ocaml-unix-4.00.1/otherlibs/unix/shutdown.c
--- ocaml-unix-3.12.1/otherlibs/unix/shutdown.c 2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/shutdown.c 2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: shutdown.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: shutdown.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <fail.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/signals.c ocaml-unix-4.00.1/otherlibs/unix/signals.c
--- ocaml-unix-3.12.1/otherlibs/unix/signals.c  2008-01-11 17:13:18.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/signals.c  2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: signals.c 8768 2008-01-11 16:13:18Z doligez $ */
+/* $Id: signals.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <errno.h>
 #include <signal.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/sleep.c ocaml-unix-4.00.1/otherlibs/unix/sleep.c
--- ocaml-unix-3.12.1/otherlibs/unix/sleep.c    2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/sleep.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: sleep.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: sleep.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <signals.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/socketaddr.c ocaml-unix-4.00.1/otherlibs/unix/socketaddr.c
--- ocaml-unix-3.12.1/otherlibs/unix/socketaddr.c       2010-01-20 17:26:46.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/socketaddr.c       2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: socketaddr.c 9540 2010-01-20 16:26:46Z doligez $ */
+/* $Id: socketaddr.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <string.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/socketaddr.h ocaml-unix-4.00.1/otherlibs/unix/socketaddr.h
--- ocaml-unix-3.12.1/otherlibs/unix/socketaddr.h       2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/socketaddr.h       2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: socketaddr.h 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: socketaddr.h 11156 2011-07-27 14:17:02Z doligez $ */

 #include <misc.h>
 #include <sys/types.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/socket.c ocaml-unix-4.00.1/otherlibs/unix/socket.c
--- ocaml-unix-3.12.1/otherlibs/unix/socket.c   2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/socket.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: socket.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: socket.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <fail.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/socketpair.c ocaml-unix-4.00.1/otherlibs/unix/socketpair.c
--- ocaml-unix-3.12.1/otherlibs/unix/socketpair.c       2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/socketpair.c       2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: socketpair.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: socketpair.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/sockopt.c ocaml-unix-4.00.1/otherlibs/unix/sockopt.c
--- ocaml-unix-3.12.1/otherlibs/unix/sockopt.c  2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/sockopt.c  2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: sockopt.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: sockopt.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <memory.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/stat.c ocaml-unix-4.00.1/otherlibs/unix/stat.c
--- ocaml-unix-3.12.1/otherlibs/unix/stat.c     2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/stat.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: stat.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: stat.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <errno.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/strofaddr.c ocaml-unix-4.00.1/otherlibs/unix/strofaddr.c
--- ocaml-unix-3.12.1/otherlibs/unix/strofaddr.c        2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/strofaddr.c        2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: strofaddr.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: strofaddr.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/symlink.c ocaml-unix-4.00.1/otherlibs/unix/symlink.c
--- ocaml-unix-3.12.1/otherlibs/unix/symlink.c  2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/symlink.c  2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: symlink.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: symlink.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <fail.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/termios.c ocaml-unix-4.00.1/otherlibs/unix/termios.c
--- ocaml-unix-3.12.1/otherlibs/unix/termios.c  2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/termios.c  2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: termios.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: termios.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/time.c ocaml-unix-4.00.1/otherlibs/unix/time.c
--- ocaml-unix-3.12.1/otherlibs/unix/time.c     2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/time.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: time.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: time.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <time.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/times.c ocaml-unix-4.00.1/otherlibs/unix/times.c
--- ocaml-unix-3.12.1/otherlibs/unix/times.c    2006-04-17 01:28:22.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/unix/times.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: times.c 7382 2006-04-16 23:28:22Z doligez $ */
+/* $Id: times.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/truncate.c ocaml-unix-4.00.1/otherlibs/unix/truncate.c
--- ocaml-unix-3.12.1/otherlibs/unix/truncate.c 2007-02-09 14:31:15.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/truncate.c 2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: truncate.c 7849 2007-02-09 13:31:15Z doligez $ */
+/* $Id: truncate.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <sys/types.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/umask.c ocaml-unix-4.00.1/otherlibs/unix/umask.c
--- ocaml-unix-3.12.1/otherlibs/unix/umask.c    2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/umask.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: umask.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: umask.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <sys/types.h>
 #include <sys/stat.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/unixLabels.ml ocaml-unix-4.00.1/otherlibs/unix/unixLabels.ml
--- ocaml-unix-3.12.1/otherlibs/unix/unixLabels.ml      2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/unixLabels.ml      2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 (***********************************************************************)
 (*                                                                     *)
-(*                           Objective Caml                            *)
+(*                                OCaml                                *)
 (*                                                                     *)
 (*               Jacques Garrigue, Kyoto University RIMS               *)
 (*                                                                     *)
@@ -11,7 +11,7 @@
 (*                                                                     *)
 (***********************************************************************)

-(* $Id: unixLabels.ml 4144 2001-12-07 13:41:02Z xleroy $ *)
+(* $Id: unixLabels.ml 11156 2011-07-27 14:17:02Z doligez $ *)

 (* Module [UnixLabels]: labelled Unix module *)

diff -Naur ocaml-unix-3.12.1/otherlibs/unix/unixLabels.mli ocaml-unix-4.00.1/otherlibs/unix/unixLabels.mli
--- ocaml-unix-3.12.1/otherlibs/unix/unixLabels.mli     2011-03-06 17:15:34.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/unixLabels.mli     2011-12-13 18:59:10.000000000 +0100
@@ -1,6 +1,6 @@
 (***********************************************************************)
 (*                                                                     *)
-(*                           Objective Caml                            *)
+(*                                OCaml                                *)
 (*                                                                     *)
 (*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         *)
 (*                                                                     *)
@@ -11,7 +11,7 @@
 (*                                                                     *)
 (***********************************************************************)

-(* $Id: unixLabels.mli 10971 2011-03-06 16:15:34Z weis $ *)
+(* $Id: unixLabels.mli 11307 2011-12-13 17:59:10Z frisch $ *)

 (** Interface to the Unix system.
    To use as replacement to default {!Unix} module,
@@ -240,6 +240,7 @@
   | O_DSYNC                     (** Writes complete as `Synchronised I/O data integrity completion' *)
   | 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 *)
 (** The flags to {!UnixLabels.openfile}. *)


diff -Naur ocaml-unix-3.12.1/otherlibs/unix/unix.ml ocaml-unix-4.00.1/otherlibs/unix/unix.ml
--- ocaml-unix-3.12.1/otherlibs/unix/unix.ml    2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/unix.ml    2012-01-18 10:28:05.000000000 +0100
@@ -1,6 +1,6 @@
 (***********************************************************************)
 (*                                                                     *)
-(*                           Objective Caml                            *)
+(*                                OCaml                                *)
 (*                                                                     *)
 (*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         *)
 (*                                                                     *)
@@ -11,7 +11,7 @@
 (*                                                                     *)
 (***********************************************************************)

-(* $Id: unix.ml 9547 2010-01-22 12:48:24Z doligez $ *)
+(* $Id: unix.ml 12038 2012-01-18 09:28:05Z protzenk $ *)

 type error =
     E2BIG
@@ -151,6 +151,7 @@
   | O_DSYNC
   | O_SYNC
   | O_RSYNC
+  | O_SHARE_DELETE

 type file_perm = int

@@ -838,27 +839,47 @@
 let open_process_in cmd =
   let (in_read, in_write) = pipe() in
   let inchan = in_channel_of_descr in_read in
-  open_proc cmd (Process_in inchan) stdin in_write [in_read];
+  begin
+    try
+      open_proc cmd (Process_in inchan) stdin in_write [in_read];
+    with e ->
+      close_in inchan;
+      close in_write;
+      raise e
+  end;
   close in_write;
   inchan

 let open_process_out cmd =
   let (out_read, out_write) = pipe() in
   let outchan = out_channel_of_descr out_write in
-  open_proc cmd (Process_out outchan) out_read stdout [out_write];
+  begin
+    try
+      open_proc cmd (Process_out outchan) out_read stdout [out_write];
+    with e ->
+      close_out outchan;
+      close out_read;
+      raise e
+  end;
   close out_read;
   outchan

 let open_process cmd =
   let (in_read, in_write) = pipe() in
-  let (out_read, out_write) = pipe() in
-  let inchan = in_channel_of_descr in_read in
-  let outchan = out_channel_of_descr out_write in
-  open_proc cmd (Process(inchan, outchan)) out_read in_write
+  let fds_to_close = ref [in_read;in_write] in
+  try
+    let (out_read, out_write) = pipe() in
+    fds_to_close := [in_read;in_write;out_read;out_write];
+    let inchan = in_channel_of_descr in_read in
+    let outchan = out_channel_of_descr out_write in
+    open_proc cmd (Process(inchan, outchan)) out_read in_write
                                            [in_read; out_write];
-  close out_read;
-  close in_write;
-  (inchan, outchan)
+    close out_read;
+    close in_write;
+    (inchan, outchan)
+  with e ->
+    List.iter close !fds_to_close;
+    raise e

 let open_proc_full cmd env proc input output error toclose =
   let cloexec = List.for_all try_set_close_on_exec toclose in
@@ -874,17 +895,24 @@

 let open_process_full cmd env =
   let (in_read, in_write) = pipe() in
-  let (out_read, out_write) = pipe() in
-  let (err_read, err_write) = pipe() in
-  let inchan = in_channel_of_descr in_read in
-  let outchan = out_channel_of_descr out_write in
-  let errchan = in_channel_of_descr err_read in
-  open_proc_full cmd env (Process_full(inchan, outchan, errchan))
-                 out_read in_write err_write [in_read; out_write; err_read];
-  close out_read;
-  close in_write;
-  close err_write;
-  (inchan, outchan, errchan)
+  let fds_to_close = ref [in_read;in_write] in
+  try
+    let (out_read, out_write) = pipe() in
+    fds_to_close := out_read::out_write:: !fds_to_close;
+    let (err_read, err_write) = pipe() in
+    fds_to_close := err_read::err_write:: !fds_to_close;
+    let inchan = in_channel_of_descr in_read in
+    let outchan = out_channel_of_descr out_write in
+    let errchan = in_channel_of_descr err_read in
+    open_proc_full cmd env (Process_full(inchan, outchan, errchan))
+      out_read in_write err_write [in_read; out_write; err_read];
+    close out_read;
+    close in_write;
+    close err_write;
+    (inchan, outchan, errchan)
+  with e ->
+    List.iter close !fds_to_close;
+    raise e

 let find_proc_id fun_name proc =
   try
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/unix.mli ocaml-unix-4.00.1/otherlibs/unix/unix.mli
--- ocaml-unix-3.12.1/otherlibs/unix/unix.mli   2011-03-06 17:17:09.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/unix.mli   2012-02-07 17:41:02.000000000 +0100
@@ -1,6 +1,6 @@
 (***********************************************************************)
 (*                                                                     *)
-(*                           Objective Caml                            *)
+(*                                OCaml                                *)
 (*                                                                     *)
 (*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         *)
 (*                                                                     *)
@@ -11,7 +11,7 @@
 (*                                                                     *)
 (***********************************************************************)

-(* $Id: unix.mli 10972 2011-03-06 16:17:09Z weis $ *)
+(* $Id: unix.mli 12140 2012-02-07 16:41:02Z doligez $ *)

 (** Interface to the Unix system *)

@@ -122,7 +122,7 @@
 val getenv : string -> string
 (** Return the value associated to a variable in the process
    environment. Raise [Not_found] if the variable is unbound.
-   (This function is identical to [Sys.getenv].) *)
+   (This function is identical to {!Sys.getenv}.) *)

 val putenv : string -> string -> unit
 (** [Unix.putenv name value] sets the value associated to a
@@ -235,9 +235,14 @@
   | O_TRUNC                     (** Truncate to 0 length if existing *)
   | O_EXCL                      (** Fail if existing *)
   | O_NOCTTY                    (** Don't make this dev a controlling tty *)
-  | O_DSYNC                     (** Writes complete as `Synchronised I/O data integrity completion' *)
-  | O_SYNC                      (** Writes complete as `Synchronised I/O file integrity completion' *)
-  | O_RSYNC                     (** Reads complete as writes (depending on O_SYNC/O_DSYNC) *)
+  | O_DSYNC                     (** Writes complete as `Synchronised I/O data
+                                   integrity completion' *)
+  | 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 *)
 (** The flags to {!Unix.openfile}. *)


@@ -765,9 +770,11 @@

 type interval_timer =
     ITIMER_REAL
-      (** decrements in real time, and sends the signal [SIGALRM] when expired.*)
+      (** decrements in real time, and sends the signal [SIGALRM] when
+         expired.*)
   | ITIMER_VIRTUAL
-      (**  decrements in process virtual time, and sends [SIGVTALRM] when expired. *)
+      (** decrements in process virtual time, and sends [SIGVTALRM]
+          when expired. *)
   | ITIMER_PROF
       (** (for profiling) decrements both when the process
          is running and when the system is running on behalf of the
@@ -1022,8 +1029,9 @@
   | SO_RCVBUF      (** Size of received buffer *)
   | SO_ERROR       (** Deprecated.  Use {!Unix.getsockopt_error} instead. *)
   | SO_TYPE        (** Report the socket type *)
-  | SO_RCVLOWAT    (** Minimum number of bytes to process for input operations *)
-  | SO_SNDLOWAT    (** Minimum number of bytes to process for output operations *)
+  | SO_RCVLOWAT    (** Minimum number of bytes to process for input operations*)
+  | SO_SNDLOWAT    (** Minimum number of bytes to process for output
+                       operations *)
 (** The socket options that can be consulted with {!Unix.getsockopt_int}
    and modified with {!Unix.setsockopt_int}.  These options have an
    integer value. *)
@@ -1058,17 +1066,21 @@
 (** Same as {!Unix.setsockopt} for an integer-valued socket option. *)

 val getsockopt_optint : file_descr -> socket_optint_option -> int option
-(** Same as {!Unix.getsockopt} for a socket option whose value is an [int option]. *)
+(** Same as {!Unix.getsockopt} for a socket option whose value is an
+   [int option]. *)

 val setsockopt_optint :
       file_descr -> socket_optint_option -> int option -> unit
-(** Same as {!Unix.setsockopt} for a socket option whose value is an [int option]. *)
+(** Same as {!Unix.setsockopt} for a socket option whose value is an
+   [int option]. *)

 val getsockopt_float : file_descr -> socket_float_option -> float
-(** Same as {!Unix.getsockopt} for a socket option whose value is a floating-point number. *)
+(** Same as {!Unix.getsockopt} for a socket option whose value is a
+   floating-point number. *)

 val setsockopt_float : file_descr -> socket_float_option -> float -> unit
-(** Same as {!Unix.setsockopt} for a socket option whose value is a floating-point number. *)
+(** Same as {!Unix.setsockopt} for a socket option whose value is a
+   floating-point number. *)

 val getsockopt_error : file_descr -> error option
 (** Return the error condition associated with the given socket,
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/unixsupport.c ocaml-unix-4.00.1/otherlibs/unix/unixsupport.c
--- ocaml-unix-3.12.1/otherlibs/unix/unixsupport.c      2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/unixsupport.c      2011-12-21 14:08:48.000000000 +0100
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: unixsupport.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: unixsupport.c 11915 2011-12-21 13:08:48Z protzenk $ */

 #include <mlvalues.h>
 #include <alloc.h>
@@ -165,7 +165,11 @@
 #define ESOCKTNOSUPPORT (-1)
 #endif
 #ifndef EOPNOTSUPP
-#define EOPNOTSUPP (-1)
+#  ifdef ENOTSUP
+#    define EOPNOTSUPP ENOTSUP
+#  else
+#    define EOPNOTSUPP (-1)
+#  endif
 #endif
 #ifndef EPFNOSUPPORT
 #define EPFNOSUPPORT (-1)
@@ -252,6 +256,11 @@
   int errconstr;
   value err;

+#if defined(ENOTSUP) && (EOPNOTSUPP != ENOTSUP)
+  if (errcode == ENOTSUP)
+    errcode = EOPNOTSUPP;
+#endif
+
   errconstr =
       cst_to_constr(errcode, error_table, sizeof(error_table)/sizeof(int), -1);
   if (errconstr == Val_int(-1)) {
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/unixsupport.h ocaml-unix-4.00.1/otherlibs/unix/unixsupport.h
--- ocaml-unix-3.12.1/otherlibs/unix/unixsupport.h      2005-09-06 14:38:32.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/unix/unixsupport.h      2012-05-28 13:31:30.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: unixsupport.h 7045 2005-09-06 12:38:32Z doligez $ */
+/* $Id: unixsupport.h 12488 2012-05-28 11:31:30Z frisch $ */

 #ifdef HAS_UNISTD
 #include <unistd.h>
@@ -23,6 +23,6 @@
 extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
 extern void uerror (char * cmdname, value arg) Noreturn;

-#define UNIX_BUFFER_SIZE 16384
+#define UNIX_BUFFER_SIZE 65536

 #define DIR_Val(v) *((DIR **) &Field(v, 0))
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/unlink.c ocaml-unix-4.00.1/otherlibs/unix/unlink.c
--- ocaml-unix-3.12.1/otherlibs/unix/unlink.c   2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/unlink.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: unlink.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: unlink.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/utimes.c ocaml-unix-4.00.1/otherlibs/unix/utimes.c
--- ocaml-unix-3.12.1/otherlibs/unix/utimes.c   2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/utimes.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: utimes.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: utimes.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <fail.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/wait.c ocaml-unix-4.00.1/otherlibs/unix/wait.c
--- ocaml-unix-3.12.1/otherlibs/unix/wait.c     2005-04-17 10:23:51.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/unix/wait.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: wait.c 6845 2005-04-17 08:23:51Z xleroy $ */
+/* $Id: wait.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/unix/write.c ocaml-unix-4.00.1/otherlibs/unix/write.c
--- ocaml-unix-3.12.1/otherlibs/unix/write.c    2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/unix/write.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: write.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: write.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <errno.h>
 #include <string.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/accept.c ocaml-unix-4.00.1/otherlibs/win32unix/accept.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/accept.c      2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/accept.c      2012-05-24 18:40:59.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: accept.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: accept.c 12480 2012-05-24 16:40:59Z xleroy $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/bind.c ocaml-unix-4.00.1/otherlibs/win32unix/bind.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/bind.c        2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/bind.c        2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: bind.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: bind.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/channels.c ocaml-unix-4.00.1/otherlibs/win32unix/channels.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/channels.c    2011-05-09 13:38:43.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/channels.c    2011-12-21 17:31:01.000000000 +0100
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: channels.c 11030 2011-05-09 11:38:43Z doligez $ */
+/* $Id: channels.c 11927 2011-12-21 16:31:01Z xleroy $ */

 #include <mlvalues.h>
 #include <alloc.h>
@@ -20,15 +20,15 @@
 #include "unixsupport.h"
 #include <fcntl.h>

-extern long _get_osfhandle(int);
-extern int _open_osfhandle(long, int);
+extern intptr_t _get_osfhandle(int);
+extern int _open_osfhandle(intptr_t, int);

 int win_CRT_fd_of_filedescr(value handle)
 {
   if (CRT_fd_val(handle) != NO_CRT_FD) {
     return CRT_fd_val(handle);
   } else {
-    int fd = _open_osfhandle((long) Handle_val(handle), O_BINARY);
+    int fd = _open_osfhandle((intptr_t) Handle_val(handle), O_BINARY);
     if (fd == -1) uerror("channel_of_descr", Nothing);
     CRT_fd_val(handle) = fd;
     return fd;
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/close.c ocaml-unix-4.00.1/otherlibs/win32unix/close.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/close.c       2011-05-09 13:38:43.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/close.c       2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: close.c 11030 2011-05-09 11:38:43Z doligez $ */
+/* $Id: close.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/close_on.c ocaml-unix-4.00.1/otherlibs/win32unix/close_on.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/close_on.c    2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/close_on.c    2012-07-30 20:59:07.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: close_on.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: close_on.c 12800 2012-07-30 18:59:07Z doligez $ */

 #include <mlvalues.h>
 #include <windows.h>
@@ -19,17 +19,14 @@

 int win_set_inherit(value fd, BOOL inherit)
 {
-  HANDLE oldh, newh;
-
-  oldh = Handle_val(fd);
-  if (! DuplicateHandle(GetCurrentProcess(), oldh,
-                        GetCurrentProcess(), &newh,
-                        0L, inherit, DUPLICATE_SAME_ACCESS)) {
+  /* According to the MSDN, SetHandleInformation may not work
+     for console handles on WinNT4 and earlier versions. */
+  if (! SetHandleInformation(Handle_val(fd),
+                             HANDLE_FLAG_INHERIT,
+                             inherit ? HANDLE_FLAG_INHERIT : 0)) {
     win32_maperr(GetLastError());
     return -1;
   }
-  Handle_val(fd) = newh;
-  CloseHandle(oldh);
   return 0;
 }

diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/connect.c ocaml-unix-4.00.1/otherlibs/win32unix/connect.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/connect.c     2006-10-18 10:26:54.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/connect.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: connect.c 7697 2006-10-18 08:26:54Z xleroy $ */
+/* $Id: connect.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <signals.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/createprocess.c ocaml-unix-4.00.1/otherlibs/win32unix/createprocess.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/createprocess.c       2009-07-20 13:51:50.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/createprocess.c       2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: createprocess.c 9319 2009-07-20 11:51:50Z doligez $ */
+/* $Id: createprocess.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <windows.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/dup2.c ocaml-unix-4.00.1/otherlibs/win32unix/dup2.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/dup2.c        2006-09-21 11:43:58.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/dup2.c        2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: dup2.c 7630 2006-09-21 09:43:58Z xleroy $ */
+/* $Id: dup2.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/dup.c ocaml-unix-4.00.1/otherlibs/win32unix/dup.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/dup.c 2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/dup.c 2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: dup.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: dup.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/errmsg.c ocaml-unix-4.00.1/otherlibs/win32unix/errmsg.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/errmsg.c      2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/errmsg.c      2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: errmsg.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: errmsg.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <stdio.h>
 #include <errno.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/getpeername.c ocaml-unix-4.00.1/otherlibs/win32unix/getpeername.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/getpeername.c 2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/getpeername.c 2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getpeername.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: getpeername.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/getpid.c ocaml-unix-4.00.1/otherlibs/win32unix/getpid.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/getpid.c      2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/getpid.c      2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getpid.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: getpid.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/getsockname.c ocaml-unix-4.00.1/otherlibs/win32unix/getsockname.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/getsockname.c 2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/getsockname.c 2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: getsockname.c 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: getsockname.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/gettimeofday.c ocaml-unix-4.00.1/otherlibs/win32unix/gettimeofday.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/gettimeofday.c        2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/gettimeofday.c        2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: gettimeofday.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: gettimeofday.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/.ignore ocaml-unix-4.00.1/otherlibs/win32unix/.ignore
--- ocaml-unix-3.12.1/otherlibs/win32unix/.ignore       1970-01-01 01:00:00.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/.ignore       2011-07-20 17:37:36.000000000 +0200
@@ -0,0 +1,27 @@
+unixLabels.ml*
+unix.mli
+unix.lib
+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
+getserv.c
+gmtime.c
+putenv.c
+rmdir.c
+socketaddr.c
+strofaddr.c
+time.c
+unlink.c
+utimes.c
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/link.c ocaml-unix-4.00.1/otherlibs/win32unix/link.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/link.c        2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/link.c        2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*                 File contributed by Lionel Fourquaux                */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: link.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: link.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <windows.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/listen.c ocaml-unix-4.00.1/otherlibs/win32unix/listen.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/listen.c      2002-04-30 17:00:48.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/listen.c      2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: listen.c 4765 2002-04-30 15:00:48Z xleroy $ */
+/* $Id: listen.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/lockf.c ocaml-unix-4.00.1/otherlibs/win32unix/lockf.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/lockf.c       2008-12-03 19:09:09.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/lockf.c       2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Contributed by Tracy Camp, PolyServe Inc., <campt@polyserve.com>   */
 /*  Further improvements by Reed Wilson                                */
@@ -13,7 +13,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: lockf.c 9153 2008-12-03 18:09:09Z doligez $ */
+/* $Id: lockf.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <errno.h>
 #include <fcntl.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/lseek.c ocaml-unix-4.00.1/otherlibs/win32unix/lseek.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/lseek.c       2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/lseek.c       2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: lseek.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: lseek.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/Makefile.nt ocaml-unix-4.00.1/otherlibs/win32unix/Makefile.nt
--- ocaml-unix-3.12.1/otherlibs/win32unix/Makefile.nt   2010-05-20 11:40:41.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/Makefile.nt   2011-12-21 10:43:13.000000000 +0100
@@ -1,6 +1,6 @@
 #########################################################################
 #                                                                       #
-#                            Objective Caml                             #
+#                                 OCaml                                 #
 #                                                                       #
 #            Xavier Leroy, projet Cristal, INRIA Rocquencourt           #
 #                                                                       #
@@ -11,7 +11,7 @@
 #                                                                       #
 #########################################################################

-# $Id: Makefile.nt 10442 2010-05-20 09:40:41Z xleroy $
+# $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 \
@@ -21,7 +21,7 @@
   mkdir.c open.c pipe.c read.c rename.c \
   select.c sendrecv.c \
   shutdown.c sleep.c socket.c sockopt.c startup.c stat.c \
-  system.c unixsupport.c windir.c winwait.c write.c \
+  system.c times.c unixsupport.c windir.c winwait.c write.c \
   winlist.c winworker.c windbug.c

 # Files from the ../unix directory
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/mkdir.c ocaml-unix-4.00.1/otherlibs/win32unix/mkdir.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/mkdir.c       2001-12-07 14:41:02.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/mkdir.c       2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: mkdir.c 4144 2001-12-07 13:41:02Z xleroy $ */
+/* $Id: mkdir.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/nonblock.c ocaml-unix-4.00.1/otherlibs/win32unix/nonblock.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/nonblock.c    2010-05-25 15:01:06.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/nonblock.c    2011-10-15 11:02:22.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: nonblock.c 10467 2010-05-25 13:01:06Z xleroy $ */
+/* $Id: nonblock.c 11223 2011-10-15 09:02:22Z xleroy $ */

 #include <mlvalues.h>
 #include <signals.h>
@@ -26,7 +26,7 @@
     win32_maperr(WSAGetLastError());
     uerror("unix_set_nonblock", Nothing);
   }
-  Flags_fd_val(socket) = Flags_fd_val(socket) | FLAGS_FD_IS_BLOCKING;
+  Flags_fd_val(socket) = Flags_fd_val(socket) & ~FLAGS_FD_IS_BLOCKING;
   return Val_unit;
 }

@@ -39,6 +39,6 @@
     win32_maperr(WSAGetLastError());
     uerror("unix_clear_nonblock", Nothing);
   }
-  Flags_fd_val(socket) = Flags_fd_val(socket) & ~FLAGS_FD_IS_BLOCKING;
+  Flags_fd_val(socket) = Flags_fd_val(socket) | FLAGS_FD_IS_BLOCKING;
   return Val_unit;
 }
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/open.c ocaml-unix-4.00.1/otherlibs/win32unix/open.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/open.c        2008-01-11 17:13:18.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/open.c        2011-12-13 17:21:10.000000000 +0100
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,29 +11,34 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: open.c 8768 2008-01-11 16:13:18Z doligez $ */
+/* $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[12] = {
+static int open_access_flags[13] = {
   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
 };

-static int open_create_flags[12] = {
-  0, 0, 0, 0, 0, O_CREAT, O_TRUNC, O_EXCL, 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[13] = {
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FILE_SHARE_DELETE
 };

 CAMLprim value unix_open(value path, value flags, value perm)
 {
-  int fileaccess, createflags, fileattrib, filecreate;
+  int fileaccess, createflags, fileattrib, filecreate, sharemode;
   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);

   createflags = convert_flag_list(flags, open_create_flags);
   if ((createflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
@@ -57,7 +62,7 @@
   attr.bInheritHandle = TRUE;

   h = CreateFile(String_val(path), fileaccess,
-                 FILE_SHARE_READ | FILE_SHARE_WRITE, &attr,
+                 sharemode, &attr,
                  filecreate, fileattrib, NULL);
   if (h == INVALID_HANDLE_VALUE) {
     win32_maperr(GetLastError());
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/pipe.c ocaml-unix-4.00.1/otherlibs/win32unix/pipe.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/pipe.c        2009-05-20 13:52:42.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/pipe.c        2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: pipe.c 9270 2009-05-20 11:52:42Z doligez $ */
+/* $Id: pipe.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <memory.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/read.c ocaml-unix-4.00.1/otherlibs/win32unix/read.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/read.c        2006-10-18 10:26:54.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/read.c        2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: read.c 7697 2006-10-18 08:26:54Z xleroy $ */
+/* $Id: read.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <string.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/rename.c ocaml-unix-4.00.1/otherlibs/win32unix/rename.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/rename.c      2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/rename.c      2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Contributed by Tracy Camp, PolyServe Inc., <campt@polyserve.com>   */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: rename.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: rename.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <stdio.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/select.c ocaml-unix-4.00.1/otherlibs/win32unix/select.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/select.c      2010-05-25 15:01:06.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/select.c      2012-07-30 20:59:07.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Contributed by Sylvain Le Gall for Lexifi                          */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: select.c 10467 2010-05-25 13:01:06Z xleroy $ */
+/* $Id: select.c 12800 2012-07-30 18:59:07Z doligez $ */

 #include <mlvalues.h>
 #include <alloc.h>
@@ -31,7 +31,7 @@
  * It takes the following parameters into account:
  * - limitation on number of objects is mostly due to limitation
  *   a WaitForMultipleObjects
- * - there is always an event "hStop" to watch 
+ * - there is always an event "hStop" to watch
  *
  * This lead to pick the following value as the biggest possible
  * value
@@ -114,9 +114,9 @@

 typedef enum _SELECTMODE {
   SELECT_MODE_NONE = 0,
-  SELECT_MODE_READ,
-  SELECT_MODE_WRITE, 
-  SELECT_MODE_EXCEPT,
+  SELECT_MODE_READ = 1,
+  SELECT_MODE_WRITE = 2,
+  SELECT_MODE_EXCEPT = 4,
 } SELECTMODE;

 typedef enum _SELECTSTATE {
@@ -157,7 +157,9 @@
 typedef struct _SELECTDATA {
   LIST             lst;
   SELECTTYPE       EType;
-  SELECTRESULT     aResults[MAXIMUM_SELECT_OBJECTS];
+  /* Sockets may generate a result for all three lists from one single query object
+   */
+  SELECTRESULT     aResults[MAXIMUM_SELECT_OBJECTS * 3];
   DWORD            nResultsCount;
   /* Data following are dedicated to APC like call, they
      will be initialized if required.
@@ -189,18 +191,18 @@
   /* Allocate the data structure */
   LPSELECTDATA res;
   DWORD        i;
-  
-  res = (LPSELECTDATA)caml_stat_alloc(sizeof(SELECTDATA)); 
+
+  res = (LPSELECTDATA)caml_stat_alloc(sizeof(SELECTDATA));

   /* Init common data */
   list_init((LPLIST)res);
   list_next_set((LPLIST)res, (LPLIST)lpSelectData);
   res->EType         = EType;
   res->nResultsCount = 0;
-        
+

   /* Data following are dedicated to APC like call, they
-     will be initialized if required. For now they are set to 
+     will be initialized if required. For now they are set to
      invalid values.
      */
   res->funcWorker    = NULL;
@@ -240,7 +242,7 @@
   DWORD i;

   res = 0;
-  if (lpSelectData->nResultsCount < MAXIMUM_SELECT_OBJECTS)
+  if (lpSelectData->nResultsCount < MAXIMUM_SELECT_OBJECTS * 3)
   {
     i = lpSelectData->nResultsCount;
     lpSelectData->aResults[i].EMode  = EMode;
@@ -253,14 +255,14 @@
 }

 /* Add a query to select data, return zero if something goes wrong */
-DWORD select_data_query_add (LPSELECTDATA lpSelectData, 
-                             SELECTMODE EMode, 
-                             HANDLE hFileDescr, 
+DWORD select_data_query_add (LPSELECTDATA lpSelectData,
+                             SELECTMODE EMode,
+                             HANDLE hFileDescr,
                              int lpOrigIdx,
                              unsigned int uFlagsFd)
 {
   DWORD res;
-  DWORD i; 
+  DWORD i;

   res = 0;
   if (lpSelectData->nQueriesCount < MAXIMUM_SELECT_OBJECTS)
@@ -278,22 +280,22 @@
 }

 /* Search for a job that has available query slots and that match provided type.
- * If none is found, create a new one. Return the corresponding SELECTDATA, and 
+ * If none is found, create a new one. Return the corresponding SELECTDATA, and
  * update provided SELECTDATA head, if required.
  */
 LPSELECTDATA select_data_job_search (LPSELECTDATA *lppSelectData, SELECTTYPE EType)
 {
   LPSELECTDATA res;
-  
+
   res = NULL;
-  
+
   /* Search for job */
   DEBUG_PRINT("Searching an available job for type %d", EType);
   res = *lppSelectData;
   while (
       res != NULL
       && !(
-        res->EType == EType 
+        res->EType == EType
         && res->nQueriesCount < MAXIMUM_SELECT_OBJECTS
         )
       )
@@ -324,7 +326,7 @@
   DWORD n;
   LPSELECTDATA  lpSelectData;
   LPSELECTQUERY lpQuery;
-  
+
   DEBUG_PRINT("Waiting for data on console");

   record;
@@ -336,7 +338,7 @@
   events[0] = hStop;
   events[1] = lpQuery->hFileDescr;
   while (lpSelectData->EState == SELECT_STATE_NONE)
-  {    
+  {
     waitRes = WaitForMultipleObjects(2, events, FALSE, INFINITE);
     if (waitRes == WAIT_OBJECT_0 || check_error(lpSelectData, waitRes == WAIT_FAILED))
     {
@@ -357,7 +359,7 @@
       lpSelectData->EState = SELECT_STATE_SIGNALED;
       break;
     }
-    else 
+    else
     {
       /* discard everything else and try again */
       if (check_error(lpSelectData, ReadConsoleInput(lpQuery->hFileDescr, &record, 1, &n) == 0))
@@ -369,9 +371,9 @@
 }

 /* Add a function to monitor console input */
-LPSELECTDATA read_console_poll_add (LPSELECTDATA lpSelectData, 
-                                    SELECTMODE EMode, 
-                                    HANDLE hFileDescr, 
+LPSELECTDATA read_console_poll_add (LPSELECTDATA lpSelectData,
+                                    SELECTMODE EMode,
+                                    HANDLE hFileDescr,
                                     int lpOrigIdx,
                                     unsigned int uFlagsFd)
 {
@@ -412,14 +414,14 @@
     {
       iterQuery = &(lpSelectData->aQueries[i]);
       res = PeekNamedPipe(
-          iterQuery->hFileDescr, 
-          NULL, 
-          0, 
-          NULL, 
-          &n, 
+          iterQuery->hFileDescr,
+          NULL,
+          0,
+          NULL,
+          &n,
           NULL);
-      if (check_error(lpSelectData, 
-            (res == 0) && 
+      if (check_error(lpSelectData,
+            (res == 0) &&
             (GetLastError() != ERROR_BROKEN_PIPE)))
       {
         break;
@@ -433,7 +435,7 @@
     };

     /* Alas, nothing except polling seems to work for pipes.
-       Check the state & stop_worker_event every 10 ms 
+       Check the state & stop_worker_event every 10 ms
      */
     if (lpSelectData->EState == SELECT_STATE_NONE)
     {
@@ -444,7 +446,7 @@
        * a chance that one of the 4 first calls succeed.
        */
       wait = 2 * wait;
-      if (wait > 10) 
+      if (wait > 10)
       {
         wait = 10;
       };
@@ -458,23 +460,23 @@
 }

 /* Add a function to monitor pipe input */
-LPSELECTDATA read_pipe_poll_add (LPSELECTDATA lpSelectData, 
-                                 SELECTMODE EMode, 
-                                 HANDLE hFileDescr, 
+LPSELECTDATA read_pipe_poll_add (LPSELECTDATA lpSelectData,
+                                 SELECTMODE EMode,
+                                 HANDLE hFileDescr,
                                  int lpOrigIdx,
                                  unsigned int uFlagsFd)
 {
   LPSELECTDATA res;
   LPSELECTDATA hd;
-  
+
   hd = lpSelectData;
   /* Polling pipe is a non blocking operation by default. This means that each
-     worker can handle many pipe. We begin to try to find a worker that is 
+     worker can handle many pipe. We begin to try to find a worker that is
      polling pipe, but for which there is under the limit of pipe per worker.
      */
   DEBUG_PRINT("Searching an available worker handling pipe");
   res = select_data_job_search(&hd, SELECT_TYPE_PIPE_READ);
-  
+
   /* Add a new pipe to poll */
   res->funcWorker = read_pipe_poll;
   select_data_query_add(res, EMode, hFileDescr, lpOrigIdx, uFlagsFd);
@@ -490,51 +492,58 @@
 void socket_poll (HANDLE hStop, void *_data)
 {
   LPSELECTDATA   lpSelectData;
-  LPSELECTQUERY  iterQuery;
-  HANDLE         aEvents[MAXIMUM_SELECT_OBJECTS];
-  DWORD          nEvents;
-  long           maskEvents;
-  DWORD          i;
-  u_long         iMode;
+  LPSELECTQUERY    iterQuery;
+  HANDLE           aEvents[MAXIMUM_SELECT_OBJECTS];
+  DWORD            nEvents;
+  long             maskEvents;
+  DWORD            i;
+  u_long           iMode;
+  SELECTMODE       mode;
+  WSANETWORKEVENTS events;

   lpSelectData = (LPSELECTDATA)_data;

+  DEBUG_PRINT("Worker has %d queries to service", lpSelectData->nQueriesCount);
   for (nEvents = 0; nEvents < lpSelectData->nQueriesCount; nEvents++)
   {
     iterQuery = &(lpSelectData->aQueries[nEvents]);
     aEvents[nEvents] = CreateEvent(NULL, TRUE, FALSE, NULL);
     maskEvents = 0;
-    switch (iterQuery->EMode)
+    mode = iterQuery->EMode;
+    if ((mode & SELECT_MODE_READ) != 0)
     {
-      case SELECT_MODE_READ:
-        maskEvents = FD_READ | FD_ACCEPT | FD_CLOSE;
-        break;
-      case SELECT_MODE_WRITE:
-        maskEvents = FD_WRITE | FD_CONNECT | FD_CLOSE;
-        break;
-      case SELECT_MODE_EXCEPT:
-        maskEvents = FD_OOB;
-        break;
+      DEBUG_PRINT("Polling read for %d", iterQuery->hFileDescr);
+      maskEvents |= FD_READ | FD_ACCEPT | FD_CLOSE;
+    }
+    if ((mode & SELECT_MODE_WRITE) != 0)
+    {
+      DEBUG_PRINT("Polling write for %d", iterQuery->hFileDescr);
+      maskEvents |= FD_WRITE | FD_CONNECT | FD_CLOSE;
+    }
+    if ((mode & SELECT_MODE_EXCEPT) != 0)
+    {
+      DEBUG_PRINT("Polling exceptions for %d", iterQuery->hFileDescr);
+      maskEvents |= FD_OOB;
     }

     check_error(lpSelectData,
         WSAEventSelect(
-          (SOCKET)(iterQuery->hFileDescr), 
-          aEvents[nEvents], 
+          (SOCKET)(iterQuery->hFileDescr),
+          aEvents[nEvents],
           maskEvents) == SOCKET_ERROR);
   }
-  
+
   /* Add stop event */
   aEvents[nEvents]  = hStop;
   nEvents++;

   if (lpSelectData->nError == 0)
   {
-    check_error(lpSelectData, 
+    check_error(lpSelectData,
         WaitForMultipleObjects(
-          nEvents, 
-          aEvents, 
-          FALSE, 
+          nEvents,
+          aEvents,
+          FALSE,
           INFINITE) == WAIT_FAILED);
   };

@@ -548,7 +557,23 @@
         DEBUG_PRINT("Socket %d has pending events", (i - 1));
         if (iterQuery != NULL)
         {
-          select_data_result_add(lpSelectData, iterQuery->EMode, iterQuery->lpOrigIdx);
+          /* Find out what kind of events were raised
+           */
+          if (WSAEnumNetworkEvents((SOCKET)(iterQuery->hFileDescr), aEvents[i], &events) == 0)
+          {
+            if ((iterQuery->EMode & SELECT_MODE_READ) != 0 && (events.lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE)) != 0)
+            {
+              select_data_result_add(lpSelectData, SELECT_MODE_READ, iterQuery->lpOrigIdx);
+            }
+            if ((iterQuery->EMode & SELECT_MODE_WRITE) != 0 && (events.lNetworkEvents & (FD_WRITE | FD_CONNECT | FD_CLOSE)) != 0)
+            {
+              select_data_result_add(lpSelectData, SELECT_MODE_WRITE, iterQuery->lpOrigIdx);
+            }
+            if ((iterQuery->EMode & SELECT_MODE_EXCEPT) != 0 && (events.lNetworkEvents & FD_OOB) != 0)
+            {
+              select_data_result_add(lpSelectData, SELECT_MODE_EXCEPT, iterQuery->lpOrigIdx);
+            }
+          }
         }
       }
       /* WSAEventSelect() automatically sets socket to nonblocking mode.
@@ -556,7 +581,7 @@
       if (iterQuery->uFlagsFd & FLAGS_FD_IS_BLOCKING)
       {
         DEBUG_PRINT("Restore a blocking socket");
-        iMode = 1;
+        iMode = 0;
         check_error(lpSelectData,
           WSAEventSelect((SOCKET)(iterQuery->hFileDescr), aEvents[i], 0) != 0 ||
           ioctlsocket((SOCKET)(iterQuery->hFileDescr), FIONBIO, &iMode) != 0);
@@ -574,30 +599,95 @@
 }

 /* Add a function to monitor socket */
-LPSELECTDATA socket_poll_add (LPSELECTDATA lpSelectData, 
-                              SELECTMODE EMode, 
-                              HANDLE hFileDescr, 
+LPSELECTDATA socket_poll_add (LPSELECTDATA lpSelectData,
+                              SELECTMODE EMode,
+                              HANDLE hFileDescr,
                               int lpOrigIdx,
                               unsigned int uFlagsFd)
 {
   LPSELECTDATA res;
-  LPSELECTDATA hd;
-  
-  hd = lpSelectData;
+  LPSELECTDATA candidate;
+  DWORD i;
+  LPSELECTQUERY aQueries;
+
+  res = lpSelectData;
+  candidate = NULL;
+  aQueries = NULL;
+
   /* Polling socket can be done mulitple handle at the same time. You just
      need one worker to use it. Try to find if there is already a worker
      handling this kind of request.
+     Only one event can be associated with a given socket which means that if a socket
+     is in more than one of the fd_sets then we have to find that particular query and update
+     EMode with the additional flag.
      */
   DEBUG_PRINT("Scanning list of worker to find one that already handle socket");
-  res = select_data_job_search(&hd, SELECT_TYPE_SOCKET);
-  
-  /* Add a new socket to poll */
-  res->funcWorker = socket_poll;
-  DEBUG_PRINT("Add socket %x to worker", hFileDescr);
-  select_data_query_add(res, EMode, hFileDescr, lpOrigIdx, uFlagsFd);
-  DEBUG_PRINT("Socket %x added", hFileDescr);
+  /* Search for job */
+  DEBUG_PRINT("Searching for an available job for type %d for descriptor %d", SELECT_TYPE_SOCKET, hFileDescr);
+  while (res != NULL)
+  {
+    if (res->EType == SELECT_TYPE_SOCKET)
+    {
+      i = res->nQueriesCount - 1;
+      aQueries = res->aQueries;
+      while (i >= 0 && aQueries[i].hFileDescr != hFileDescr)
+      {
+        i--;
+      }
+      /* If we didn't find the socket but this worker has available slots, store it
+       */
+      if (i < 0)
+      {
+        if ( res->nQueriesCount < MAXIMUM_SELECT_OBJECTS)
+        {
+          candidate = res;
+        }
+        res = LIST_NEXT(LPSELECTDATA, res);
+      }
+      else
+      {
+        /* Previous socket query located -- we're finished
+         */
+        aQueries = &aQueries[i];
+        break;
+      }
+    }
+    else
+    {
+      res = LIST_NEXT(LPSELECTDATA, res);
+    }
+  }

-  return hd;
+  if (res == NULL)
+  {
+    res = candidate;
+
+    /* No matching job found, create one */
+    if (res == NULL)
+    {
+      DEBUG_PRINT("No job for type %d found, create one", SELECT_TYPE_SOCKET);
+      res = select_data_new(lpSelectData, SELECT_TYPE_SOCKET);
+      res->funcWorker = socket_poll;
+      res->nQueriesCount = 1;
+      aQueries = &res->aQueries[0];
+    }
+    else
+    {
+      aQueries = &(res->aQueries[res->nQueriesCount++]);
+    }
+    aQueries->EMode = EMode;
+    aQueries->hFileDescr = hFileDescr;
+    aQueries->lpOrigIdx = lpOrigIdx;
+    aQueries->uFlagsFd = uFlagsFd;
+    DEBUG_PRINT("Socket %x added", hFileDescr);
+  }
+  else
+  {
+    aQueries->EMode |= EMode;
+    DEBUG_PRINT("Socket %x updated to %d", hFileDescr, aQueries->EMode);
+  }
+
+  return res;
 }

 /***********************/
@@ -605,19 +695,19 @@
 /***********************/

 /* Add a static result */
-LPSELECTDATA static_poll_add (LPSELECTDATA lpSelectData, 
-                              SELECTMODE EMode, 
-                              HANDLE hFileDescr, 
+LPSELECTDATA static_poll_add (LPSELECTDATA lpSelectData,
+                              SELECTMODE EMode,
+                              HANDLE hFileDescr,
                               int lpOrigIdx,
                               unsigned int uFlagsFd)
 {
   LPSELECTDATA res;
   LPSELECTDATA hd;
-  
+
   /* Look for an already initialized static element */
   hd = lpSelectData;
   res = select_data_job_search(&hd, SELECT_TYPE_STATIC);
-  
+
   /* Add a new query/result */
   select_data_query_add(res, EMode, hFileDescr, lpOrigIdx, uFlagsFd);
   select_data_result_add(res, EMode, lpOrigIdx);
@@ -648,7 +738,7 @@
   {
     switch(GetFileType(Handle_val(fd)))
     {
-      case FILE_TYPE_DISK: 
+      case FILE_TYPE_DISK:
         res = SELECT_HANDLE_DISK;
         break;

@@ -693,8 +783,8 @@
   DEBUG_PRINT("Begin dispatching handle %x", hFileDescr);

   DEBUG_PRINT("Waiting for %d on handle %x", EMode, hFileDescr);
-  
-  /* There is only 2 way to have except mode: transmission of OOB data through 
+
+  /* There is only 2 way to have except mode: transmission of OOB data through
      a socket TCP/IP and through a strange interaction with a TTY.
      With windows, we only consider the TCP/IP except condition
   */
@@ -789,7 +879,7 @@
   CAMLlocal2(result, list);
   int i;

-  switch( iterResult->EMode )  
+  switch( iterResult->EMode )
   {
     case SELECT_MODE_READ:
       list = readfds;
@@ -802,12 +892,12 @@
       break;
   };

-  for(i=0; list != Val_unit && i < iterResult->lpOrigIdx; ++i ) 
+  for(i=0; list != Val_unit && i < iterResult->lpOrigIdx; ++i )
   {
     list = Field(list, 1);
   }

-  if (list == Val_unit) 
+  if (list == Val_unit)
     failwith ("select.c: original file handle not found");

   result = Field(list, 0);
@@ -817,13 +907,49 @@

 #define MAX(a, b) ((a) > (b) ? (a) : (b))

+/* Convert fdlist to an fd_set if all the handles in fdlist are sockets and return 0.
+ * Returns 1 if a non-socket value is encountered.
+ */
+static int fdlist_to_fdset(value fdlist, fd_set *fdset)
+{
+  value l, c;
+  FD_ZERO(fdset);
+  for (l = fdlist; l != Val_int(0); l = Field(l, 1)) {
+    c = Field(l, 0);
+    if (Descr_kind_val(c) == KIND_SOCKET) {
+      FD_SET(Socket_val(c), fdset);
+    } else {
+      DEBUG_PRINT("Non socket value encountered");
+      return 0;
+    }
+  }
+  return 1;
+}
+
+static value fdset_to_fdlist(value fdlist, fd_set *fdset)
+{
+  value res = Val_int(0);
+  Begin_roots2(fdlist, res)
+    for (/*nothing*/; fdlist != Val_int(0); fdlist = Field(fdlist, 1)) {
+      value s = Field(fdlist, 0);
+      if (FD_ISSET(Socket_val(s), fdset)) {
+        value newres = alloc_small(2, 0);
+        Field(newres, 0) = s;
+        Field(newres, 1) = res;
+        res = newres;
+      }
+    }
+  End_roots();
+  return res;
+}
+
 CAMLprim value unix_select(value readfds, value writefds, value exceptfds, value timeout)
-{  
+{
   /* Event associated to handle */
   DWORD   nEventsCount;
   DWORD   nEventsMax;
   HANDLE *lpEventsDone;
-  
+
   /* Data for all handles */
   LPSELECTDATA lpSelectData;
   LPSELECTDATA iterSelectData;
@@ -860,246 +986,287 @@
   CAMLlocal5 (read_list, write_list, except_list, res, l);
   CAMLlocal1 (fd);

+  fd_set read, write, except;
+  double tm;
+  struct timeval tv;
+  struct timeval * tvp;
+
   DEBUG_PRINT("in select");

-  nEventsCount   = 0;
-  nEventsMax     = 0;
-  lpEventsDone   = NULL;
-  lpSelectData   = NULL;
-  iterSelectData = NULL;
-  iterResult     = NULL;
-  err            = 0;
-  hasStaticData  = 0;
-  waitRet        = 0;
-  readfds_len    = caml_list_length(readfds);
-  writefds_len   = caml_list_length(writefds);
-  exceptfds_len  = caml_list_length(exceptfds);
-  hdsMax         = MAX(readfds_len, MAX(writefds_len, exceptfds_len));
+  err = 0;
+  tm = Double_val(timeout);
+  if (readfds == Val_int(0) && writefds == Val_int(0) && exceptfds == Val_int(0)) {
+    DEBUG_PRINT("nothing to do");
+    if ( tm > 0.0 ) {
+      enter_blocking_section();
+      Sleep( (int)(tm * 1000));
+      leave_blocking_section();
+    }
+    read_list = write_list = except_list = Val_int(0);
+  } else {
+    if (fdlist_to_fdset(readfds, &read) && fdlist_to_fdset(writefds, &write) && fdlist_to_fdset(exceptfds, &except)) {
+      DEBUG_PRINT("only sockets to select on, using classic select");
+      if (tm < 0.0) {
+        tvp = (struct timeval *) NULL;
+      } else {
+        tv.tv_sec = (int) tm;
+        tv.tv_usec = (int) (1e6 * (tm - (int) tm));
+        tvp = &tv;
+      }
+      enter_blocking_section();
+      if (select(FD_SETSIZE, &read, &write, &except, tvp) == -1) {
+        err = WSAGetLastError();
+        DEBUG_PRINT("Error %ld occurred", err);
+      }
+      leave_blocking_section();
+      if (err) {
+        DEBUG_PRINT("Error %ld occurred", err);
+        win32_maperr(err);
+        uerror("select", Nothing);
+      }
+      read_list = fdset_to_fdlist(readfds, &read);
+      write_list = fdset_to_fdlist(writefds, &write);
+      except_list = fdset_to_fdlist(exceptfds, &except);
+    } else {
+      nEventsCount   = 0;
+      nEventsMax     = 0;
+      lpEventsDone   = NULL;
+      lpSelectData   = NULL;
+      iterSelectData = NULL;
+      iterResult     = NULL;
+      hasStaticData  = 0;
+      waitRet        = 0;
+      readfds_len    = caml_list_length(readfds);
+      writefds_len   = caml_list_length(writefds);
+      exceptfds_len  = caml_list_length(exceptfds);
+      hdsMax         = MAX(readfds_len, MAX(writefds_len, exceptfds_len));

-  hdsData = (HANDLE *)caml_stat_alloc(sizeof(HANDLE) * hdsMax);
+      hdsData = (HANDLE *)caml_stat_alloc(sizeof(HANDLE) * hdsMax);

-  if (Double_val(timeout) >= 0.0)
-  {
-    milliseconds = 1000 * Double_val(timeout);
-    DEBUG_PRINT("Will wait %d ms", milliseconds);
-  }
-  else
-  {
-    milliseconds = INFINITE;
-  }
+      if (tm >= 0.0)
+        {
+          milliseconds = 1000 * tm;
+          DEBUG_PRINT("Will wait %d ms", milliseconds);
+        }
+      else
+        {
+          milliseconds = INFINITE;
+        }


-  /* Create list of select data, based on the different list of fd to watch */
-  DEBUG_PRINT("Dispatch read fd");
-  handle_set_init(&hds, hdsData, hdsMax);
-  i=0;
-  for (l = readfds; l != Val_int(0); l = Field(l, 1))
-  {
-    fd = Field(l, 0);
-    if (!handle_set_mem(&hds, Handle_val(fd)))
-    {
-      handle_set_add(&hds, Handle_val(fd));
-      lpSelectData = select_data_dispatch(lpSelectData, SELECT_MODE_READ, fd, i++);
-    }
-    else
-    {
-      DEBUG_PRINT("Discarding handle %x which is already monitor for read", Handle_val(fd));
-    }
-  }
-  handle_set_reset(&hds);
+      /* Create list of select data, based on the different list of fd to watch */
+      DEBUG_PRINT("Dispatch read fd");
+      handle_set_init(&hds, hdsData, hdsMax);
+      i=0;
+      for (l = readfds; l != Val_int(0); l = Field(l, 1))
+        {
+          fd = Field(l, 0);
+          if (!handle_set_mem(&hds, Handle_val(fd)))
+            {
+              handle_set_add(&hds, Handle_val(fd));
+              lpSelectData = select_data_dispatch(lpSelectData, SELECT_MODE_READ, fd, i++);
+            }
+          else
+            {
+              DEBUG_PRINT("Discarding handle %x which is already monitor for read", Handle_val(fd));
+            }
+        }
+      handle_set_reset(&hds);

-  DEBUG_PRINT("Dispatch write fd");
-  handle_set_init(&hds, hdsData, hdsMax);
-  i=0;
-  for (l = writefds; l != Val_int(0); l = Field(l, 1))
-  {
-    fd = Field(l, 0);
-    if (!handle_set_mem(&hds, Handle_val(fd)))
-    {
-      handle_set_add(&hds, Handle_val(fd));
-      lpSelectData = select_data_dispatch(lpSelectData, SELECT_MODE_WRITE, fd, i++);
-    }
-    else
-    {
-      DEBUG_PRINT("Discarding handle %x which is already monitor for write", Handle_val(fd));
-    }
-  }
-  handle_set_reset(&hds);
+      DEBUG_PRINT("Dispatch write fd");
+      handle_set_init(&hds, hdsData, hdsMax);
+      i=0;
+      for (l = writefds; l != Val_int(0); l = Field(l, 1))
+        {
+          fd = Field(l, 0);
+          if (!handle_set_mem(&hds, Handle_val(fd)))
+            {
+              handle_set_add(&hds, Handle_val(fd));
+              lpSelectData = select_data_dispatch(lpSelectData, SELECT_MODE_WRITE, fd, i++);
+            }
+          else
+            {
+              DEBUG_PRINT("Discarding handle %x which is already monitor for write", Handle_val(fd));
+            }
+        }
+      handle_set_reset(&hds);

-  DEBUG_PRINT("Dispatch exceptional fd");
-  handle_set_init(&hds, hdsData, hdsMax);
-  i=0;
-  for (l = exceptfds; l != Val_int(0); l = Field(l, 1))
-  {
-    fd = Field(l, 0);
-    if (!handle_set_mem(&hds, Handle_val(fd)))
-    {
-      handle_set_add(&hds, Handle_val(fd));
-      lpSelectData = select_data_dispatch(lpSelectData, SELECT_MODE_EXCEPT, fd, i++);
-    }
-    else
-    {
-      DEBUG_PRINT("Discarding handle %x which is already monitor for exceptional", Handle_val(fd));
-    }
-  }
-  handle_set_reset(&hds);
+      DEBUG_PRINT("Dispatch exceptional fd");
+      handle_set_init(&hds, hdsData, hdsMax);
+      i=0;
+      for (l = exceptfds; l != Val_int(0); l = Field(l, 1))
+        {
+          fd = Field(l, 0);
+          if (!handle_set_mem(&hds, Handle_val(fd)))
+            {
+              handle_set_add(&hds, Handle_val(fd));
+              lpSelectData = select_data_dispatch(lpSelectData, SELECT_MODE_EXCEPT, fd, i++);
+            }
+          else
+            {
+              DEBUG_PRINT("Discarding handle %x which is already monitor for exceptional", Handle_val(fd));
+            }
+        }
+      handle_set_reset(&hds);

-  /* Building the list of handle to wait for */
-  DEBUG_PRINT("Building events done array");
-  nEventsMax   = list_length((LPLIST)lpSelectData);
-  nEventsCount = 0;
-  lpEventsDone = (HANDLE *)caml_stat_alloc(sizeof(HANDLE) * nEventsMax);
-
-  iterSelectData = lpSelectData;
-  while (iterSelectData != NULL)
-  {
-    /* Check if it is static data. If this is the case, launch everything
-     * but don't wait for events. It helps to test if there are events on
-     * any other fd (which are not static), knowing that there is at least
-     * one result (the static data).
-     */
-    if (iterSelectData->EType == SELECT_TYPE_STATIC)
-    {
-      hasStaticData = TRUE;
-    };
+      /* Building the list of handle to wait for */
+      DEBUG_PRINT("Building events done array");
+      nEventsMax   = list_length((LPLIST)lpSelectData);
+      nEventsCount = 0;
+      lpEventsDone = (HANDLE *)caml_stat_alloc(sizeof(HANDLE) * nEventsMax);

-    /* Execute APC */
-    if (iterSelectData->funcWorker != NULL)
-    {
-      iterSelectData->lpWorker = 
-        worker_job_submit(
-            iterSelectData->funcWorker, 
-            (void *)iterSelectData);
-      DEBUG_PRINT("Job submitted to worker %x", iterSelectData->lpWorker); 
-      lpEventsDone[nEventsCount] = worker_job_event_done(iterSelectData->lpWorker);
-      nEventsCount++;
-    };
-    iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData);
-  };
+      iterSelectData = lpSelectData;
+      while (iterSelectData != NULL)
+        {
+          /* Check if it is static data. If this is the case, launch everything
+           * but don't wait for events. It helps to test if there are events on
+           * any other fd (which are not static), knowing that there is at least
+           * one result (the static data).
+           */
+          if (iterSelectData->EType == SELECT_TYPE_STATIC)
+            {
+              hasStaticData = TRUE;
+            };
+
+          /* Execute APC */
+          if (iterSelectData->funcWorker != NULL)
+            {
+              iterSelectData->lpWorker =
+                worker_job_submit(
+                                  iterSelectData->funcWorker,
+                                  (void *)iterSelectData);
+              DEBUG_PRINT("Job submitted to worker %x", iterSelectData->lpWorker);
+              lpEventsDone[nEventsCount] = worker_job_event_done(iterSelectData->lpWorker);
+              nEventsCount++;
+            };
+          iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData);
+        };

-  DEBUG_PRINT("Need to watch %d workers", nEventsCount);
+      DEBUG_PRINT("Need to watch %d workers", nEventsCount);

-  /* Processing select itself */
-  enter_blocking_section();
-  /* There are worker started, waiting to be monitored */
-  if (nEventsCount > 0)
-  {
-    /* Waiting for event */
-    if (err == 0 && !hasStaticData)
-    {
-      DEBUG_PRINT("Waiting for one select worker to be done");
-      switch (WaitForMultipleObjects(nEventsCount, lpEventsDone, FALSE, milliseconds))
-      {
-        case WAIT_FAILED:
-          err = GetLastError();
-          break;
-
-        case WAIT_TIMEOUT:
-          DEBUG_PRINT("Select timeout");
-          break;
-
-        default:
-          DEBUG_PRINT("One worker is done");
-          break;
-      };
-    }
+      /* Processing select itself */
+      enter_blocking_section();
+      /* There are worker started, waiting to be monitored */
+      if (nEventsCount > 0)
+        {
+          /* Waiting for event */
+          if (err == 0 && !hasStaticData)
+            {
+              DEBUG_PRINT("Waiting for one select worker to be done");
+              switch (WaitForMultipleObjects(nEventsCount, lpEventsDone, FALSE, milliseconds))
+                {
+                case WAIT_FAILED:
+                  err = GetLastError();
+                  break;
+
+                case WAIT_TIMEOUT:
+                  DEBUG_PRINT("Select timeout");
+                  break;
+
+                default:
+                  DEBUG_PRINT("One worker is done");
+                  break;
+                };
+            }
+
+          /* Ordering stop to every worker */
+          DEBUG_PRINT("Sending stop signal to every select workers");
+          iterSelectData = lpSelectData;
+          while (iterSelectData != NULL)
+            {
+              if (iterSelectData->lpWorker != NULL)
+                {
+                  worker_job_stop(iterSelectData->lpWorker);
+                };
+              iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData);
+            };
+
+          DEBUG_PRINT("Waiting for every select worker to be done");
+          switch (WaitForMultipleObjects(nEventsCount, lpEventsDone, TRUE, INFINITE))
+            {
+            case WAIT_FAILED:
+              err = GetLastError();
+              break;
+
+            default:
+              DEBUG_PRINT("Every worker is done");
+              break;
+            }
+        }
+      /* Nothing to monitor but some time to wait. */
+      else if (!hasStaticData)
+        {
+          Sleep(milliseconds);
+        }
+      leave_blocking_section();

-    /* Ordering stop to every worker */
-    DEBUG_PRINT("Sending stop signal to every select workers");
-    iterSelectData = lpSelectData;
-    while (iterSelectData != NULL)
-    {
-      if (iterSelectData->lpWorker != NULL)
-      {
-        worker_job_stop(iterSelectData->lpWorker);
-      };
-      iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData);
-    };
-      
-    DEBUG_PRINT("Waiting for every select worker to be done");
-    switch (WaitForMultipleObjects(nEventsCount, lpEventsDone, TRUE, INFINITE))
-    {
-      case WAIT_FAILED:
-        err = GetLastError();
-        break;
+      DEBUG_PRINT("Error status: %d (0 is ok)", err);
+      /* Build results */
+      if (err == 0)
+        {
+          DEBUG_PRINT("Building result");
+          read_list = Val_unit;
+          write_list = Val_unit;
+          except_list = Val_unit;
+
+          iterSelectData = lpSelectData;
+          while (iterSelectData != NULL)
+            {
+              for (i = 0; i < iterSelectData->nResultsCount; i++)
+                {
+                  iterResult = &(iterSelectData->aResults[i]);
+                  l = alloc_small(2, 0);
+                  Store_field(l, 0, find_handle(iterResult, readfds, writefds, exceptfds));
+                  switch (iterResult->EMode)
+                    {
+                    case SELECT_MODE_READ:
+                      Store_field(l, 1, read_list);
+                      read_list = l;
+                      break;
+                    case SELECT_MODE_WRITE:
+                      Store_field(l, 1, write_list);
+                      write_list = l;
+                      break;
+                    case SELECT_MODE_EXCEPT:
+                      Store_field(l, 1, except_list);
+                      except_list = l;
+                      break;
+                    }
+                }
+              /* We try to only process the first error, bypass other errors */
+              if (err == 0 && iterSelectData->EState == SELECT_STATE_ERROR)
+                {
+                  err = iterSelectData->nError;
+                }
+              iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData);
+            }
+        }

-      default:
-        DEBUG_PRINT("Every worker is done");
-        break;
-    }
-  }
-  /* Nothing to monitor but some time to wait. */
-  else if (!hasStaticData)
-  {
-    Sleep(milliseconds);
-  }
-  leave_blocking_section();
+      /* Free resources */
+      DEBUG_PRINT("Free selectdata resources");
+      iterSelectData = lpSelectData;
+      while (iterSelectData != NULL)
+        {
+          lpSelectData = iterSelectData;
+          iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData);
+          select_data_free(lpSelectData);
+        }
+      lpSelectData = NULL;

-  DEBUG_PRINT("Error status: %d (0 is ok)", err);
-  /* Build results */
-  if (err == 0)
-  {
-    DEBUG_PRINT("Building result");
-    read_list = Val_unit; 
-    write_list = Val_unit;
-    except_list = Val_unit;
+      /* Free allocated events/handle set array */
+      DEBUG_PRINT("Free local allocated resources");
+      caml_stat_free(lpEventsDone);
+      caml_stat_free(hdsData);

-    iterSelectData = lpSelectData;
-    while (iterSelectData != NULL)
-    {
-      for (i = 0; i < iterSelectData->nResultsCount; i++)
-      {
-        iterResult = &(iterSelectData->aResults[i]);
-        l = alloc_small(2, 0);
-        Store_field(l, 0, find_handle(iterResult, readfds, writefds, exceptfds));
-        switch (iterResult->EMode)
+      DEBUG_PRINT("Raise error if required");
+      if (err != 0)
         {
-        case SELECT_MODE_READ:
-          Store_field(l, 1, read_list);
-          read_list = l;
-          break;
-        case SELECT_MODE_WRITE:
-          Store_field(l, 1, write_list);
-          write_list = l;
-          break;
-        case SELECT_MODE_EXCEPT:
-          Store_field(l, 1, except_list);
-          except_list = l;
-          break;
+          win32_maperr(err);
+          uerror("select", Nothing);
         }
-      }
-      /* We try to only process the first error, bypass other errors */
-      if (err == 0 && iterSelectData->EState == SELECT_STATE_ERROR)
-      {
-        err = iterSelectData->nError;
-      }
-      iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData);
     }
   }

-  /* Free resources */
-  DEBUG_PRINT("Free selectdata resources");
-  iterSelectData = lpSelectData;
-  while (iterSelectData != NULL)
-  {
-    lpSelectData = iterSelectData;
-    iterSelectData = LIST_NEXT(LPSELECTDATA, iterSelectData);
-    select_data_free(lpSelectData);
-  }
-  lpSelectData = NULL;
-  
-  /* Free allocated events/handle set array */
-  DEBUG_PRINT("Free local allocated resources");
-  caml_stat_free(lpEventsDone);
-  caml_stat_free(hdsData);
-
-  DEBUG_PRINT("Raise error if required");
-  if (err != 0)
-  {
-    win32_maperr(err);
-    uerror("select", Nothing);
-  }
-
   DEBUG_PRINT("Build final result");
   res = alloc_small(3, 0);
   Store_field(res, 0, read_list);
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/sendrecv.c ocaml-unix-4.00.1/otherlibs/win32unix/sendrecv.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/sendrecv.c    2006-10-18 10:26:54.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/sendrecv.c    2011-12-20 13:37:52.000000000 +0100
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: sendrecv.c 7697 2006-10-18 08:26:54Z xleroy $ */
+/* $Id: sendrecv.c 11896 2011-12-20 12:37:52Z xleroy $ */

 #include <mlvalues.h>
 #include <alloc.h>
@@ -132,9 +132,7 @@
   return Val_int(ret);
 }

-CAMLprim value unix_sendto(argv, argc)
-     value * argv;
-     int argc;
+CAMLprim value unix_sendto(value * argv, int argc)
 {
   return unix_sendto_native
            (argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/shutdown.c ocaml-unix-4.00.1/otherlibs/win32unix/shutdown.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/shutdown.c    2002-04-30 17:00:48.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/shutdown.c    2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: shutdown.c 4765 2002-04-30 15:00:48Z xleroy $ */
+/* $Id: shutdown.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include "unixsupport.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/sleep.c ocaml-unix-4.00.1/otherlibs/win32unix/sleep.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/sleep.c       2002-06-07 11:49:45.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/sleep.c       2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: sleep.c 4899 2002-06-07 09:49:45Z xleroy $ */
+/* $Id: sleep.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <signals.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/socketaddr.h ocaml-unix-4.00.1/otherlibs/win32unix/socketaddr.h
--- ocaml-unix-3.12.1/otherlibs/win32unix/socketaddr.h  2005-03-24 18:20:54.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/socketaddr.h  2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: socketaddr.h 6824 2005-03-24 17:20:54Z doligez $ */
+/* $Id: socketaddr.h 11156 2011-07-27 14:17:02Z doligez $ */

 #include <misc.h>

diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/socket.c ocaml-unix-4.00.1/otherlibs/win32unix/socket.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/socket.c      2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/socket.c      2012-05-24 18:40:59.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,13 +11,13 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: socket.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: socket.c 12480 2012-05-24 16:40:59Z xleroy $ */

 #include <mlvalues.h>
 #include "unixsupport.h"

 int socket_domain_table[] = {
-  PF_UNIX, PF_INET
+  PF_UNIX, PF_INET /*, PF_INET6 */
 };

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

+  /* 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);
+  }
   oldvaluelen = sizeof(oldvalue);
   retcode = getsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
                        (char *) &oldvalue, &oldvaluelen);
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/sockopt.c ocaml-unix-4.00.1/otherlibs/win32unix/sockopt.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/sockopt.c     2008-08-01 15:46:08.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/sockopt.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: sockopt.c 8968 2008-08-01 13:46:08Z xleroy $ */
+/* $Id: sockopt.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <errno.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/startup.c ocaml-unix-4.00.1/otherlibs/win32unix/startup.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/startup.c     2010-05-25 15:01:06.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/startup.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/stat.c ocaml-unix-4.00.1/otherlibs/win32unix/stat.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/stat.c        2009-05-20 13:52:42.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/stat.c        2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: stat.c 9270 2009-05-20 11:52:42Z doligez $ */
+/* $Id: stat.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <errno.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/system.c ocaml-unix-4.00.1/otherlibs/win32unix/system.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/system.c      2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/system.c      2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: system.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: system.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <memory.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/times.c ocaml-unix-4.00.1/otherlibs/win32unix/times.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/times.c       1970-01-01 01:00:00.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/times.c       2012-07-30 20:59:07.000000000 +0200
@@ -0,0 +1,35 @@
+#include <windows.h>
+#include <mlvalues.h>
+#include "unixsupport.h"
+
+
+double to_sec(FILETIME ft) {
+  ULARGE_INTEGER tmp;
+
+  tmp.u.LowPart = ft.dwLowDateTime;
+  tmp.u.HighPart = ft.dwHighDateTime;
+
+  /* convert to seconds:
+     GetProcessTimes returns number of 100-nanosecond intervals */
+  return tmp.QuadPart / 1e7;
+}
+
+
+value unix_times(value unit) {
+
+  value res;
+  FILETIME creation, exit, stime, utime;
+
+  if (!(GetProcessTimes(GetCurrentProcess(), &creation, &exit, &stime, &utime))) {
+    win32_maperr(GetLastError());
+    uerror("times", Nothing);
+  }
+
+  res = alloc_small(4 * Double_wosize, Double_array_tag);
+  Store_double_field(res, 0, to_sec(utime));
+  Store_double_field(res, 1, to_sec(stime));
+  Store_double_field(res, 2, 0);
+  Store_double_field(res, 3, 0);
+  return res;
+
+}
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/unix.ml ocaml-unix-4.00.1/otherlibs/win32unix/unix.ml
--- ocaml-unix-3.12.1/otherlibs/win32unix/unix.ml       2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/unix.ml       2011-12-21 10:43:13.000000000 +0100
@@ -1,6 +1,6 @@
 (***********************************************************************)
 (*                                                                     *)
-(*                           Objective Caml                            *)
+(*                                OCaml                                *)
 (*                                                                     *)
 (*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   *)
 (*                                                                     *)
@@ -11,7 +11,7 @@
 (*                                                                     *)
 (***********************************************************************)

-(* $Id: unix.ml 9547 2010-01-22 12:48:24Z doligez $ *)
+(* $Id: unix.ml 11912 2011-12-21 09:43:13Z protzenk $ *)

 (* Initialization *)

@@ -170,6 +170,7 @@
   | O_DSYNC
   | O_SYNC
   | O_RSYNC
+  | O_SHARE_DELETE

 type file_perm = int

@@ -407,9 +408,7 @@
 external mktime : tm -> float * tm = "unix_mktime"
 let alarm n = invalid_arg "Unix.alarm not implemented"
 external sleep : int -> unit = "unix_sleep"
-let times () =
-  { tms_utime = Sys.time(); tms_stime = 0.0;
-    tms_cutime = 0.0; tms_cstime = 0.0 }
+external times: unit -> process_times = "unix_times"
 external utimes : string -> float -> float -> unit = "unix_utimes"

 type interval_timer =
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/unixsupport.c ocaml-unix-4.00.1/otherlibs/win32unix/unixsupport.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/unixsupport.c 2010-05-25 15:01:06.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/unixsupport.c 2011-10-15 11:02:22.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: unixsupport.c 10467 2010-05-25 13:01:06Z xleroy $ */
+/* $Id: unixsupport.c 11223 2011-10-15 09:02:22Z xleroy $ */

 #include <stddef.h>
 #include <mlvalues.h>
@@ -44,7 +44,8 @@
   win_handle_compare,
   win_handle_hash,
   custom_serialize_default,
-  custom_deserialize_default
+  custom_deserialize_default,
+  custom_compare_ext_default
 };

 value win_alloc_handle(HANDLE h)
@@ -53,7 +54,7 @@
   Handle_val(res) = h;
   Descr_kind_val(res) = KIND_HANDLE;
   CRT_fd_val(res) = NO_CRT_FD;
-  Flags_fd_val(res) = 0;
+  Flags_fd_val(res) = FLAGS_FD_IS_BLOCKING;
   return res;
 }

@@ -63,7 +64,7 @@
   Socket_val(res) = s;
   Descr_kind_val(res) = KIND_SOCKET;
   CRT_fd_val(res) = NO_CRT_FD;
-  Flags_fd_val(res) = 0;
+  Flags_fd_val(res) = FLAGS_FD_IS_BLOCKING;
   return res;
 }

diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/unixsupport.h ocaml-unix-4.00.1/otherlibs/win32unix/unixsupport.h
--- ocaml-unix-3.12.1/otherlibs/win32unix/unixsupport.h 2010-05-25 15:01:06.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/unixsupport.h 2012-05-28 13:31:30.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: unixsupport.h 10467 2010-05-25 13:01:06Z xleroy $ */
+/* $Id: unixsupport.h 12488 2012-05-28 11:31:30Z frisch $ */

 #define WIN32_LEAN_AND_MEAN
 #include <wtypes.h>
@@ -59,4 +59,4 @@
 /* Blocking or nonblocking.  By default a filedescr is in blocking state */
 #define FLAGS_FD_IS_BLOCKING (1<<0)

-#define UNIX_BUFFER_SIZE 16384
+#define UNIX_BUFFER_SIZE 65536
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/windbug.c ocaml-unix-4.00.1/otherlibs/win32unix/windbug.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/windbug.c     2010-05-25 15:01:06.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/windbug.c     2012-07-30 20:59:07.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Contributed by Sylvain Le Gall for Lexifi                          */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: windbug.c 10467 2010-05-25 13:01:06Z xleroy $ */
+/* $Id: windbug.c 12800 2012-07-30 18:59:07Z doligez $ */

 #include "windbug.h"

@@ -26,7 +26,7 @@
     debug = (getenv("OCAMLDEBUG") != NULL);
     debug_init = 1;
   };
-#endif 
+#endif

   return debug;
 }
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/windbug.h ocaml-unix-4.00.1/otherlibs/win32unix/windbug.h
--- ocaml-unix-3.12.1/otherlibs/win32unix/windbug.h     2010-05-25 15:01:06.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/windbug.h     2012-01-14 10:40:49.000000000 +0100
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Contributed by Sylvain Le Gall for Lexifi                          */
 /*                                                                     */
@@ -11,20 +11,22 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: windbug.h 10467 2010-05-25 13:01:06Z xleroy $ */
+/* $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)
+ */
 #define DEBUG_PRINT(fmt, ...) \
   do \
   { \
     if (debug_test()) \
     { \
-      fprintf(stderr, "DBUG (pid:%d, tid: %d): ", GetCurrentProcessId(), GetCurrentThreadId()); \
-      fprintf(stderr, fmt, __VA_ARGS__); \
+      fprintf(stderr, "DBUG (pid:%ld, tid: %ld): ", GetCurrentProcessId(), GetCurrentThreadId()); \
+      fprintf(stderr, fmt, ##__VA_ARGS__); \
       fprintf(stderr, "\n"); \
       fflush(stderr); \
     }; \
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/windir.c ocaml-unix-4.00.1/otherlibs/win32unix/windir.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/windir.c      2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/windir.c      2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*   Pascal Cuoq and Xavier Leroy, projet Cristal, INRIA Rocquencourt  */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: windir.c 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: windir.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <mlvalues.h>
 #include <memory.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/winlist.c ocaml-unix-4.00.1/otherlibs/win32unix/winlist.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/winlist.c     2008-07-31 14:09:18.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/winlist.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Contributed by Sylvain Le Gall for Lexifi                          */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: winlist.c 8961 2008-07-31 12:09:18Z xleroy $ */
+/* $Id: winlist.c 11156 2011-07-27 14:17:02Z doligez $ */

 /* Basic list function in C. */

diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/winlist.h ocaml-unix-4.00.1/otherlibs/win32unix/winlist.h
--- ocaml-unix-3.12.1/otherlibs/win32unix/winlist.h     2008-07-31 14:09:18.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/winlist.h     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Contributed by Sylvain Le Gall for Lexifi                          */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: winlist.h 8961 2008-07-31 12:09:18Z xleroy $ */
+/* $Id: winlist.h 11156 2011-07-27 14:17:02Z doligez $ */
 #ifndef _WINLIST_H
 #define _WINLIST_H

diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/winwait.c ocaml-unix-4.00.1/otherlibs/win32unix/winwait.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/winwait.c     2008-01-11 17:13:18.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/winwait.c     2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*   Pascal Cuoq and Xavier Leroy, projet Cristal, INRIA Rocquencourt  */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: winwait.c 8768 2008-01-11 16:13:18Z doligez $ */
+/* $Id: winwait.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <windows.h>
 #include <mlvalues.h>
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/winworker.c ocaml-unix-4.00.1/otherlibs/win32unix/winworker.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/winworker.c   2010-05-25 15:01:06.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/winworker.c   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Contributed by Sylvain Le Gall for Lexifi                          */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: winworker.c 10467 2010-05-25 13:01:06Z xleroy $ */
+/* $Id: winworker.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include "winworker.h"
 #include "winlist.h"
diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/winworker.h ocaml-unix-4.00.1/otherlibs/win32unix/winworker.h
--- ocaml-unix-3.12.1/otherlibs/win32unix/winworker.h   2010-01-22 13:48:24.000000000 +0100
+++ ocaml-unix-4.00.1/otherlibs/win32unix/winworker.h   2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*  Contributed by Sylvain Le Gall for Lexifi                          */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: winworker.h 9547 2010-01-22 12:48:24Z doligez $ */
+/* $Id: winworker.h 11156 2011-07-27 14:17:02Z doligez $ */
 #ifndef _WINWORKER_H
 #define _WINWORKER_H

diff -Naur ocaml-unix-3.12.1/otherlibs/win32unix/write.c ocaml-unix-4.00.1/otherlibs/win32unix/write.c
--- ocaml-unix-3.12.1/otherlibs/win32unix/write.c       2009-09-25 17:03:06.000000000 +0200
+++ ocaml-unix-4.00.1/otherlibs/win32unix/write.c       2011-07-27 16:17:02.000000000 +0200
@@ -1,6 +1,6 @@
 /***********************************************************************/
 /*                                                                     */
-/*                           Objective Caml                            */
+/*                                OCaml                                */
 /*                                                                     */
 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
 /*                                                                     */
@@ -11,7 +11,7 @@
 /*                                                                     */
 /***********************************************************************/

-/* $Id: write.c 9359 2009-09-25 15:03:06Z weis $ */
+/* $Id: write.c 11156 2011-07-27 14:17:02Z doligez $ */

 #include <errno.h>
 #include <string.h>