summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorlum <lum@openbsd.org>2019-06-27 16:55:08 +0000
committerlum <lum@openbsd.org>2019-06-27 16:55:08 +0000
commite91a0089e69650df63bfd13170139c7d4af52dc9 (patch)
treedd86ce2a47136f29dc4a65d470be0bd5d3460922 /usr.bin
parentThe C89 standard only requires that atexit(3) returns a non-zero value (diff)
downloadwireguard-openbsd-e91a0089e69650df63bfd13170139c7d4af52dc9.tar.xz
wireguard-openbsd-e91a0089e69650df63bfd13170139c7d4af52dc9.zip
Display an error message if trying to copy or rename a file to itself.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mg/dired.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c
index 3770eb21472..3f18d785739 100644
--- a/usr.bin/mg/dired.c
+++ b/usr.bin/mg/dired.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dired.c,v 1.88 2019/06/27 16:13:01 lum Exp $ */
+/* $OpenBSD: dired.c,v 1.89 2019/06/27 16:55:08 lum Exp $ */
/* This file is in the public domain. */
@@ -484,6 +484,10 @@ d_copy(int f, int n)
topath = adjustname(toname, TRUE);
}
}
+ if (strcmp(frname, topath) == 0) {
+ ewprintf("Cannot copy to same file: %s", frname);
+ return (TRUE);
+ }
ret = (copy(frname, topath) >= 0) ? TRUE : FALSE;
if (ret != TRUE)
return (ret);
@@ -538,6 +542,10 @@ d_rename(int f, int n)
topath = adjustname(toname, TRUE);
}
}
+ if (strcmp(frname, topath) == 0) {
+ ewprintf("Cannot move to same file: %s", frname);
+ return (TRUE);
+ }
ret = (rename(frname, topath) >= 0) ? TRUE : FALSE;
if (ret != TRUE)
return (ret);