summaryrefslogtreecommitdiff
path: root/otherlibs
diff options
context:
space:
mode:
authorFrancois Berenger <737920+UnixJunkie@users.noreply.github.com>2018-07-31 14:57:21 +0900
committerNicolás Ojeda Bär <n.oje.bar@gmail.com>2018-07-31 07:57:21 +0200
commit5b884d62447f1a9b7d840130726b73688ea349db (patch)
treeaa0a3a5a309f89db9a0134f6aa0713d13fa20cd7 /otherlibs
parent5de54bc149502672ffe4e58194407cb26895ce38 (diff)
downloadocaml-5b884d62447f1a9b7d840130726b73688ea349db.tar.gz
Unix fsync (#1839)
* added otherlibs/unix/fsync.c and otherlibs/unix/unix.ml * add Unix.fsync * added otherlibs/win32unix/fsync.c * Unix.fsync for windows * big typo * Rewrite Unix.fsync stub for Windows * belts and braces: fail in the case of named pipe * Add missing include * corrected header * better ocamldoc for fsync * rm fsync.c from the UNIX_FILES list * updated Changes for Unix.fsync * Use _commit instead of FlushFileBuffers * Include <io.h>
Diffstat (limited to 'otherlibs')
-rw-r--r--otherlibs/threads/unix.ml1
-rw-r--r--otherlibs/unix/Makefile2
-rw-r--r--otherlibs/unix/fsync.c35
-rw-r--r--otherlibs/unix/unix.ml2
-rw-r--r--otherlibs/unix/unix.mli3
-rw-r--r--otherlibs/win32unix/Makefile2
-rw-r--r--otherlibs/win32unix/unix.ml1
7 files changed, 43 insertions, 3 deletions
diff --git a/otherlibs/threads/unix.ml b/otherlibs/threads/unix.ml
index 605b732f0b..4cf44916db 100644
--- a/otherlibs/threads/unix.ml
+++ b/otherlibs/threads/unix.ml
@@ -212,6 +212,7 @@ external openfile : string -> open_flag list -> file_perm -> file_descr
= "unix_open"
external close : file_descr -> unit = "unix_close"
+external fsync : file_descr -> unit = "unix_fsync"
external unsafe_read : file_descr -> bytes -> int -> int -> int = "unix_read"
external unsafe_write : file_descr -> bytes -> int -> int -> int
= "unix_write"
diff --git a/otherlibs/unix/Makefile b/otherlibs/unix/Makefile
index 5638191f78..cbd398e4b7 100644
--- a/otherlibs/unix/Makefile
+++ b/otherlibs/unix/Makefile
@@ -23,7 +23,7 @@ EXTRACAMLFLAGS=-nolabels
LDOPTS=$(NATIVECCLIBS)
COBJS=accept.o access.o addrofstr.o alarm.o bind.o channels.o chdir.o \
- chmod.o chown.o chroot.o close.o closedir.o connect.o cst2constr.o \
+ chmod.o chown.o chroot.o close.o fsync.o closedir.o connect.o cst2constr.o \
cstringv.o dup.o dup2.o envir.o errmsg.o execv.o execve.o execvp.o exit.o \
fchmod.o fchown.o fcntl.o fork.o ftruncate.o \
getaddrinfo.o getcwd.o getegid.o geteuid.o getgid.o \
diff --git a/otherlibs/unix/fsync.c b/otherlibs/unix/fsync.c
new file mode 100644
index 0000000000..48e9f19665
--- /dev/null
+++ b/otherlibs/unix/fsync.c
@@ -0,0 +1,35 @@
+/**************************************************************************/
+/* */
+/* OCaml */
+/* */
+/* Francois Berenger, Kyushu Institute of Technology */
+/* */
+/* Copyright 2018 Institut National de Recherche en Informatique et */
+/* en Automatique. */
+/* */
+/* All rights reserved. This file is distributed under the terms of */
+/* the GNU Lesser General Public License version 2.1, with the */
+/* special exception on linking described in the file LICENSE. */
+/* */
+/**************************************************************************/
+
+#include <caml/mlvalues.h>
+#include <caml/signals.h>
+#include "unixsupport.h"
+
+#ifdef _WIN32
+#include <io.h>
+#define fsync(fd) _commit(win_CRT_fd_of_filedescr(fd))
+#else
+#define fsync(fd) fsync(Int_val(fd))
+#endif
+
+CAMLprim value unix_fsync(value fd)
+{
+ int ret;
+ caml_enter_blocking_section();
+ ret = fsync(fd);
+ caml_leave_blocking_section();
+ if (ret == -1) uerror("fsync", Nothing);
+ return Val_unit;
+}
diff --git a/otherlibs/unix/unix.ml b/otherlibs/unix/unix.ml
index 42110cce5c..dd1d770ff2 100644
--- a/otherlibs/unix/unix.ml
+++ b/otherlibs/unix/unix.ml
@@ -303,8 +303,8 @@ type file_perm = int
external openfile : string -> open_flag list -> file_perm -> file_descr
= "unix_open"
-
external close : file_descr -> unit = "unix_close"
+external fsync : file_descr -> unit = "unix_fsync"
external unsafe_read : file_descr -> bytes -> int -> int -> int
= "unix_read"
external unsafe_write : file_descr -> bytes -> int -> int -> int = "unix_write"
diff --git a/otherlibs/unix/unix.mli b/otherlibs/unix/unix.mli
index 6ef823f00a..78d60df704 100644
--- a/otherlibs/unix/unix.mli
+++ b/otherlibs/unix/unix.mli
@@ -307,6 +307,9 @@ val openfile : string -> open_flag list -> file_perm -> file_descr
val close : file_descr -> unit
(** Close a file descriptor. *)
+val fsync : file_descr -> unit
+(** Flush file buffers to disk. *)
+
val read : file_descr -> bytes -> int -> int -> int
(** [read fd buff ofs len] reads [len] bytes from descriptor [fd],
storing them in byte sequence [buff], starting at position [ofs] in
diff --git a/otherlibs/win32unix/Makefile b/otherlibs/win32unix/Makefile
index 05732c60e9..53c9a3917b 100644
--- a/otherlibs/win32unix/Makefile
+++ b/otherlibs/win32unix/Makefile
@@ -34,7 +34,7 @@ UNIX_FILES = access.c addrofstr.c chdir.c chmod.c cst2constr.c \
exit.c getaddrinfo.c getcwd.c gethost.c gethostname.c \
getnameinfo.c getproto.c \
getserv.c gmtime.c mmap_ba.c putenv.c rmdir.c \
- socketaddr.c strofaddr.c time.c unlink.c
+ socketaddr.c strofaddr.c time.c unlink.c fsync.c
UNIX_CAML_FILES = unix.mli unixLabels.mli unixLabels.ml
diff --git a/otherlibs/win32unix/unix.ml b/otherlibs/win32unix/unix.ml
index f51f52d433..a2d8dde199 100644
--- a/otherlibs/win32unix/unix.ml
+++ b/otherlibs/win32unix/unix.ml
@@ -182,6 +182,7 @@ type file_perm = int
external openfile : string -> open_flag list -> file_perm -> file_descr
= "unix_open"
external close : file_descr -> unit = "unix_close"
+external fsync : file_descr -> unit = "unix_fsync"
external unsafe_read : file_descr -> bytes -> int -> int -> int
= "unix_read"
external unsafe_write : file_descr -> bytes -> int -> int -> int