(* Fichiers munis de permissions *) type permission = Read Write module Access : sig type t val default: t val get: t -> permission -> bool val set: t -> permission -> bool -> t end = struct type t = { read: bool; write: bool } let default = { read = true; write = true } let get t = function Read -> t.read Write -> t.write let set t p v = match p with Read -> { t with read = v } Write -> { t with write = v } end exception PermissionDenied module File : sig type t = private { name: string; mutable access: Access.t } val create: string -> t val chmod: t -> Access.t -> unit val open_in: t -> in_channel val open_out: t -> out_channel end = struct type t = { name: string; mutable access: Access.t } let create f = { name = f; access = Access.default } let chmod f a = f.access <- a let open_in f = if not (Access.get f.access Read) then raise PermissionDenied; open_in f.name let open_out f = if not (Access.get f.access Write) then raise PermissionDenied; open_out f.name end
This document was generated using caml2html