From 513217100b6a51a7b9428e83e1d1df6df28b4db7 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sun, 20 May 2007 14:11:32 +0200 Subject: [PATCH] unlink file before writing it Signed-off-by: Pierre Habouzit --- tools/Makefile | 2 +- tools/cpkg2c.mll | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) 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(); } -- 2.20.1