let filename = getenv "HOME" // ".goaljobs-memory" in
let fd = openfile filename [O_RDWR; O_CREAT] 0o644 in
lockf fd (if write then F_LOCK else F_RLOCK) 0;
+
(* If the file is newly created with zero size, write an
* empty hash table.
*)
(* Run the function. *)
let r = try Either (f fd) with exn -> Or exn in
lockf fd F_ULOCK 0;
+ close fd;
match r with
| Either x -> x
| Or exn -> raise exn