From 8039ec4db5ec942d4d91a82c347e497b4ba69e55 Mon Sep 17 00:00:00 2001 From: Jacques-Pascal Deplaix Date: Sat, 30 May 2015 04:54:44 +0100 Subject: [PATCH] Have better default opening flags for CCIO.with_{in, out} --- src/io/CCIO.ml | 4 ++-- src/io/CCIO.mli | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/io/CCIO.ml b/src/io/CCIO.ml index 9b61841d..20dc6ade 100644 --- a/src/io/CCIO.ml +++ b/src/io/CCIO.ml @@ -72,7 +72,7 @@ let gen_flat_map f next_elem = in next -let with_in ?(mode=0o644) ?(flags=[]) filename f = +let with_in ?(mode=0o644) ?(flags=[Open_text]) filename f = let ic = open_in_gen (Open_rdonly::flags) mode filename in try let x = f ic in @@ -134,7 +134,7 @@ let read_all ?(size=1024) ic = with Exit -> Bytes.sub_string !buf 0 !len -let with_out ?(mode=0o644) ?(flags=[Open_creat]) filename f = +let with_out ?(mode=0o644) ?(flags=[Open_creat; Open_trunc; Open_text]) filename f = let oc = open_out_gen (Open_wronly::flags) mode filename in try let x = f oc in diff --git a/src/io/CCIO.mli b/src/io/CCIO.mli index 13af260d..6e68ad88 100644 --- a/src/io/CCIO.mli +++ b/src/io/CCIO.mli @@ -48,7 +48,7 @@ Examples: with_in "/tmp/input" (fun ic -> let chunks = read_chunks ic in - with_out ~flags:[Open_creat; Open_wronly] ~mode:0o644 "/tmp/output" + with_out ~flags:[Open_binary] ~mode:0o644 "/tmp/output" (fun oc -> write_gen oc chunks ) @@ -70,7 +70,7 @@ val with_in : ?mode:int -> ?flags:open_flag list -> (** Open an input file with the given optional flag list, calls the function on the input channel. When the function raises or returns, the channel is closed. - @param flags opening flags (default [[Open_rdonly]]) *) + @param flags opening flags (default [[Open_text]]). [Open_rdonly] is used in any cases *) val read_chunks : ?size:int -> in_channel -> string gen (** Read the channel's content into chunks of size [size] *) @@ -94,7 +94,7 @@ val read_all : ?size:int -> in_channel -> string val with_out : ?mode:int -> ?flags:open_flag list -> string -> (out_channel -> 'a) -> 'a (** Same as {!with_in} but for an output channel - @param flags opening flags (default [[Open_creat; Open_wronly]]) *) + @param flags opening flags (default [[Open_creat; Open_trunc; Open_text]]). [Open_wronly] is used in any cases *) val with_out_a : ?mode:int -> ?flags:open_flag list -> string -> (out_channel -> 'a) -> 'a