comparison src/w32.c @ 15615:124e347ce827

(normalize_filename): Always lower-case drive letters, even on systems that preserve case in filenames. (sys_rename): Do not delete newname if only changing case. On Windows 95, use our version of mktemp (not the MSVC version) and give the temp name a long extension to ensure the final rename works as expected.
author Miles Bader <miles@gnu.org>
date Sun, 07 Jul 1996 01:59:24 +0000
parents 6344f92ddba2
children 481b7874a1e9
comparison
equal deleted inserted replaced
15614:6fb29f91d5ec 15615:124e347ce827
398 register char *fp; 398 register char *fp;
399 char path_sep; 399 char path_sep;
400 { 400 {
401 char sep; 401 char sep;
402 char *elem; 402 char *elem;
403
404 /* Always lower-case drive letters a-z, even if the filesystem
405 preserves case in filenames.
406 This is so filenames can be compared by string comparison
407 functions that are case-sensitive. Even case-preserving filesystems
408 do not distinguish case in drive letters. */
409 if (fp[1] == ':' && *fp >= 'A' && *fp <= 'Z')
410 {
411 *fp += 'a' - 'A';
412 fp += 2;
413 }
403 414
404 if (NILP (Vwin32_downcase_file_names)) 415 if (NILP (Vwin32_downcase_file_names))
405 { 416 {
406 while (*fp) 417 while (*fp)
407 { 418 {
1048 1059
1049 int 1060 int
1050 sys_rename (const char * oldname, const char * newname) 1061 sys_rename (const char * oldname, const char * newname)
1051 { 1062 {
1052 char temp[MAX_PATH]; 1063 char temp[MAX_PATH];
1064 DWORD attr;
1053 1065
1054 /* MoveFile on Win95 doesn't correctly change the short file name 1066 /* MoveFile on Win95 doesn't correctly change the short file name
1055 alias when oldname has a three char extension and newname has the 1067 alias in a number of circumstances (it is not easy to predict when
1056 same first three chars in its extension. To avoid problems, on 1068 just by looking at oldname and newname, unfortunately). In these
1057 Win95 we rename to a temporary name first. */ 1069 cases, renaming through a temporary name avoids the problem.
1070
1071 A second problem on Win95 is that renaming through a temp name when
1072 newname is uppercase fails (the final long name ends up in
1073 lowercase, although the short alias might be uppercase) UNLESS the
1074 long temp name is not 8.3.
1075
1076 So, on Win95 we always rename through a temp name, and we make sure
1077 the temp name has a long extension to ensure correct renaming. */
1058 1078
1059 strcpy (temp, map_win32_filename (oldname, NULL)); 1079 strcpy (temp, map_win32_filename (oldname, NULL));
1060 1080
1061 if (GetVersion () & 0x80000000) 1081 if (GetVersion () & 0x80000000)
1062 { 1082 {
1063 char * p; 1083 char * p;
1064 1084
1065 unixtodos_filename (temp);
1066 if (p = strrchr (temp, '\\')) 1085 if (p = strrchr (temp, '\\'))
1067 p++; 1086 p++;
1068 else 1087 else
1069 p = temp; 1088 p = temp;
1070 strcpy (p, "__XXXXXX"); 1089 strcpy (p, "__XXXXXX");
1071 _mktemp (temp); 1090 sys_mktemp (temp);
1091 /* Force temp name to require a manufactured 8.3 alias - this
1092 seems to make the second rename work properly. */
1093 strcat (temp, ".long");
1072 if (rename (map_win32_filename (oldname, NULL), temp) < 0) 1094 if (rename (map_win32_filename (oldname, NULL), temp) < 0)
1073 return -1; 1095 return -1;
1074 } 1096 }
1075 1097
1076 /* Emulate Unix behaviour - newname is deleted if it already exists 1098 /* Emulate Unix behaviour - newname is deleted if it already exists
1077 (at least if it is a file; don't do this for directories). */ 1099 (at least if it is a file; don't do this for directories).
1100 However, don't do this if we are just changing the case of the file
1101 name - we will end up deleting the file we are trying to rename! */
1078 newname = map_win32_filename (newname, NULL); 1102 newname = map_win32_filename (newname, NULL);
1079 if (GetFileAttributes (newname) != -1) 1103 if (stricmp (newname, temp) != 0
1104 && (attr = GetFileAttributes (newname)) != -1
1105 && (attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
1080 { 1106 {
1081 _chmod (newname, 0666); 1107 _chmod (newname, 0666);
1082 _unlink (newname); 1108 _unlink (newname);
1083 } 1109 }
1084 1110