From e97fb4b0d6167510f30a24a46f07b85aa45229a3 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sun, 18 Jan 2004 23:32:56 +0000 Subject: [PATCH] Windows rename() needs an unlink() first (reported by Steven Edwards). --- tools/bin2res.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/bin2res.c b/tools/bin2res.c index e1654a3add6..68e76cc8160 100644 --- a/tools/bin2res.c +++ b/tools/bin2res.c @@ -183,8 +183,18 @@ int process_resources(const char* input_file_name, const char* specific_file_nam if (inserting) { fclose(ftmp); - if (c == EOF && rename(tmp_file_name, input_file_name) < 0) - c = '.'; /* force an error */ + if (c == EOF) + { + if (rename(tmp_file_name, input_file_name) < 0) + { + /* try unlinking first, Windows rename is brain-damaged */ + if (unlink(input_file_name) < 0 || rename(tmp_file_name, input_file_name) < 0) + { + unlink(tmp_file_name); + return 0; + } + } + } else unlink(tmp_file_name); }