mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
changed the API of CCBigstring.map_file
This commit is contained in:
parent
a63d095722
commit
88ceaa0d99
2 changed files with 15 additions and 10 deletions
|
|
@ -207,13 +207,17 @@ let to_gen_slice a i len =
|
|||
let map_file_descr ?pos ?(shared=false) fd len =
|
||||
B.map_file fd ?pos Bigarray.char Bigarray.c_layout shared len
|
||||
|
||||
let with_map_file ?pos ?(mode=0o644) ?(flags=[Unix.O_RDONLY]) ?shared name len f =
|
||||
let fd = Unix.openfile name flags mode in
|
||||
let a = map_file_descr ?pos ?shared fd len in
|
||||
let with_map_file ?pos ?len ?(mode=0o644) ?(flags=[Open_rdonly]) ?shared name f =
|
||||
let ic = open_in_gen flags mode name in
|
||||
let len = match len with
|
||||
| None -> in_channel_length ic
|
||||
| Some n -> n
|
||||
in
|
||||
let a = map_file_descr ?pos ?shared (Unix.descr_of_in_channel ic) len in
|
||||
try
|
||||
let x = f a in
|
||||
Unix.close fd;
|
||||
close_in ic;
|
||||
x
|
||||
with e ->
|
||||
Unix.close fd;
|
||||
close_in ic;
|
||||
raise e
|
||||
|
|
|
|||
|
|
@ -107,11 +107,12 @@ val to_gen_slice : t -> int -> int -> char gen
|
|||
(** {2 Memory-map} *)
|
||||
|
||||
val with_map_file :
|
||||
?pos:int64 -> ?mode:int -> ?flags:Unix.open_flag list -> ?shared:bool ->
|
||||
string -> int -> (t -> 'a) -> 'a
|
||||
(** [with_map_file name len f] maps the file into memory, opening it, and
|
||||
call [f] with a slice [pos.... pos+len] of the bytes of the file. When
|
||||
[f] returns, the file is closed.
|
||||
?pos:int64 -> ?len:int -> ?mode:int -> ?flags:open_flag list -> ?shared:bool ->
|
||||
string -> (t -> 'a) -> 'a
|
||||
(** [with_map_file name f] maps the file into memory, opening it, and
|
||||
call [f] with a slice [pos.... pos+len] of the bytes of the file
|
||||
where [len] is the length of the file if not provided.
|
||||
When [f] returns, the file is closed.
|
||||
@param pos offset in the file (default 0)
|
||||
@param shared if true, modifications are shared between processes that
|
||||
have mapped this file (requires the filedescr to be open in write mode).
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue