diff --git a/src/configure.in b/src/configure.in
index 2c6847ff5c4592f3f3143634b60d623c20103dcd..0c27165dbb9d36c6625da7e0a640e4d648d2bb22 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -1,4 +1,4 @@
-AC_REVISION("$Id: configure.in,v 1.188 1998/05/17 23:15:58 grubba Exp $")
+AC_REVISION("$Id: configure.in,v 1.189 1998/05/22 08:25:52 neotron Exp $")
 AC_INIT(interpret.c)
 AC_CONFIG_HEADER(machine.h)
 
@@ -994,6 +994,7 @@ AC_CHECK_FUNCS( \
  fork \
  fork1 \
  flock \
+ lockf \
  setuid getuid seteuid geteuid \
  setgid getgid setegid getegid \
  getpwent getpwnam getpwuid \
diff --git a/src/fdlib.h b/src/fdlib.h
index ac038faad91de9a59c4a378fba21633cbb27927c..b550978f227b76cb8133c5144cf43dbd6e708332 100644
--- a/src/fdlib.h
+++ b/src/fdlib.h
@@ -1,5 +1,5 @@
 /*
- * $Id: fdlib.h,v 1.14 1998/04/06 04:22:11 hubbe Exp $
+ * $Id: fdlib.h,v 1.15 1998/05/22 08:25:53 neotron Exp $
  */
 #ifndef FDLIB_H
 #define FDLIB_H
@@ -206,7 +206,7 @@ extern int fd_type[MAX_OPEN_FILEDESCRIPTORS];
 #define S_IFSOCK 0140000
 #endif
 
-#else
+#else // HAVE_WINSOCK
 
 
 typedef int FD;
@@ -259,15 +259,25 @@ typedef int FD;
 #define fd_FD_ISSET FD_ISSET
 #define fd_FD_ZERO FD_ZERO
 
+#ifdef HAVE_FLOCK
+#define HAVE_FD_FLOCK
 #define fd_flock flock
 #define fd_LOCK_SH LOCK_SH
 #define fd_LOCK_EX LOCK_EX
 #define fd_LOCK_UN LOCK_UN
 #define fd_LOCK_NB LOCK_NB
-
-#ifdef HAVE_FLOCK
-#define HAVE_FD_FLOCK
+#else
+#ifdef HAVE_LOCKF
+#define HAVE_FD_LOCKF
+#define fd_LOCK_EX F_LOCK
+#define fd_LOCK_UN F_ULOCK
+#define fd_LOCK_NB F_TLOCK
+#define fd_lockf(fd,mode) lockf(fd,mode,0)
 #endif
+#endif
+
+
+
 
 #define fd_shutdown_read 0
 #define fd_shutdown_write 1
@@ -303,6 +313,6 @@ typedef struct my_fd_set_s
 #define SEEK_END 2
 #endif
 
-#endif
+#endif // Don't HAVE_WINSOCK
 
-#endif
+#endif // FDLIB_H
diff --git a/src/modules/files/file.c b/src/modules/files/file.c
index 20baa6b0c62f10bf1f4baf938564cf910e29613e..5b3f8f2ff0eb59d32e253f5bcecd90cdfaa397d0 100644
--- a/src/modules/files/file.c
+++ b/src/modules/files/file.c
@@ -5,7 +5,7 @@
 \*/
 
 #include "global.h"
-RCSID("$Id: file.c,v 1.97 1998/05/19 20:35:39 hubbe Exp $");
+RCSID("$Id: file.c,v 1.98 1998/05/22 08:25:54 neotron Exp $");
 #include "fdlib.h"
 #include "interpret.h"
 #include "svalue.h"
@@ -174,7 +174,7 @@ static void init_fd(int fd, int open_mode)
   THIS->write_oob_callback.type=T_INT;
   THIS->write_oob_callback.u.integer=0;
 #endif /* WITH_OOB */
-#ifdef HAVE_FD_FLOCK
+#if defined(HAVE_FD_FLOCK) || defined(HAVE_FD_LOCKF) 
   THIS->key=0;
 #endif
 }
@@ -196,7 +196,7 @@ void reset_variables(void)
 
 static void free_fd_stuff(void)
 {
-#ifdef HAVE_FD_FLOCK
+#if defined(HAVE_FD_FLOCK) || defined(HAVE_FD_LOCKF) 
   if(THIS->key)
   {
     destruct(THIS->key);
@@ -1464,7 +1464,7 @@ static void init_file_struct(struct object *o)
   ERRNO=0;
   THIS->open_mode=0;
   THIS->flags=0;
-#ifdef HAVE_FD_FLOCK
+#if defined(HAVE_FD_FLOCK) || defined(HAVE_FD_LOCKF) 
   THIS->key=0;
 #endif /* HAVE_FD_FLOCK */
   THIS->myself=o;
@@ -1936,7 +1936,7 @@ void create_proxy_pipe(struct object *o, int for_reading)
 
 #endif
 
-#ifdef HAVE_FD_FLOCK
+#if defined(HAVE_FD_FLOCK) || defined(HAVE_FD_LOCKF) 
 
 static struct program * file_lock_key_program;
 
@@ -1974,7 +1974,11 @@ static void low_file_lock(INT32 args, int flags)
   o=clone_object(file_lock_key_program,0);
 
   THREADS_ALLOW();
+#ifdef HAVE_FD_FLOCK
   ret=fd_flock(fd, flags);
+#else
+  ret=fd_lockf(fd, flags);
+#endif  
   THREADS_DISALLOW();
 
   if(ret<0)
@@ -1996,10 +2000,19 @@ static void file_lock(INT32 args)
   low_file_lock(args,fd_LOCK_EX);
 }
 
+// If (fd_LOCK_EX | fd_LOCK_NB) is used with lockf, the result will be
+// F_TEST, which only tests for the existance of a lock on the file.
+#ifdef HAVE_FD_FLOCK
 static void file_trylock(INT32 args)
 {
   low_file_lock(args,fd_LOCK_EX | fd_LOCK_NB);
 }
+#else
+static void file_trylock(INT32 args)
+{
+  low_file_lock(args, fd_LOCK_NB);
+}
+#endif
 
 #define THIS_KEY ((struct file_lock_key_storage *)(fp->current_storage))
 static void init_file_lock_key(struct object *o)
@@ -2025,7 +2038,11 @@ static void exit_file_lock_key(struct object *o)
     THREADS_ALLOW();
     do
     {
+#ifdef HAVE_FD_FLOCK
       err=fd_flock(fd, fd_LOCK_UN);
+#else
+      err=fd_lockf(fd, fd_LOCK_UN);
+#endif
     }while(err<0 && errno==EINTR);
     THREADS_DISALLOW();
 
diff --git a/src/modules/files/file.h b/src/modules/files/file.h
index 833ce00321f4fe3834d654ef53d6b2630caeb5cb..6f2ceb3727cdc13911e06064bd1d10c57360ad01 100644
--- a/src/modules/files/file.h
+++ b/src/modules/files/file.h
@@ -5,7 +5,7 @@
 \*/
 
 /*
- * $Id: file.h,v 1.10 1998/04/06 04:34:05 hubbe Exp $
+ * $Id: file.h,v 1.11 1998/05/22 08:25:55 neotron Exp $
  */
 
 #ifndef FILE_H
@@ -41,7 +41,7 @@ struct my_file
   struct svalue write_oob_callback;
 #endif /* WITH_OOB */
 
-#ifdef HAVE_FD_FLOCK
+#if defined(HAVE_FD_FLOCK) || defined(HAVE_FD_LOCKF) 
   struct object *key;
 #endif
   struct object *myself;
diff --git a/src/modules/files/file_functions.h b/src/modules/files/file_functions.h
index 4242dc51ee53e78be3bd3221e8982c3dc059a461..2c25bb60ed5fd869325188715be8e80d16c02b6a 100644
--- a/src/modules/files/file_functions.h
+++ b/src/modules/files/file_functions.h
@@ -44,7 +44,7 @@
   FILE_FUNC("proxy",file_proxy,"function(object:void)")
 #endif
 
-#ifdef HAVE_FD_FLOCK
+#if defined(HAVE_FD_FLOCK) || defined(HAVE_FD_LOCKF) 
   FILE_FUNC("lock",file_lock,"function(void|int:object)")
   FILE_FUNC("trylock",file_trylock,"function(void|int:object)")
 #endif
diff --git a/src/modules/files/testsuite.in b/src/modules/files/testsuite.in
index a253e3b39d619be13864fdd964fc212d4aa536f0..44b7bdd6e1df71bc48935e8e2dee35a3912d7f11 100644
--- a/src/modules/files/testsuite.in
+++ b/src/modules/files/testsuite.in
@@ -223,12 +223,12 @@ test_eq(Stdio.read_file("conftest",100,5),"")
 // locking
 cond([[Stdio.File()->lock]],
 [[
-  test_true(Stdio.File("conftest","wr")->lock())
-  test_true(Stdio.File("conftest","wr")->trylock())
-  test_true(Stdio.File("conftest","wr")->trylock())
+  test_true(Stdio.File("conftest","wr")->lock()&&1)
+  test_true(Stdio.File("conftest","wr")->trylock()&&1)
+  test_true(Stdio.File("conftest","wr")->trylock()&&1)
   test_eval_error([[mixed o=Stdio.File("conftest","wr"); objekt k=o->lock(); o->lock();]])
   test_any([[mixed o=Stdio.File("conftest","wr"); o->lock(); return o->trylock();]],0)
-  test_true(Stdio.File("conftest","wr")->lock())
+  test_true(Stdio.File("conftest","wr")->lock()&&1)
 ]])
 
 test_do(rm("conftest"))