+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.
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;
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;
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;
}
}
/* 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),
}
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;