summaryrefslogtreecommitdiffstats
path: root/otherlibs/unix
diff options
context:
space:
mode:
Diffstat (limited to 'otherlibs/unix')
-rw-r--r--otherlibs/unix/lseek.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/otherlibs/unix/lseek.c b/otherlibs/unix/lseek.c
index 6dece9503..cb59bb551 100644
--- a/otherlibs/unix/lseek.c
+++ b/otherlibs/unix/lseek.c
@@ -39,8 +39,10 @@ static int seek_command_table[] = {
CAMLprim value unix_lseek(value fd, value ofs, value cmd)
{
file_offset ret;
+ caml_enter_blocking_section();
ret = lseek(Int_val(fd), Long_val(ofs),
seek_command_table[Int_val(cmd)]);
+ caml_leave_blocking_section();
if (ret == -1) uerror("lseek", Nothing);
if (ret > Max_long) unix_error(EOVERFLOW, "lseek", Nothing);
return Val_long(ret);
@@ -49,8 +51,13 @@ CAMLprim value unix_lseek(value fd, value ofs, value cmd)
CAMLprim value unix_lseek_64(value fd, value ofs, value cmd)
{
file_offset ret;
- ret = lseek(Int_val(fd), File_offset_val(ofs),
- seek_command_table[Int_val(cmd)]);
+ /* [ofs] is an Int64, which is stored as a custom block; we must therefore
+ extract its contents before dropping the runtime lock, or it might be
+ moved. */
+ file_offset ofs_c = File_offset_val(ofs);
+ caml_enter_blocking_section();
+ ret = lseek(Int_val(fd), ofs_c, seek_command_table[Int_val(cmd)]);
+ caml_leave_blocking_section();
if (ret == -1) uerror("lseek", Nothing);
return Val_file_offset(ret);
}