mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
fix bug in CCPrint.to_file
This commit is contained in:
parent
4102f3b95d
commit
f6fd779f1c
1 changed files with 8 additions and 3 deletions
|
|
@ -127,6 +127,13 @@ let fprintf oc format =
|
||||||
buffer
|
buffer
|
||||||
format
|
format
|
||||||
|
|
||||||
|
let kfprintf k oc format =
|
||||||
|
let buffer = Buffer.create 64 in
|
||||||
|
Printf.kbprintf
|
||||||
|
(fun fmt -> Buffer.output_buffer oc buffer; k fmt)
|
||||||
|
buffer
|
||||||
|
format
|
||||||
|
|
||||||
let printf format = fprintf stdout format
|
let printf format = fprintf stdout format
|
||||||
let eprintf format = fprintf stderr format
|
let eprintf format = fprintf stderr format
|
||||||
|
|
||||||
|
|
@ -134,8 +141,6 @@ let _with_file_out filename f =
|
||||||
let oc = open_out filename in
|
let oc = open_out filename in
|
||||||
begin try
|
begin try
|
||||||
let x = f oc in
|
let x = f oc in
|
||||||
flush oc;
|
|
||||||
close_out oc;
|
|
||||||
x
|
x
|
||||||
with e ->
|
with e ->
|
||||||
close_out_noerr oc;
|
close_out_noerr oc;
|
||||||
|
|
@ -143,7 +148,7 @@ let _with_file_out filename f =
|
||||||
end
|
end
|
||||||
|
|
||||||
let to_file filename format =
|
let to_file filename format =
|
||||||
_with_file_out filename (fun oc -> fprintf oc format)
|
_with_file_out filename (fun oc -> kfprintf (fun _ -> close_out oc) oc format)
|
||||||
|
|
||||||
(** {2 Monadic IO} *)
|
(** {2 Monadic IO} *)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue