You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 335 Reporter: administrator Status: closed Resolution: not a bug Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
See transcript below. Note that opening the file with open_out_gen
seems to be the trigger. The problem also exists under Linux, so I presume
it is not an OpenBSD-specific problem.
$ touch foo
$ ocaml
Objective Caml version 3.01
let file = open_out_gen ~mode:[ Open_append ] ~perm:0o644 "foo" in
See transcript below. Note that opening the file with open_out_gen
seems to be the trigger. The problem also exists under Linux, so I presume
it is not an OpenBSD-specific problem.
It's actually normal Unix (POSIX) behavior. Opening a file in
"append" mode doesn't open it in "write" mode automatically:
let file = open_out_gen ~mode:[ Open_append ] ~perm:0o644 "foo" in
Here, you get a Unix file descriptor that is not opened in write mode.
Caml builds an I/O buffer on top of it.
begin
output_string file "test";
Here, Caml writes to the I/O buffer. No actual Unix I/O yet, so no
error.
close_out file;
Here, Caml flushes its buffer in preparation for closing it. Flushing
means performing an actual Unix write() system call, which lets you
know that it doesn't like your file descriptor:
The problem is not with "close_out" -- any operation that actually
performs a Unix write() operation, such as flushing or writing more
data than fits in the buffer, would do the same.
The solution is of course to open in write mode AND append mode:
let file = open_out_gen ~mode:[Open_write;Open_append] ~perm:0o644 "foo"
I agree this is a bit surprising, but it's all standard Unix
behavior. You'd get exactly the same situation in a C program using
stdio.
Original bug ID: 335
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Full_Name: Matt Liggett
Version: OCaml 3.01
OS: OpenBSD/i386 2.8
Submission from: chapman.ciswired.com (206.97.67.75)
See transcript below. Note that opening the file with open_out_gen
seems to be the trigger. The problem also exists under Linux, so I presume
it is not an OpenBSD-specific problem.
$ touch foo
$ ocaml
Objective Caml version 3.01
let file = open_out_gen ~mode:[ Open_append ] ~perm:0o644 "foo" in
begin
output_string file "test";
close_out file;
end;;
Uncaught exception: Sys_error "Bad file descriptor".
let file = open_out "floop" in
begin
output_string file "test";
close_out file;
end;;
The text was updated successfully, but these errors were encountered: