summaryrefslogtreecommitdiffstats
path: root/byterun
diff options
context:
space:
mode:
authorMark Shinwell <mshinwell@janestreet.com>2010-04-23 07:58:59 +0000
committerMark Shinwell <mshinwell@janestreet.com>2010-04-23 07:58:59 +0000
commit62d8b11287062ccd0e17eae0e9816ae4ab3b8ff7 (patch)
tree299fddf2919542b0fa7954292b228ec5fc6150a1 /byterun
parent27780d9f8a6812ac8d79c80565ebd5d991db8f65 (diff)
fix mantis 5032
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10300 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'byterun')
-rw-r--r--byterun/io.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/byterun/io.c b/byterun/io.c
index 44d1f293c..e7c7f0485 100644
--- a/byterun/io.c
+++ b/byterun/io.c
@@ -494,19 +494,30 @@ CAMLprim value caml_channel_descriptor(value vchannel)
CAMLprim value caml_ml_close_channel(value vchannel)
{
int result;
+ int do_syscall;
+ int fd;
/* For output channels, must have flushed before */
struct channel * channel = Channel(vchannel);
if (channel->fd != -1){
- result = close(channel->fd);
+ fd = channel->fd;
channel->fd = -1;
+ do_syscall = 1;
}else{
+ do_syscall = 0;
result = 0;
}
/* Ensure that every read or write on the channel will cause an
immediate caml_flush_partial or caml_refill, thus raising a Sys_error
exception */
channel->curr = channel->max = channel->end;
+
+ if (do_syscall) {
+ caml_enter_blocking_section();
+ result = close(fd);
+ caml_leave_blocking_section();
+ }
+
if (result == -1) caml_sys_error (NO_ARG);
return Val_unit;
}