update default opening flags for CCIO.with_{in,out}

This commit is contained in:
Simon Cruanes 2015-05-29 20:58:37 +02:00
parent 5e1ab12fda
commit 36bd12ff45
2 changed files with 10 additions and 8 deletions

View file

@ -73,7 +73,7 @@ let gen_flat_map f next_elem =
next next
let with_in ?(mode=0o644) ?(flags=[]) filename f = let with_in ?(mode=0o644) ?(flags=[]) filename f =
let ic = open_in_gen flags mode filename in let ic = open_in_gen (Open_rdonly::flags) mode filename in
try try
let x = f ic in let x = f ic in
close_in ic; close_in ic;
@ -134,8 +134,8 @@ let read_all ?(size=1024) ic =
with Exit -> with Exit ->
Bytes.sub_string !buf 0 !len Bytes.sub_string !buf 0 !len
let with_out ?(mode=0o644) ?(flags=[]) filename f = let with_out ?(mode=0o644) ?(flags=[Open_creat]) filename f =
let oc = open_out_gen flags mode filename in let oc = open_out_gen (Open_wronly::flags) mode filename in
try try
let x = f oc in let x = f oc in
close_out oc; close_out oc;
@ -145,7 +145,7 @@ let with_out ?(mode=0o644) ?(flags=[]) filename f =
raise e raise e
let with_out_a ?mode ?(flags=[]) filename f = let with_out_a ?mode ?(flags=[]) filename f =
with_out ?mode ~flags:(Open_creat::Open_append::flags) filename f with_out ?mode ~flags:(Open_wronly::Open_creat::Open_append::flags) filename f
let write_line oc s = let write_line oc s =
output_string oc s; output_string oc s;

View file

@ -69,7 +69,8 @@ val with_in : ?mode:int -> ?flags:open_flag list ->
string -> (in_channel -> 'a) -> 'a string -> (in_channel -> 'a) -> 'a
(** Open an input file with the given optional flag list, calls the function (** Open an input file with the given optional flag list, calls the function
on the input channel. When the function raises or returns, the on the input channel. When the function raises or returns, the
channel is closed. *) channel is closed.
@param flags opening flags (default [[Open_rdonly]]) *)
val read_chunks : ?size:int -> in_channel -> string gen val read_chunks : ?size:int -> in_channel -> string gen
(** Read the channel's content into chunks of size [size] *) (** Read the channel's content into chunks of size [size] *)
@ -92,12 +93,13 @@ val read_all : ?size:int -> in_channel -> string
val with_out : ?mode:int -> ?flags:open_flag list -> val with_out : ?mode:int -> ?flags:open_flag list ->
string -> (out_channel -> 'a) -> 'a string -> (out_channel -> 'a) -> 'a
(** Same as {!with_in} but for an output channel *) (** Same as {!with_in} but for an output channel
@param flags opening flags (default [[Open_creat; Open_wronly]]) *)
val with_out_a : ?mode:int -> ?flags:open_flag list -> val with_out_a : ?mode:int -> ?flags:open_flag list ->
string -> (out_channel -> 'a) -> 'a string -> (out_channel -> 'a) -> 'a
(** Similar to {!with_out} but with the [Open_append] and [Open_creat] (** Similar to {!with_out} but with the [[Open_append; Open_creat; Open_wronly]]
flags activated *) flags activated, to append to the file *)
val write_line : out_channel -> string -> unit val write_line : out_channel -> string -> unit
(** Write the given string on the channel, followed by "\n" *) (** Write the given string on the channel, followed by "\n" *)