aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeoff Voelker1998-05-30 23:41:57 +0000
committerGeoff Voelker1998-05-30 23:41:57 +0000
commiteb9ea53f9cc5d63dc74dd837e56ef46b4a26504d (patch)
tree1216aa1c8a90385b2cee372b8e6c57fda3269fa3
parenta5b56dcda17f619180f2d05c8b3e3062bb329a69 (diff)
downloademacs-eb9ea53f9cc5d63dc74dd837e56ef46b4a26504d.tar.gz
emacs-eb9ea53f9cc5d63dc74dd837e56ef46b4a26504d.zip
(sys_rename): Handle filenames with accented characters.
(stat): Handle "c:/.." and "/.." specially.
-rw-r--r--src/w32.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/w32.c b/src/w32.c
index eaf0a6c3d18..7bd8a00a4ad 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -1446,6 +1446,7 @@ sys_rename (const char * oldname, const char * newname)
1446{ 1446{
1447 char temp[MAX_PATH]; 1447 char temp[MAX_PATH];
1448 DWORD attr; 1448 DWORD attr;
1449 int result;
1449 1450
1450 /* MoveFile on Windows 95 doesn't correctly change the short file name 1451 /* MoveFile on Windows 95 doesn't correctly change the short file name
1451 alias in a number of circumstances (it is not easy to predict when 1452 alias in a number of circumstances (it is not easy to predict when
@@ -1484,9 +1485,13 @@ sys_rename (const char * oldname, const char * newname)
1484 name - we will end up deleting the file we are trying to rename! */ 1485 name - we will end up deleting the file we are trying to rename! */
1485 newname = map_w32_filename (newname, NULL); 1486 newname = map_w32_filename (newname, NULL);
1486 1487
1487 /* TODO: Use GetInformationByHandle (on NT) to ensure newname and temp 1488 /* Suggested by Pekka Pirila <pekka.pirila@vtt.fi>: stricmp does not
1488 do not refer to the same file, eg. through share aliases. */ 1489 handle accented characters correctly, so comparing filenames will
1489 if (stricmp (newname, temp) != 0 1490 accidentally delete these files. Instead, do the rename first;
1491 newname will not be deleted if successful or if errno == EACCES.
1492 In this case, delete the file explicitly. */
1493 result = rename (temp, newname);
1494 if (result < 0 && errno == EACCES
1490 && (attr = GetFileAttributes (newname)) != -1 1495 && (attr = GetFileAttributes (newname)) != -1
1491 && (attr & FILE_ATTRIBUTE_DIRECTORY) == 0) 1496 && (attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
1492 { 1497 {
@@ -1494,7 +1499,7 @@ sys_rename (const char * oldname, const char * newname)
1494 _unlink (newname); 1499 _unlink (newname);
1495 } 1500 }
1496 1501
1497 return rename (temp, newname); 1502 return result;
1498} 1503}
1499 1504
1500int 1505int
@@ -1628,7 +1633,7 @@ generate_inode_val (const char * name)
1628int 1633int
1629stat (const char * path, struct stat * buf) 1634stat (const char * path, struct stat * buf)
1630{ 1635{
1631 char * name; 1636 char *name, *r;
1632 WIN32_FIND_DATA wfd; 1637 WIN32_FIND_DATA wfd;
1633 HANDLE fh; 1638 HANDLE fh;
1634 DWORD fake_inode; 1639 DWORD fake_inode;
@@ -1650,6 +1655,13 @@ stat (const char * path, struct stat * buf)
1650 return -1; 1655 return -1;
1651 } 1656 }
1652 1657
1658 /* If name is "c:/.." or "/.." then stat "c:/" or "/". */
1659 r = IS_DEVICE_SEP (name[1]) ? &name[2] : name;
1660 if (IS_DIRECTORY_SEP (r[0]) && r[1] == '.' && r[2] == '.' && r[3] == '\0')
1661 {
1662 r[1] = r[2] = '\0';
1663 }
1664
1653 /* Remove trailing directory separator, unless name is the root 1665 /* Remove trailing directory separator, unless name is the root
1654 directory of a drive or UNC volume in which case ensure there 1666 directory of a drive or UNC volume in which case ensure there
1655 is a trailing separator. */ 1667 is a trailing separator. */