summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/io.c b/io.c
index 583353c609..8b7fb21542 100644
--- a/io.c
+++ b/io.c
@@ -816,18 +816,23 @@ next_argv()
VALUE str;
FILE *fw;
- if (!*inplace) {
- Fatal("Can't do inplace edit without backup");
- }
if (rb_defout != rb_stdout) {
Fio_close(rb_defout);
}
fstat(fileno(fr), &st);
- str = str_new2(fn);
- str_cat(str, inplace, strlen(inplace));
- if (rename(fn, RSTRING(str)->ptr) < 0) {
- Warning("Can't rename %s to %s: %s, skipping file",
- fn, RSTRING(str)->ptr, strerror(errno));
+ if (*inplace) {
+ str = str_new2(fn);
+ str_cat(str, inplace, strlen(inplace));
+ if (rename(fn, RSTRING(str)->ptr) < 0) {
+ Warning("Can't rename %s to %s: %s, skipping file",
+ fn, RSTRING(str)->ptr, strerror(errno));
+ fclose(fr);
+ goto retry;
+ }
+ }
+ else if (unlink(fn) < 0) {
+ Warning("Can't remove %s: %s, skipping file",
+ fn, strerror(errno));
fclose(fr);
goto retry;
}