From: Pierre Habouzit Date: Sun, 20 May 2007 12:11:32 +0000 (+0200) Subject: unlink file before writing it X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=513217100b6a51a7b9428e83e1d1df6df28b4db7 unlink file before writing it Signed-off-by: Pierre Habouzit --- diff --git a/tools/Makefile b/tools/Makefile index 4164759..e056653 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,5 +1,5 @@ cpkg2c: cpkg2c.mll ocamllex $< - $(if $(shell which ocamlopt),ocamlopt -o $@ str.cmxa,ocamlc -o $@ str.cma) $@.ml + $(if $(shell which ocamlopt),ocamlopt -o $@ str.cmxa unix.cmxa,ocamlc -o $@ str.cma unix.cma) $@.ml @$(RM) cpkg2c.ml cpkg2c.c* cpkg2c.o diff --git a/tools/cpkg2c.mll b/tools/cpkg2c.mll index a3a3782..c0a0453 100644 --- a/tools/cpkg2c.mll +++ b/tools/cpkg2c.mll @@ -630,12 +630,13 @@ int luaopen_%s(lua_State *L) let file = Sys.argv.(2) in let lexbuf = L.from_channel (open_in file) in let l = (startchunk cLine file lexbuf) in - if Sys.argv.(3) = "-o" then - let ob = open_out_gen [ Open_trunc ; Open_wronly; Open_creat ] 0o444 Sys.argv.(4) in - match Sys.argv.(1) with - | "-h" -> warn ob; do_h ob l; close_out ob - | "-c" -> warn ob; do_c ob l; close_out ob - | _ -> usage () - else + if Sys.argv.(3) = "-o" then ( + Unix.unlink Sys.argv.(4); + let ob = open_out_gen [ Open_trunc ; Open_wronly; Open_creat ] 0o444 Sys.argv.(4) in + match Sys.argv.(1) with + | "-h" -> warn ob; do_h ob l; close_out ob + | "-c" -> warn ob; do_c ob l; close_out ob + | _ -> usage () + ) else usage(); }