Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2023-04-18 19:18:27 +0300
committerCorinna Vinschen <corinna@vinschen.de>2023-04-18 19:18:27 +0300
commitd30a5917a9c40aec18c2243dfc2848c616dca77a (patch)
tree7c667abc90801cf3cfddfa327b1d5733c8098388 /winsup/cygwin/syscalls.cc
parentfa84aa4dd2fb43eaf7fcdfb040aef854f2f19d01 (diff)
Cygwin: align renameat2 to Linux behaviour
In contrast to rename default behaviour, Linux' renameat2 returns -1 with errno set to EEXIST, if oldfile and newfile refer to the same file, and the RENAME_NOREPLACE flag is set. Follow suit, given this is a Linux-only function anyway. Fixes: f665b1cef30f ("cygwin: Implement renameat2") Reported-by: Bruno Haible <bruno@clisp.org> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/cygwin/syscalls.cc')
-rw-r--r--winsup/cygwin/syscalls.cc18
1 files changed, 13 insertions, 5 deletions
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index b10972056..73343ecc1 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -2108,6 +2108,14 @@ nt_path_has_executable_suffix (PUNICODE_STRING upath)
return false;
}
+inline int
+set_same_file_return (bool noreplace)
+{
+ if (!noreplace)
+ return 0;
+ set_errno (EEXIST);
+ return -1;
+}
/* If newpath names an existing file and the RENAME_NOREPLACE flag is
specified, fail with EEXIST. Exception: Don't fail if the purpose
of the rename is just to change the case of oldpath on a
@@ -2286,7 +2294,7 @@ rename2 (const char *oldpath, const char *newpath, unsigned int at2flags)
newpc.get_nt_native_path (),
FALSE))
{
- res = 0;
+ res = set_same_file_return (noreplace);
__leave;
}
newpc.file_attributes (INVALID_FILE_ATTRIBUTES);
@@ -2301,7 +2309,7 @@ rename2 (const char *oldpath, const char *newpath, unsigned int at2flags)
if (newpc.get_nt_native_path ()->Length
== oldpc.get_nt_native_path ()->Length)
{
- res = 0;
+ res = set_same_file_return (noreplace);
__leave;
}
if (*(PWCHAR) ((PBYTE) newpc.get_nt_native_path ()->Buffer
@@ -2321,7 +2329,7 @@ rename2 (const char *oldpath, const char *newpath, unsigned int at2flags)
newpc.get_nt_native_path (),
oldpc.objcaseinsensitive ()))
{
- res = 0;
+ res = set_same_file_return (noreplace);
__leave;
}
}
@@ -2350,7 +2358,7 @@ rename2 (const char *oldpath, const char *newpath, unsigned int at2flags)
newpc.get_nt_native_path (),
oldpc.objcaseinsensitive ()))
{
- res = 0;
+ res = set_same_file_return (noreplace);
__leave;
}
}
@@ -2571,7 +2579,7 @@ skip_pre_W10_checks:
{
debug_printf ("%s and %s are the same file", oldpath, newpath);
NtClose (nfh);
- res = 0;
+ res = set_same_file_return (noreplace);
__leave;
}
NtClose (nfh);