]> sourceware.org Git - newlib-cygwin.git/commitdiff
* syscalls.cc (rename): Allocate temporary path buffers using
authorCorinna Vinschen <corinna@vinschen.de>
Mon, 19 May 2008 20:22:29 +0000 (20:22 +0000)
committerCorinna Vinschen <corinna@vinschen.de>
Mon, 19 May 2008 20:22:29 +0000 (20:22 +0000)
tmp_pathbuf.  Don't try to unset R/O attribute on dstpc if a
removepc exists.  dstpc is a non-existant file in that case.

winsup/cygwin/ChangeLog
winsup/cygwin/syscalls.cc

index 6cca20af2f462fe4f20c1200c814fb977962d9e7..90c031fccc0da4697058b7aceb4aadc4b45e5952 100644 (file)
@@ -1,3 +1,9 @@
+2008-05-19  Corinna Vinschen  <corinna@vinschen.de>
+
+       * syscalls.cc (rename): Allocate temporary path buffers using
+       tmp_pathbuf.  Don't try to unset R/O attribute on dstpc if a
+       removepc exists.  dstpc is a non-existant file in that case.
+
 2008-05-17  Christopher Faylor  <me+cygwin@cgf.cx>
 
        * include/stdint.h: Use int rather than long for {u,}int32_t.
index 4f35b6b69e0abdc0f514aa4d686a85e4796d8317..82f745bb8e2b7eaa7e988a80216c6c8577eb4072 100644 (file)
@@ -1494,6 +1494,7 @@ stop_transaction (NTSTATUS status, HANDLE old_trans, HANDLE trans)
 extern "C" int
 rename (const char *oldpath, const char *newpath)
 {
+  tmp_pathbuf tp;
   int res = -1;
   char *oldbuf, *newbuf;
   path_conv oldpc, newpc, new2pc, *dstpc, *removepc = NULL;
@@ -1533,7 +1534,7 @@ rename (const char *oldpath, const char *newpath)
   olen = strlen (oldpath);
   if (isdirsep (oldpath[olen - 1]))
     {
-      stpcpy (oldbuf = (char *) alloca (olen + 1), oldpath);
+      stpcpy (oldbuf = tp.c_get (), oldpath);
       while (olen > 0 && isdirsep (oldbuf[olen - 1]))
        oldbuf[--olen] = '\0';
       oldpath = oldbuf;
@@ -1568,7 +1569,7 @@ rename (const char *oldpath, const char *newpath)
   nlen = strlen (newpath);
   if (isdirsep (newpath[nlen - 1]))
     {
-      stpcpy (newbuf = (char *) alloca (nlen + 1), newpath);
+      stpcpy (newbuf = tp.c_get (), newpath);
       while (nlen > 0 && isdirsep (newbuf[nlen - 1]))
        newbuf[--nlen] = '\0';
       newpath = newbuf;
@@ -1746,8 +1747,10 @@ rename (const char *oldpath, const char *newpath)
        }
     }
   /* You can't copy a file if the destination exists and has the R/O
-     attribute set.  Remove the R/O attribute first. */
-  else if (dstpc->has_attribute (FILE_ATTRIBUTE_READONLY))
+     attribute set.  Remove the R/O attribute first.  But first check
+     if a removepc exists.  If so, dstpc points to a non-existing file
+     due to a mangled suffix. */
+  else if (!removepc && dstpc->has_attribute (FILE_ATTRIBUTE_READONLY))
     {
       status = NtOpenFile (&nfh, FILE_WRITE_ATTRIBUTES,
                           dstpc->get_object_attr (attr, sec_none_nih),
@@ -1814,7 +1817,10 @@ rename (const char *oldpath, const char *newpath)
     }
   size = sizeof (FILE_RENAME_INFORMATION)
         + dstpc->get_nt_native_path ()->Length;
-  pfri = (PFILE_RENAME_INFORMATION) alloca (size);
+  if (size > NT_MAX_PATH * sizeof (WCHAR)) /* Hopefully very seldom. */
+    pfri = (PFILE_RENAME_INFORMATION) alloca (size);
+  else
+    pfri = (PFILE_RENAME_INFORMATION) tp.w_get ();
   pfri->ReplaceIfExists = TRUE;
   pfri->RootDirectory = NULL;
   pfri->FileNameLength = dstpc->get_nt_native_path ()->Length;
This page took 0.037097 seconds and 5 git commands to generate.