[PATCH 02/11] syscalls.cc: Deduplicate _remove_r

Ben Wijen ben@wijen.net
Fri Jan 15 13:45:25 GMT 2021


The _remove_r code is already in the remove function.
Therefore, just call the remove function and make
sure errno is set correctly in the reent struct.
---
 winsup/cygwin/syscalls.cc | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index ce4e9c65c..0e89b4f44 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -1133,18 +1133,15 @@ unlink (const char *ourname)
 }
 
 extern "C" int
-_remove_r (struct _reent *, const char *ourname)
+_remove_r (struct _reent *ptr, const char *ourname)
 {
-  path_conv win32_name (ourname, PC_SYM_NOFOLLOW);
+  int ret;
 
-  if (win32_name.error)
-    {
-      set_errno (win32_name.error);
-      syscall_printf ("%R = remove(%s)",-1, ourname);
-      return -1;
-    }
+  errno = 0;
+  if ((ret = remove (ourname)) == -1 && errno != 0)
+    ptr->_errno = errno;
 
-  return win32_name.isdir () ? rmdir (ourname) : unlink (ourname);
+  return ret;
 }
 
 extern "C" int
-- 
2.29.2



More information about the Cygwin-patches mailing list