1
(***********************************************************************)
5
(* Fran�ois Pessaux, projet Cristal, INRIA Rocquencourt *)
6
(* Pierre Weis, projet Cristal, INRIA Rocquencourt *)
7
(* Jun Furuse, projet Cristal, INRIA Rocquencourt *)
9
(* Copyright 1999 - 2003 *)
10
(* Institut National de Recherche en Informatique et en Automatique. *)
11
(* Distributed only by permission. *)
13
(***********************************************************************)
15
(* temporary directory *)
16
let tmp_dir = ref (try Sys.getenv "CAMLIMAGESTMPDIR" with Not_found -> "/tmp");;
20
let rec new_tmp_name prefx =
23
Filename.concat !tmp_dir
24
(Printf.sprintf "camlimages-%s-%d" prefx !cnter) in
25
if not (Sys.file_exists name) then name else begin
26
prerr_endline ("Warning: tmp file " ^ name ^ " already exists");
30
let remove_tmp_file tmpfile = try Sys.remove tmpfile with _ -> ();;
32
let new_tmp_file_name prefx =
33
if not (Sys.file_exists !tmp_dir) then
34
failwith ("Temporary directory " ^ !tmp_dir ^ " does not exist") else
35
let f = new_tmp_name prefx in
36
at_exit (fun () -> remove_tmp_file f);