diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2023-04-18 18:18:27 +0200 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2023-04-18 18:18:39 +0200 |
commit | 7b3b2c201a271c5dcddcd3060f58d841478d47d9 (patch) | |
tree | 973ec85c6410fea0c1a5117f444b7e298d111593 | |
parent | 4b8222983f914a7950987802e73fc069dffc3058 (diff) | |
download | newlib-7b3b2c201a271c5dcddcd3060f58d841478d47d9.zip newlib-7b3b2c201a271c5dcddcd3060f58d841478d47d9.tar.gz newlib-7b3b2c201a271c5dcddcd3060f58d841478d47d9.tar.bz2 |
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>
-rw-r--r-- | winsup/cygwin/release/3.4.7 | 4 | ||||
-rw-r--r-- | winsup/cygwin/syscalls.cc | 18 |
2 files changed, 17 insertions, 5 deletions
diff --git a/winsup/cygwin/release/3.4.7 b/winsup/cygwin/release/3.4.7 index 7bc7d4a..0e69221 100644 --- a/winsup/cygwin/release/3.4.7 +++ b/winsup/cygwin/release/3.4.7 @@ -21,3 +21,7 @@ Bug Fixes - Fix error handling in readlinkat. Addresses: https://cygwin.com/pipermail/cygwin/2023-April/253510.html + +- Fix return code and errno set by renameat2, if oldfile and newfile + refer to the same file, and the RENAME_NOREPLACE flag is set. + Addresses: https://cygwin.com/pipermail/cygwin/2023-April/253514.html diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index a4e4af6..5adc614 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -2122,6 +2122,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 @@ -2300,7 +2308,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); @@ -2315,7 +2323,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 @@ -2335,7 +2343,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; } } @@ -2364,7 +2372,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; } } @@ -2582,7 +2590,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); |