--- file.c	2006-07-11 11:00:41.000000000 -0200
+++ file.c.new	2007-06-09 07:49:32.000000000 -0200
@@ -18,6 +18,9 @@
 #include <stdio.h>
 #ifdef NEKO_WINDOWS
 #	include <windows.h>
+#	include <file.h>
+#else
+#	include <sys/file.h>
 #endif
 
 /**
@@ -77,6 +80,29 @@
 	return val_true;
 }
 
+static value file_lock( value o, value exclusive ) {
+	fio *f;
+	int error_code;
+	val_check_kind(o, k_file);
+	val_check(exclusive, bool);
+	f = val_file(o);
+	error_code = flock(fileno(f->io), (exclusive ? LOCK_EX : LOCK_SH) | LOCK_NB);
+	if(error_code == -1) {
+		return val_false;
+	}
+	return val_true;
+}
+
+static value file_unlock( value o) {
+	fio *f;
+	val_check_kind(o, k_file);
+	f = val_file(o);
+	if(-1 == flock(fileno(f->io), LOCK_UN)) {
+		file_error("file_unlock", f);
+	}
+	return val_true;
+}
+
 /**
 	file_name : 'file -> string
 	<doc>Return the name of the file which was opened</doc>
@@ -303,5 +329,7 @@
 DEFINE_PRIM(file_eof,1);
 DEFINE_PRIM(file_flush,1);
 DEFINE_PRIM(file_contents,1);
+DEFINE_PRIM(file_lock,2);
+DEFINE_PRIM(file_unlock,1);
 
 /* ************************************************************************ */
