summaryrefslogtreecommitdiffstats
path: root/otherlibs/unix
diff options
context:
space:
mode:
Diffstat (limited to 'otherlibs/unix')
-rw-r--r--otherlibs/unix/lockf.c61
-rw-r--r--otherlibs/unix/unix.ml3
-rw-r--r--otherlibs/unix/unix.mli19
3 files changed, 51 insertions, 32 deletions
diff --git a/otherlibs/unix/lockf.c b/otherlibs/unix/lockf.c
index 2cffcd062..0b1f34b7e 100644
--- a/otherlibs/unix/lockf.c
+++ b/otherlibs/unix/lockf.c
@@ -11,36 +11,12 @@
/* $Id$ */
-#include <mlvalues.h>
-#include "unixsupport.h"
-
-#ifdef HAS_LOCKF
-#ifdef HAS_UNISTD
-#include <unistd.h>
-#else
-#define F_ULOCK 0
-#define F_LOCK 1
-#define F_TLOCK 2
-#define F_TEST 3
-#endif
-
-static int lock_command_table[] = {
- F_ULOCK, F_LOCK, F_TLOCK, F_TEST
-};
-
-value unix_lockf(value fd, value cmd, value span) /* ML */
-{
- if (lockf(Int_val(fd), lock_command_table[Int_val(cmd)], Long_val(span))
- == -1) uerror("lockf", Nothing);
- return Val_unit;
-}
-
-#else
-
#include <errno.h>
#include <fcntl.h>
+#include <mlvalues.h>
+#include "unixsupport.h"
-#ifdef F_SETLK
+#if defined(F_GETLK) && defined(F_SETLK) && defined(F_SETLKW)
value unix_lockf(value fd, value cmd, value span) /* ML */
{
@@ -84,6 +60,14 @@ value unix_lockf(value fd, value cmd, value span) /* ML */
}
}
break;
+ case 4: /* F_RLOCK */
+ l.l_type = F_RDLCK;
+ ret = fcntl(fildes, F_SETLKW, &l);
+ break;
+ case 5: /* F_TRLOCK */
+ l.l_type = F_RDLCK;
+ ret = fcntl(fildes, F_SETLK, &l);
+ break;
default:
errno = EINVAL;
ret = -1;
@@ -94,6 +78,29 @@ value unix_lockf(value fd, value cmd, value span) /* ML */
#else
+#ifdef HAS_LOCKF
+#ifdef HAS_UNISTD
+#include <unistd.h>
+#else
+#define F_ULOCK 0
+#define F_LOCK 1
+#define F_TLOCK 2
+#define F_TEST 3
+#endif
+
+static int lock_command_table[] = {
+ F_ULOCK, F_LOCK, F_TLOCK, F_TEST, F_LOCK, F_TLOCK
+};
+
+value unix_lockf(value fd, value cmd, value span) /* ML */
+{
+ if (lockf(Int_val(fd), lock_command_table[Int_val(cmd)], Long_val(span))
+ == -1) uerror("lockf", Nothing);
+ return Val_unit;
+}
+
+#else
+
value unix_lockf(value fd, value cmd, value span)
{ invalid_argument("lockf not implemented"); }
diff --git a/otherlibs/unix/unix.ml b/otherlibs/unix/unix.ml
index 78b6d9597..e9f96e10e 100644
--- a/otherlibs/unix/unix.ml
+++ b/otherlibs/unix/unix.ml
@@ -235,6 +235,7 @@ external mkdir : string -> file_perm -> unit = "unix_mkdir"
external rmdir : string -> unit = "unix_rmdir"
external chdir : string -> unit = "unix_chdir"
external getcwd : unit -> string = "unix_getcwd"
+external chroot : string -> unit = "unix_chroot"
type dir_handle
@@ -256,6 +257,8 @@ type lock_command =
| F_LOCK
| F_TLOCK
| F_TEST
+ | F_RLOCK
+ | F_TRLOCK
external lockf : file_descr -> lock_command -> int -> unit = "unix_lockf"
external kill : int -> int -> unit = "unix_kill"
diff --git a/otherlibs/unix/unix.mli b/otherlibs/unix/unix.mli
index 0f55c1a34..5fac6cd99 100644
--- a/otherlibs/unix/unix.mli
+++ b/otherlibs/unix/unix.mli
@@ -371,6 +371,8 @@ val chdir : string -> unit
(* Change the process working directory. *)
val getcwd : unit -> string
(* Return the name of the current working directory. *)
+val chroot : string -> unit
+ (* Change the process root directory. *)
type dir_handle
@@ -472,10 +474,12 @@ val select :
(*** Locking *)
type lock_command =
- F_ULOCK (* Unlock a region *)
- | F_LOCK (* Lock a region, and block if already locked *)
- | F_TLOCK (* Lock a region, or fail if already locked *)
- | F_TEST (* Test a region for other process' locks *)
+ F_ULOCK (* Unlock a region *)
+ | F_LOCK (* Lock a region for writing, and block if already locked *)
+ | F_TLOCK (* Lock a region for writing, or fail if already locked *)
+ | F_TEST (* Test a region for other process locks *)
+ | F_RLOCK (* Lock a region for reading, and block if already locked *)
+ | F_TRLOCK (* Lock a region for reading, or fail if already locked *)
(* Commands for [lockf]. *)
@@ -485,7 +489,12 @@ val lockf : file_descr -> lock_command -> int -> unit
as [fd]. The region starts at the current read/write position for
[fd] (as set by [lseek]), and extends [size] bytes forward if
[size] is positive, [size] bytes backwards if [size] is negative,
- or to the end of the file if [size] is zero. *)
+ or to the end of the file if [size] is zero.
+ A write lock (set with [F_LOCK] or [F_TLOCK]) prevents any other
+ process from acquiring a read or write lock on the region.
+ A read lock (set with [F_RLOCK] or [F_TRLOCK]) prevents any other
+ process from acquiring a write lock on the region, but lets
+ other processes acquire read locks on it. *)
(*** Signals *)