aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1994-11-01 08:16:31 +0000
committerRichard M. Stallman1994-11-01 08:16:31 +0000
commit5e570b758548713c1b189f180e829f0b474fdf66 (patch)
tree6b6f2aad6c969c6e9e65ca5865a49dace28c8695 /src
parentcc5f52cbfa696dc1557f28b3c32f199f4620af62 (diff)
downloademacs-5e570b758548713c1b189f180e829f0b474fdf66.tar.gz
emacs-5e570b758548713c1b189f180e829f0b474fdf66.zip
Change explicit uses of the Unix directory separator
/' to uses of the macros IS_ANY_SEP, IS_DIRECTORY_SEP, S_DEVICE_SEP, DIRECTORY_SEP, and DEVICE_SEP. [WINDOWSNT]: Don't define HAVE_FSYNC; add includes for NT. (Ffile_name_absolute_p): Test DOS_NT instead of MSDOS. (Fwrite_region, Fdo_auto_save, Ffile_modes): Likewise. (Qfind_buffer_file_type): Test DOS_NT instead of MSDOS. (syms_of_files): Likewise. (Finsert_file_types): Test DOS_NT instead of MSDOS. Rename local var try to trytry. (Fadd_name_to_file): Wlways fail. (Frename_file) [WINDOWSNT]: Use MoveFile, not link and unlink, and check for both ERROR_FILE_EXISTS and ERROR_ALREADY_EXISTS. (Fmake_directory_internal) [WINDOWSNT]: Invoke mkdir without the mask. (Fexpand_file_name): Test DOS_NT, not MSDOS. (Fexpand_file_name) [WINDOWSNT]: Accept // or \\ at start. Call dostonunix_filename for HOME envvar, for ~USER. Quote directory separators found in environment variables. (Fsubstitute_in_file_name): Test DOS_NT instead of MSDOS. (Fsubstitute_in_file_name) [WINDOWSNT]: Accept // or \\ at start. Work around alloca bug in MS compiler. (Ffile_name_directory): Test DOS_NT instead of MSDOS sometimes. But don't insert a drive letter on windows.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c355
1 files changed, 218 insertions, 137 deletions
diff --git a/src/fileio.c b/src/fileio.c
index a7fe29e174b..1667b60628c 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -69,16 +69,25 @@ extern char *strerror ();
69#ifndef USG 69#ifndef USG
70#ifndef VMS 70#ifndef VMS
71#ifndef BSD4_1 71#ifndef BSD4_1
72#ifndef WINDOWSNT
72#define HAVE_FSYNC 73#define HAVE_FSYNC
73#endif 74#endif
74#endif 75#endif
75#endif 76#endif
77#endif
76 78
77#include "lisp.h" 79#include "lisp.h"
78#include "intervals.h" 80#include "intervals.h"
79#include "buffer.h" 81#include "buffer.h"
80#include "window.h" 82#include "window.h"
81 83
84#ifdef WINDOWSNT
85#define NOMINMAX 1
86#include <windows.h>
87#include <stdlib.h>
88#include <fcntl.h>
89#endif /* not WINDOWSNT */
90
82#ifdef VMS 91#ifdef VMS
83#include <file.h> 92#include <file.h>
84#include <rmsdef.h> 93#include <rmsdef.h>
@@ -292,7 +301,7 @@ on VMS, perhaps instead a string ending in `:', `]' or `>'.")
292 beg = XSTRING (file)->data; 301 beg = XSTRING (file)->data;
293 p = beg + XSTRING (file)->size; 302 p = beg + XSTRING (file)->size;
294 303
295 while (p != beg && p[-1] != '/' 304 while (p != beg && !IS_ANY_SEP (p[-1])
296#ifdef VMS 305#ifdef VMS
297 && p[-1] != ':' && p[-1] != ']' && p[-1] != '>' 306 && p[-1] != ':' && p[-1] != ']' && p[-1] != '>'
298#endif /* VMS */ 307#endif /* VMS */
@@ -303,24 +312,35 @@ on VMS, perhaps instead a string ending in `:', `]' or `>'.")
303 312
304 if (p == beg) 313 if (p == beg)
305 return Qnil; 314 return Qnil;
306#ifdef MSDOS 315#ifdef DOS_NT
307 /* Expansion of "c:" to drive and default directory. */ 316 /* Expansion of "c:" to drive and default directory. */
317 /* (NT does the right thing.) */
308 if (p == beg + 2 && beg[1] == ':') 318 if (p == beg + 2 && beg[1] == ':')
309 { 319 {
310 int drive = (*beg) - 'a'; 320 int drive = (*beg) - 'a';
311 /* MAXPATHLEN+1 is guaranteed to be enough space for getdefdir. */ 321 /* MAXPATHLEN+1 is guaranteed to be enough space for getdefdir. */
312 unsigned char *res = alloca (MAXPATHLEN + 5); 322 unsigned char *res = alloca (MAXPATHLEN + 5);
313 if (getdefdir (drive + 1, res + 2)) 323 unsigned char *res1;
324#ifdef WINDOWSNT
325 res1 = res;
326 /* The NT version places the drive letter at the beginning already. */
327#else /* not WINDOWSNT */
328 /* On MSDOG we must put the drive letter in by hand. */
329 res1 = res + 2;
330#endif /* not WINDOWSNT */
331 if (getdefdir (drive + 1, res))
314 { 332 {
333#ifdef MSDOS
315 res[0] = drive + 'a'; 334 res[0] = drive + 'a';
316 res[1] = ':'; 335 res[1] = ':';
317 if (res[strlen (res) - 1] != '/') 336#endif /* MSDOS */
337 if (IS_DIRECTORY_SEP (res[strlen (res) - 1]))
318 strcat (res, "/"); 338 strcat (res, "/");
319 beg = res; 339 beg = res;
320 p = beg + strlen (beg); 340 p = beg + strlen (beg);
321 } 341 }
322 } 342 }
323#endif 343#endif /* DOS_NT */
324 return make_string (beg, p - beg); 344 return make_string (beg, p - beg);
325} 345}
326 346
@@ -347,12 +367,12 @@ or the entire name if it contains no slash.")
347 beg = XSTRING (file)->data; 367 beg = XSTRING (file)->data;
348 end = p = beg + XSTRING (file)->size; 368 end = p = beg + XSTRING (file)->size;
349 369
350 while (p != beg && p[-1] != '/' 370 while (p != beg && !IS_ANY_SEP (p[-1])
351#ifdef VMS 371#ifdef VMS
352 && p[-1] != ':' && p[-1] != ']' && p[-1] != '>' 372 && p[-1] != ':' && p[-1] != ']' && p[-1] != '>'
353#endif /* VMS */ 373#endif /* VMS */
354#ifdef MSDOS 374#ifdef MSDOS
355 && p[-1] != ':' && p[-1] != '\\' 375 && p[-1] != ':'
356#endif 376#endif
357 ) p--; 377 ) p--;
358 378
@@ -451,10 +471,13 @@ file_name_as_directory (out, in)
451 /* For Unix syntax, Append a slash if necessary */ 471 /* For Unix syntax, Append a slash if necessary */
452#ifdef MSDOS 472#ifdef MSDOS
453 if (out[size] != ':' && out[size] != '/' && out[size] != '\\') 473 if (out[size] != ':' && out[size] != '/' && out[size] != '\\')
454#else 474#else /* not MSDOS */
455 if (out[size] != '/') 475 if (!IS_ANY_SEP (out[size]))
456#endif 476 {
457 strcat (out, "/"); 477 out[size + 1] = DIRECTORY_SEP;
478 out[size + 2] = '\0';
479 }
480#endif /* not MSDOS */
458#endif /* not VMS */ 481#endif /* not VMS */
459 return out; 482 return out;
460} 483}
@@ -541,7 +564,7 @@ directory_file_name (src, dst)
541 { 564 {
542 /* what about when we have logical_name:???? */ 565 /* what about when we have logical_name:???? */
543 if (src[slen - 1] == ':') 566 if (src[slen - 1] == ':')
544 { /* Xlate logical name and see what we get */ 567 { /* Xlate logical name and see what we get */
545 ptr = strcpy (dst, src); /* upper case for getenv */ 568 ptr = strcpy (dst, src); /* upper case for getenv */
546 while (*ptr) 569 while (*ptr)
547 { 570 {
@@ -549,7 +572,7 @@ directory_file_name (src, dst)
549 *ptr -= 040; 572 *ptr -= 040;
550 ptr++; 573 ptr++;
551 } 574 }
552 dst[slen - 1] = 0; /* remove colon */ 575 dst[slen - 1] = 0; /* remove colon */
553 if (!(src = egetenv (dst))) 576 if (!(src = egetenv (dst)))
554 return 0; 577 return 0;
555 /* should we jump to the beginning of this procedure? 578 /* should we jump to the beginning of this procedure?
@@ -567,7 +590,7 @@ directory_file_name (src, dst)
567 } 590 }
568 } 591 }
569 else 592 else
570 { /* not a directory spec */ 593 { /* not a directory spec */
571 strcpy (dst, src); 594 strcpy (dst, src);
572 return 0; 595 return 0;
573 } 596 }
@@ -597,7 +620,7 @@ directory_file_name (src, dst)
597 /* If we have the top-level of a rooted directory (i.e. xx:[000000]), 620 /* If we have the top-level of a rooted directory (i.e. xx:[000000]),
598 then translate the device and recurse. */ 621 then translate the device and recurse. */
599 if (dst[slen - 1] == ':' 622 if (dst[slen - 1] == ':'
600 && dst[slen - 2] != ':' /* skip decnet nodes */ 623 && dst[slen - 2] != ':' /* skip decnet nodes */
601 && strcmp(src + slen, "[000000]") == 0) 624 && strcmp(src + slen, "[000000]") == 0)
602 { 625 {
603 dst[slen - 1] = '\0'; 626 dst[slen - 1] = '\0';
@@ -630,13 +653,8 @@ directory_file_name (src, dst)
630 But leave "/" unchanged; do not change it to "". */ 653 But leave "/" unchanged; do not change it to "". */
631 strcpy (dst, src); 654 strcpy (dst, src);
632 if (slen > 1 655 if (slen > 1
633#ifdef MSDOS 656 && IS_DIRECTORY_SEP (dst[slen - 1])
634 && (dst[slen - 1] == '/' || dst[slen - 1] == '/') 657 && !IS_DEVICE_SEP (dst[slen - 2]))
635 && dst[slen - 2] != ':'
636#else
637 && dst[slen - 1] == '/'
638#endif
639 )
640 dst[slen - 1] = 0; 658 dst[slen - 1] = 0;
641 return 1; 659 return 1;
642} 660}
@@ -721,11 +739,12 @@ See also the function `substitute-in-file-name'.")
721 int lbrack = 0, rbrack = 0; 739 int lbrack = 0, rbrack = 0;
722 int dots = 0; 740 int dots = 0;
723#endif /* VMS */ 741#endif /* VMS */
724#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */ 742#ifdef DOS_NT
743 /* Demacs 1.1.2 91/10/20 Manabu Higashida */
725 int drive = -1; 744 int drive = -1;
726 int relpath = 0; 745 int relpath = 0;
727 unsigned char *tmp, *defdir; 746 unsigned char *tmp, *defdir;
728#endif 747#endif /* DOS_NT */
729 Lisp_Object handler; 748 Lisp_Object handler;
730 749
731 CHECK_STRING (name, 0); 750 CHECK_STRING (name, 0);
@@ -741,6 +760,8 @@ See also the function `substitute-in-file-name'.")
741 defalt = current_buffer->directory; 760 defalt = current_buffer->directory;
742 CHECK_STRING (defalt, 1); 761 CHECK_STRING (defalt, 1);
743 762
763 o = XSTRING (defalt)->data;
764
744 /* Make sure DEFALT is properly expanded. 765 /* Make sure DEFALT is properly expanded.
745 It would be better to do this down below where we actually use 766 It would be better to do this down below where we actually use
746 defalt. Unfortunately, calling Fexpand_file_name recursively 767 defalt. Unfortunately, calling Fexpand_file_name recursively
@@ -753,13 +774,9 @@ See also the function `substitute-in-file-name'.")
753 The EQ test avoids infinite recursion. */ 774 The EQ test avoids infinite recursion. */
754 if (! NILP (defalt) && !EQ (defalt, name) 775 if (! NILP (defalt) && !EQ (defalt, name)
755 /* This saves time in a common case. */ 776 /* This saves time in a common case. */
756#ifdef MSDOS 777 && ! (XSTRING (defalt)->size >= 3
757 && (XSTRING (defalt)->size < 3 778 && IS_DIRECTORY_SEP (XSTRING (defalt)->data[0])
758 || XSTRING (defalt)->data[1] != ':' 779 && IS_DEVICE_SEP (XSTRING (defalt)->data[1])))
759 || XSTRING (defalt)->data[2] != '/'))
760#else
761 && XSTRING (defalt)->data[0] != '/')
762#endif
763 { 780 {
764 struct gcpro gcpro1; 781 struct gcpro gcpro1;
765 782
@@ -781,7 +798,9 @@ See also the function `substitute-in-file-name'.")
781#ifdef MSDOS 798#ifdef MSDOS
782 /* First map all backslashes to slashes. */ 799 /* First map all backslashes to slashes. */
783 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm)); 800 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm));
801#endif
784 802
803#ifdef DOS_NT
785 /* Now strip drive name. */ 804 /* Now strip drive name. */
786 { 805 {
787 unsigned char *colon = rindex (nm, ':'); 806 unsigned char *colon = rindex (nm, ':');
@@ -792,19 +811,19 @@ See also the function `substitute-in-file-name'.")
792 { 811 {
793 drive = tolower (colon[-1]) - 'a'; 812 drive = tolower (colon[-1]) - 'a';
794 nm = colon + 1; 813 nm = colon + 1;
795 if (*nm != '/') 814 if (!IS_DIRECTORY_SEP (*nm))
796 { 815 {
797 defdir = alloca (MAXPATHLEN + 1); 816 defdir = alloca (MAXPATHLEN + 1);
798 relpath = getdefdir (drive + 1, defdir); 817 relpath = getdefdir (drive + 1, defdir);
799 } 818 }
800 } 819 }
801 } 820 }
802#endif 821#endif /* DOS_NT */
803 822
804 /* If nm is absolute, flush ...// and detect /./ and /../. 823 /* If nm is absolute, flush ...// and detect /./ and /../.
805 If no /./ or /../ we can return right away. */ 824 If no /./ or /../ we can return right away. */
806 if ( 825 if (
807 nm[0] == '/' 826 IS_DIRECTORY_SEP (nm[0])
808#ifdef VMS 827#ifdef VMS
809 || index (nm, ':') 828 || index (nm, ':')
810#endif /* VMS */ 829#endif /* VMS */
@@ -826,24 +845,28 @@ See also the function `substitute-in-file-name'.")
826 845
827 /* "//" anywhere isn't necessarily hairy; we just start afresh 846 /* "//" anywhere isn't necessarily hairy; we just start afresh
828 with the second slash. */ 847 with the second slash. */
829 if (p[0] == '/' && p[1] == '/' 848 if (IS_DIRECTORY_SEP (p[0]) && IS_DIRECTORY_SEP (p[1])
830#ifdef APOLLO 849#ifdef APOLLO
831 /* // at start of filename is meaningful on Apollo system */ 850 /* // at start of filename is meaningful on Apollo system */
832 && nm != p 851 && nm != p
833#endif /* APOLLO */ 852#endif /* APOLLO */
853#ifdef WINDOWSNT
854 /* \\ or // at the start of a pathname is meaningful on NT. */
855 && nm != p
856#endif /* WINDOWSNT */
834 ) 857 )
835 nm = p + 1; 858 nm = p + 1;
836 859
837 /* "~" is hairy as the start of any path element. */ 860 /* "~" is hairy as the start of any path element. */
838 if (p[0] == '/' && p[1] == '~') 861 if (IS_DIRECTORY_SEP (p[0]) && p[1] == '~')
839 nm = p + 1, lose = 1; 862 nm = p + 1, lose = 1;
840 863
841 /* "." and ".." are hairy. */ 864 /* "." and ".." are hairy. */
842 if (p[0] == '/' 865 if (IS_DIRECTORY_SEP (p[0])
843 && p[1] == '.' 866 && p[1] == '.'
844 && (p[2] == '/' 867 && (IS_DIRECTORY_SEP (p[2])
845 || p[2] == 0 868 || p[2] == 0
846 || (p[2] == '.' && (p[3] == '/' 869 || (p[2] == '.' && (IS_DIRECTORY_SEP (p[3])
847 || p[3] == 0)))) 870 || p[3] == 0))))
848 lose = 1; 871 lose = 1;
849#ifdef VMS 872#ifdef VMS
@@ -864,7 +887,7 @@ See also the function `substitute-in-file-name'.")
864 /* VMS pre V4.4,convert '-'s in filenames. */ 887 /* VMS pre V4.4,convert '-'s in filenames. */
865 if (lbrack == rbrack) 888 if (lbrack == rbrack)
866 { 889 {
867 if (dots < 2) /* this is to allow negative version numbers */ 890 if (dots < 2) /* this is to allow negative version numbers */
868 p[0] = '_'; 891 p[0] = '_';
869 } 892 }
870 else 893 else
@@ -927,11 +950,11 @@ See also the function `substitute-in-file-name'.")
927 if (index (nm, '/')) 950 if (index (nm, '/'))
928 return build_string (sys_translate_unix (nm)); 951 return build_string (sys_translate_unix (nm));
929#endif /* VMS */ 952#endif /* VMS */
930#ifndef MSDOS 953#ifndef DOS_NT
931 if (nm == XSTRING (name)->data) 954 if (nm == XSTRING (name)->data)
932 return name; 955 return name;
933 return build_string (nm); 956 return build_string (nm);
934#endif 957#endif /* not DOS_NT */
935 } 958 }
936 } 959 }
937 960
@@ -941,33 +964,37 @@ See also the function `substitute-in-file-name'.")
941 964
942 if (nm[0] == '~') /* prefix ~ */ 965 if (nm[0] == '~') /* prefix ~ */
943 { 966 {
944 if (nm[1] == '/' 967 if (IS_DIRECTORY_SEP (nm[1])
945#ifdef VMS 968#ifdef VMS
946 || nm[1] == ':' 969 || nm[1] == ':'
947#endif /* VMS */ 970#endif /* VMS */
948 || nm[1] == 0) /* ~ by itself */ 971 || nm[1] == 0) /* ~ by itself */
949 { 972 {
950 if (!(newdir = (unsigned char *) egetenv ("HOME"))) 973 if (!(newdir = (unsigned char *) egetenv ("HOME")))
951 newdir = (unsigned char *) ""; 974 newdir = (unsigned char *) "";
952#ifdef MSDOS 975#ifdef DOS_NT
953 dostounix_filename (newdir); 976 dostounix_filename (newdir);
954#endif 977#endif
955 nm++; 978 nm++;
956#ifdef VMS 979#ifdef VMS
957 nm++; /* Don't leave the slash in nm. */ 980 nm++; /* Don't leave the slash in nm. */
958#endif /* VMS */ 981#endif /* VMS */
959 } 982 }
960 else /* ~user/filename */ 983 else /* ~user/filename */
961 { 984 {
962 for (p = nm; *p && (*p != '/' 985 for (p = nm; *p && (!IS_DIRECTORY_SEP (*p)
963#ifdef VMS 986#ifdef VMS
964 && *p != ':' 987 && *p != ':'
965#endif /* VMS */ 988#endif /* VMS */
966 ); p++); 989 ); p++);
967 o = (unsigned char *) alloca (p - nm + 1); 990 o = (unsigned char *) alloca (p - nm + 1);
968 bcopy ((char *) nm, o, p - nm); 991 bcopy ((char *) nm, o, p - nm);
969 o [p - nm] = 0; 992 o [p - nm] = 0;
970 993
994#ifdef WINDOWSNT
995 newdir = (unsigned char *) egetenv ("HOME");
996 dostounix_filename (newdir);
997#else /* not WINDOWSNT */
971 pw = (struct passwd *) getpwnam (o + 1); 998 pw = (struct passwd *) getpwnam (o + 1);
972 if (pw) 999 if (pw)
973 { 1000 {
@@ -976,30 +1003,31 @@ See also the function `substitute-in-file-name'.")
976 nm = p + 1; /* skip the terminator */ 1003 nm = p + 1; /* skip the terminator */
977#else 1004#else
978 nm = p; 1005 nm = p;
979#endif /* VMS */ 1006#endif /* VMS */
980 } 1007 }
1008#endif /* not WINDOWSNT */
981 1009
982 /* If we don't find a user of that name, leave the name 1010 /* If we don't find a user of that name, leave the name
983 unchanged; don't move nm forward to p. */ 1011 unchanged; don't move nm forward to p. */
984 } 1012 }
985 } 1013 }
986 1014
987 if (nm[0] != '/' 1015 if (!IS_ANY_SEP (nm[0])
988#ifdef VMS 1016#ifdef VMS
989 && !index (nm, ':') 1017 && !index (nm, ':')
990#endif /* not VMS */ 1018#endif /* not VMS */
991#ifdef MSDOS 1019#ifdef DOS_NT
992 && drive == -1 1020 && drive == -1
993#endif 1021#endif /* DOS_NT */
994 && !newdir) 1022 && !newdir)
995 { 1023 {
996 newdir = XSTRING (defalt)->data; 1024 newdir = XSTRING (defalt)->data;
997 } 1025 }
998 1026
999#ifdef MSDOS 1027#ifdef DOS_NT
1000 if (newdir == 0 && relpath) 1028 if (newdir == 0 && relpath)
1001 newdir = defdir; 1029 newdir = defdir;
1002#endif 1030#endif /* DOS_NT */
1003 if (newdir != 0) 1031 if (newdir != 0)
1004 { 1032 {
1005 /* Get rid of any slash at the end of newdir. */ 1033 /* Get rid of any slash at the end of newdir. */
@@ -1010,7 +1038,7 @@ See also the function `substitute-in-file-name'.")
1010#ifdef MSDOS 1038#ifdef MSDOS
1011 if (newdir[1] != ':' && length > 1) 1039 if (newdir[1] != ':' && length > 1)
1012#endif 1040#endif
1013 if (newdir[length - 1] == '/') 1041 if (IS_DIRECTORY_SEP (newdir[length - 1]))
1014 { 1042 {
1015 unsigned char *temp = (unsigned char *) alloca (length); 1043 unsigned char *temp = (unsigned char *) alloca (length);
1016 bcopy (newdir, temp, length - 1); 1044 bcopy (newdir, temp, length - 1);
@@ -1024,18 +1052,20 @@ See also the function `substitute-in-file-name'.")
1024 1052
1025 /* Now concatenate the directory and name to new space in the stack frame */ 1053 /* Now concatenate the directory and name to new space in the stack frame */
1026 tlen += strlen (nm) + 1; 1054 tlen += strlen (nm) + 1;
1027#ifdef MSDOS 1055#ifdef DOS_NT
1028 /* Add reserved space for drive name. */ 1056 /* Add reserved space for drive name. (The Microsoft x86 compiler
1029 target = (unsigned char *) alloca (tlen + 2) + 2; 1057 produces incorrect code if the following two lines are combined.) */
1030#else 1058 target = (unsigned char *) alloca (tlen + 2);
1059 target += 2;
1060#else /* not DOS_NT */
1031 target = (unsigned char *) alloca (tlen); 1061 target = (unsigned char *) alloca (tlen);
1032#endif 1062#endif /* not DOS_NT */
1033 *target = 0; 1063 *target = 0;
1034 1064
1035 if (newdir) 1065 if (newdir)
1036 { 1066 {
1037#ifndef VMS 1067#ifndef VMS
1038 if (nm[0] == 0 || nm[0] == '/') 1068 if (nm[0] == 0 || IS_DIRECTORY_SEP (nm[0]))
1039 strcpy (target, newdir); 1069 strcpy (target, newdir);
1040 else 1070 else
1041#endif 1071#endif
@@ -1080,7 +1110,7 @@ See also the function `substitute-in-file-name'.")
1080 do 1110 do
1081 o--; 1111 o--;
1082 while (o[-1] != '.' && o[-1] != '[' && o[-1] != '<'); 1112 while (o[-1] != '.' && o[-1] != '[' && o[-1] != '<');
1083 if (p[1] == '.') /* foo.-.bar ==> bar*/ 1113 if (p[1] == '.') /* foo.-.bar ==> bar. */
1084 p += 2; 1114 p += 2;
1085 else if (o[-1] == '.') /* '.foo.-]' ==> ']' */ 1115 else if (o[-1] == '.') /* '.foo.-]' ==> ']' */
1086 p++, o--; 1116 p++, o--;
@@ -1097,23 +1127,31 @@ See also the function `substitute-in-file-name'.")
1097 *o++ = *p++; 1127 *o++ = *p++;
1098 } 1128 }
1099#else /* not VMS */ 1129#else /* not VMS */
1100 if (*p != '/') 1130 if (!IS_DIRECTORY_SEP (*p))
1101 { 1131 {
1102 *o++ = *p++; 1132 *o++ = *p++;
1103 } 1133 }
1134#ifdef WINDOWSNT
1135 else if (!strncmp (p, "\\\\", 2) || !strncmp (p, "//", 2))
1136#else /* not WINDOWSNT */
1104 else if (!strncmp (p, "//", 2) 1137 else if (!strncmp (p, "//", 2)
1138#endif /* not WINDOWSNT */
1105#ifdef APOLLO 1139#ifdef APOLLO
1106 /* // at start of filename is meaningful in Apollo system */ 1140 /* // at start of filename is meaningful in Apollo system */
1107 && o != target 1141 && o != target
1108#endif /* APOLLO */ 1142#endif /* APOLLO */
1143#ifdef WINDOWSNT
1144 /* \\ at start of filename is meaningful in Windows-NT */
1145 && o != target
1146#endif /* WINDOWSNT */
1109 ) 1147 )
1110 { 1148 {
1111 o = target; 1149 o = target;
1112 p++; 1150 p++;
1113 } 1151 }
1114 else if (p[0] == '/' 1152 else if (IS_DIRECTORY_SEP (p[0])
1115 && p[1] == '.' 1153 && p[1] == '.'
1116 && (p[2] == '/' 1154 && (IS_DIRECTORY_SEP (p[2])
1117 || p[2] == 0)) 1155 || p[2] == 0))
1118 { 1156 {
1119 /* If "/." is the entire filename, keep the "/". Otherwise, 1157 /* If "/." is the entire filename, keep the "/". Otherwise,
@@ -1122,43 +1160,59 @@ See also the function `substitute-in-file-name'.")
1122 *o++ = *p; 1160 *o++ = *p;
1123 p += 2; 1161 p += 2;
1124 } 1162 }
1163#ifdef WINDOWSNT
1164 else if (!strncmp (p, "\\..", 3) || !strncmp (p, "/..", 3))
1165#else /* not WINDOWSNT */
1125 else if (!strncmp (p, "/..", 3) 1166 else if (!strncmp (p, "/..", 3)
1167#endif /* not WINDOWSNT */
1126 /* `/../' is the "superroot" on certain file systems. */ 1168 /* `/../' is the "superroot" on certain file systems. */
1127 && o != target 1169 && o != target
1128 && (p[3] == '/' || p[3] == 0)) 1170 && (IS_DIRECTORY_SEP (p[3]) || p[3] == 0))
1129 { 1171 {
1130 while (o != target && *--o != '/') 1172 while (o != target && (--o) && !IS_DIRECTORY_SEP (*o))
1131 ; 1173 ;
1132#ifdef APOLLO 1174#ifdef APOLLO
1133 if (o == target + 1 && o[-1] == '/' && o[0] == '/') 1175 if (o == target + 1 && o[-1] == '/' && o[0] == '/')
1134 ++o; 1176 ++o;
1135 else 1177 else
1136#endif /* APOLLO */ 1178#endif /* APOLLO */
1137 if (o == target && *o == '/') 1179#ifdef WINDOWSNT
1180 if (o == target + 1 && (o[-1] == '/' && o[0] == '/')
1181 || (o[-1] == '\\' && o[0] == '\\'))
1182 ++o;
1183 else
1184#endif /* WINDOWSNT */
1185 if (o == target && IS_ANY_SEP (*o))
1138 ++o; 1186 ++o;
1139 p += 3; 1187 p += 3;
1140 } 1188 }
1141 else 1189 else
1142 { 1190 {
1143 *o++ = *p++; 1191 *o++ = *p++;
1144 } 1192 }
1145#endif /* not VMS */ 1193#endif /* not VMS */
1146 } 1194 }
1147 1195
1148#ifdef MSDOS 1196#ifdef DOS_NT
1149 /* at last, set drive name. */ 1197 /* at last, set drive name. */
1150 if (target[1] != ':') 1198 if (target[1] != ':'
1199#ifdef WINDOWSNT
1200 /* Allow network paths that look like "\\foo" */
1201 && !(IS_DIRECTORY_SEP (target[0]) && IS_DIRECTORY_SEP (target[1]))
1202#endif /* WINDOWSNT */
1203 )
1151 { 1204 {
1152 target -= 2; 1205 target -= 2;
1153 target[0] = (drive < 0 ? getdisk () : drive) + 'a'; 1206 target[0] = (drive < 0 ? getdisk () : drive) + 'a';
1154 target[1] = ':'; 1207 target[1] = ':';
1155 } 1208 }
1156#endif 1209#endif /* DOS_NT */
1157 1210
1158 return make_string (target, o - target); 1211 return make_string (target, o - target);
1159} 1212}
1213
1160#if 0 1214#if 0
1161/* Changed this DEFUN to a DEAFUN, so as not to confuse `make-docfile'. 1215/* Changed this DEFUN to a DEAFUN, so as not to confuse `make-docfile'. */
1162DEAFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0, 1216DEAFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0,
1163 "Convert FILENAME to absolute, and canonicalize it.\n\ 1217 "Convert FILENAME to absolute, and canonicalize it.\n\
1164Second arg DEFAULT is directory to start with if FILENAME is relative\n\ 1218Second arg DEFAULT is directory to start with if FILENAME is relative\n\
@@ -1239,7 +1293,7 @@ See also the function `substitute-in-file-name'.")
1239 /* VMS pre V4.4,convert '-'s in filenames. */ 1293 /* VMS pre V4.4,convert '-'s in filenames. */
1240 if (lbrack == rbrack) 1294 if (lbrack == rbrack)
1241 { 1295 {
1242 if (dots < 2) /* this is to allow negative version numbers */ 1296 if (dots < 2) /* this is to allow negative version numbers */
1243 p[0] = '_'; 1297 p[0] = '_';
1244 } 1298 }
1245 else 1299 else
@@ -1312,7 +1366,7 @@ See also the function `substitute-in-file-name'.")
1312 1366
1313 newdir = 0; 1367 newdir = 0;
1314 1368
1315 if (nm[0] == '~') /* prefix ~ */ 1369 if (nm[0] == '~') /* prefix ~ */
1316 if (nm[1] == '/' 1370 if (nm[1] == '/'
1317#ifdef VMS 1371#ifdef VMS
1318 || nm[1] == ':' 1372 || nm[1] == ':'
@@ -1323,7 +1377,7 @@ See also the function `substitute-in-file-name'.")
1323 newdir = (unsigned char *) ""; 1377 newdir = (unsigned char *) "";
1324 nm++; 1378 nm++;
1325#ifdef VMS 1379#ifdef VMS
1326 nm++; /* Don't leave the slash in nm. */ 1380 nm++; /* Don't leave the slash in nm. */
1327#endif /* VMS */ 1381#endif /* VMS */
1328 } 1382 }
1329 else /* ~user/filename */ 1383 else /* ~user/filename */
@@ -1337,7 +1391,7 @@ See also the function `substitute-in-file-name'.")
1337 unsigned char *ptr1 = index (user, ':'); 1391 unsigned char *ptr1 = index (user, ':');
1338 if (ptr1 != 0 && ptr1 - user < len) 1392 if (ptr1 != 0 && ptr1 - user < len)
1339 len = ptr1 - user; 1393 len = ptr1 - user;
1340#endif /* VMS */ 1394#endif /* VMS */
1341 /* Copy the user name into temp storage. */ 1395 /* Copy the user name into temp storage. */
1342 o = (unsigned char *) alloca (len + 1); 1396 o = (unsigned char *) alloca (len + 1);
1343 bcopy ((char *) user, o, len); 1397 bcopy ((char *) user, o, len);
@@ -1420,7 +1474,7 @@ See also the function `substitute-in-file-name'.")
1420 do 1474 do
1421 o--; 1475 o--;
1422 while (o[-1] != '.' && o[-1] != '[' && o[-1] != '<'); 1476 while (o[-1] != '.' && o[-1] != '[' && o[-1] != '<');
1423 if (p[1] == '.') /* foo.-.bar ==> bar*/ 1477 if (p[1] == '.') /* foo.-.bar ==> bar. */
1424 p += 2; 1478 p += 2;
1425 else if (o[-1] == '.') /* '.foo.-]' ==> ']' */ 1479 else if (o[-1] == '.') /* '.foo.-]' ==> ']' */
1426 p++, o--; 1480 p++, o--;
@@ -1438,7 +1492,7 @@ See also the function `substitute-in-file-name'.")
1438 } 1492 }
1439#else /* not VMS */ 1493#else /* not VMS */
1440 if (*p != '/') 1494 if (*p != '/')
1441 { 1495 {
1442 *o++ = *p++; 1496 *o++ = *p++;
1443 } 1497 }
1444 else if (!strncmp (p, "//", 2) 1498 else if (!strncmp (p, "//", 2)
@@ -1471,7 +1525,7 @@ See also the function `substitute-in-file-name'.")
1471 p += 3; 1525 p += 3;
1472 } 1526 }
1473 else 1527 else
1474 { 1528 {
1475 *o++ = *p++; 1529 *o++ = *p++;
1476 } 1530 }
1477#endif /* not VMS */ 1531#endif /* not VMS */
@@ -1520,28 +1574,30 @@ duplicates what `expand-file-name' does.")
1520 /* // at start of file name is meaningful in Apollo system */ 1574 /* // at start of file name is meaningful in Apollo system */
1521 (p[0] == '/' && p - 1 != nm) 1575 (p[0] == '/' && p - 1 != nm)
1522#else /* not APOLLO */ 1576#else /* not APOLLO */
1577#ifdef WINDOWSNT
1578 (IS_DIRECTORY_SEP (p[0]) && p - 1 != nm)
1579#else /* not WINDOWSNT */
1523 p[0] == '/' 1580 p[0] == '/'
1581#endif /* not WINDOWSNT */
1524#endif /* not APOLLO */ 1582#endif /* not APOLLO */
1525 ) 1583 )
1526 && p != nm && 1584 && p != nm
1585 && (0
1527#ifdef VMS 1586#ifdef VMS
1528 (p[-1] == ':' || p[-1] == ']' || p[-1] == '>' || 1587 || p[-1] == ':' || p[-1] == ']' || p[-1] == '>'
1529#endif /* VMS */
1530 p[-1] == '/')
1531#ifdef VMS
1532 )
1533#endif /* VMS */ 1588#endif /* VMS */
1589 || IS_DIRECTORY_SEP (p[-1])))
1534 { 1590 {
1535 nm = p; 1591 nm = p;
1536 substituted = 1; 1592 substituted = 1;
1537 } 1593 }
1538#ifdef MSDOS 1594#ifdef DOS_NT
1539 if (p[0] && p[1] == ':') 1595 if (p[0] && p[1] == ':')
1540 { 1596 {
1541 nm = p; 1597 nm = p;
1542 substituted = 1; 1598 substituted = 1;
1543 } 1599 }
1544#endif /* MSDOS */ 1600#endif /* DOS_NT */
1545 } 1601 }
1546 1602
1547#ifdef VMS 1603#ifdef VMS
@@ -1585,9 +1641,9 @@ duplicates what `expand-file-name' does.")
1585 target = (unsigned char *) alloca (s - o + 1); 1641 target = (unsigned char *) alloca (s - o + 1);
1586 strncpy (target, o, s - o); 1642 strncpy (target, o, s - o);
1587 target[s - o] = 0; 1643 target[s - o] = 0;
1588#ifdef MSDOS 1644#ifdef DOS_NT
1589 strupr (target); /* $home == $HOME etc. */ 1645 strupr (target); /* $home == $HOME etc. */
1590#endif 1646#endif /* DOS_NT */
1591 1647
1592 /* Get variable value */ 1648 /* Get variable value */
1593 o = (unsigned char *) egetenv (target); 1649 o = (unsigned char *) egetenv (target);
@@ -1636,9 +1692,9 @@ duplicates what `expand-file-name' does.")
1636 target = (unsigned char *) alloca (s - o + 1); 1692 target = (unsigned char *) alloca (s - o + 1);
1637 strncpy (target, o, s - o); 1693 strncpy (target, o, s - o);
1638 target[s - o] = 0; 1694 target[s - o] = 0;
1639#ifdef MSDOS 1695#ifdef DOS_NT
1640 strupr (target); /* $home == $HOME etc. */ 1696 strupr (target); /* $home == $HOME etc. */
1641#endif 1697#endif /* DOS_NT */
1642 1698
1643 /* Get variable value */ 1699 /* Get variable value */
1644 o = (unsigned char *) egetenv (target); 1700 o = (unsigned char *) egetenv (target);
@@ -1654,17 +1710,20 @@ duplicates what `expand-file-name' does.")
1654 /* If /~ or // appears, discard everything through first slash. */ 1710 /* If /~ or // appears, discard everything through first slash. */
1655 1711
1656 for (p = xnm; p != x; p++) 1712 for (p = xnm; p != x; p++)
1657 if ((p[0] == '~' || 1713 if ((p[0] == '~'
1658#ifdef APOLLO 1714#ifdef APOLLO
1659 /* // at start of file name is meaningful in Apollo system */ 1715 /* // at start of file name is meaningful in Apollo system */
1660 (p[0] == '/' && p - 1 != xnm) 1716 || (p[0] == '/' && p - 1 != xnm)
1661#else /* not APOLLO */ 1717#else /* not APOLLO */
1662 p[0] == '/' 1718#ifdef WINDOWSNT
1663#endif /* not APOLLO */ 1719 || (IS_DIRECTORY_SEP (p[0]) && p - 1 != xnm)
1720#else /* not WINDOWSNT */
1721 || p[0] == '/'
1722#endif /* not WINDOWSNT */
1664 ) 1723 )
1665 && p != nm && p[-1] == '/') 1724 && p != nm && IS_DIRECTORY_SEP (p[-1]))
1666 xnm = p; 1725 xnm = p;
1667#ifdef MSDOS 1726#ifdef DOS_NT
1668 else if (p[0] && p[1] == ':') 1727 else if (p[0] && p[1] == ':')
1669 xnm = p; 1728 xnm = p;
1670#endif 1729#endif
@@ -1702,7 +1761,8 @@ expand_and_dir_to_file (filename, defdir)
1702 /* Remove final slash, if any (unless path is root). 1761 /* Remove final slash, if any (unless path is root).
1703 stat behaves differently depending! */ 1762 stat behaves differently depending! */
1704 if (XSTRING (abspath)->size > 1 1763 if (XSTRING (abspath)->size > 1
1705 && XSTRING (abspath)->data[XSTRING (abspath)->size - 1] == '/') 1764 && IS_DIRECTORY_SEP (XSTRING (abspath)->data[XSTRING (abspath)->size - 1])
1765 && !IS_DEVICE_SEP (XSTRING (abspath)->data[XSTRING (abspath)->size-2]))
1706 /* We cannot take shortcuts; they might be wrong for magic file names. */ 1766 /* We cannot take shortcuts; they might be wrong for magic file names. */
1707 abspath = Fdirectory_file_name (abspath); 1767 abspath = Fdirectory_file_name (abspath);
1708#endif 1768#endif
@@ -1875,7 +1935,11 @@ DEFUN ("make-directory-internal", Fmake_directory_internal,
1875 1935
1876 dir = XSTRING (dirname)->data; 1936 dir = XSTRING (dirname)->data;
1877 1937
1938#ifdef WINDOWSNT
1939 if (mkdir (dir) != 0)
1940#else
1878 if (mkdir (dir, 0777) != 0) 1941 if (mkdir (dir, 0777) != 0)
1942#endif
1879 report_file_error ("Creating directory", Flist (1, &dirname)); 1943 report_file_error ("Creating directory", Flist (1, &dirname));
1880 1944
1881 return Qnil; 1945 return Qnil;
@@ -1961,11 +2025,21 @@ This is what happens in interactive use with M-x.")
1961#ifndef BSD4_1 2025#ifndef BSD4_1
1962 if (0 > rename (XSTRING (filename)->data, XSTRING (newname)->data)) 2026 if (0 > rename (XSTRING (filename)->data, XSTRING (newname)->data))
1963#else 2027#else
2028#ifdef WINDOWSNT
2029 if (!MoveFile (XSTRING (filename)->data, XSTRING (newname)->data))
2030#else /* not WINDOWSNT */
1964 if (0 > link (XSTRING (filename)->data, XSTRING (newname)->data) 2031 if (0 > link (XSTRING (filename)->data, XSTRING (newname)->data)
1965 || 0 > unlink (XSTRING (filename)->data)) 2032 || 0 > unlink (XSTRING (filename)->data))
2033#endif /* not WINDOWSNT */
1966#endif 2034#endif
1967 { 2035 {
2036#ifdef WINDOWSNT
2037 /* Why two? And why doesn't MS document what MoveFile will return? */
2038 if (GetLastError () == ERROR_FILE_EXISTS
2039 || GetLastError () == ERROR_ALREADY_EXISTS)
2040#else /* not WINDOWSNT */
1968 if (errno == EXDEV) 2041 if (errno == EXDEV)
2042#endif /* not WINDOWSNT */
1969 { 2043 {
1970 Fcopy_file (filename, newname, 2044 Fcopy_file (filename, newname,
1971 /* We have already prompted if it was an integer, 2045 /* We have already prompted if it was an integer,
@@ -2021,6 +2095,11 @@ This is what happens in interactive use with M-x.")
2021 || INTEGERP (ok_if_already_exists)) 2095 || INTEGERP (ok_if_already_exists))
2022 barf_or_query_if_file_exists (newname, "make it a new name", 2096 barf_or_query_if_file_exists (newname, "make it a new name",
2023 INTEGERP (ok_if_already_exists)); 2097 INTEGERP (ok_if_already_exists));
2098#ifdef WINDOWSNT
2099 /* Windows does not support this operation. */
2100 report_file_error ("Adding new name", Flist (2, &filename));
2101#else /* not WINDOWSNT */
2102
2024 unlink (XSTRING (newname)->data); 2103 unlink (XSTRING (newname)->data);
2025 if (0 > link (XSTRING (filename)->data, XSTRING (newname)->data)) 2104 if (0 > link (XSTRING (filename)->data, XSTRING (newname)->data))
2026 { 2105 {
@@ -2032,6 +2111,7 @@ This is what happens in interactive use with M-x.")
2032 report_file_error ("Adding new name", Flist (2, &filename)); 2111 report_file_error ("Adding new name", Flist (2, &filename));
2033#endif 2112#endif
2034 } 2113 }
2114#endif /* not WINDOWSNT */
2035 2115
2036 UNGCPRO; 2116 UNGCPRO;
2037 return Qnil; 2117 return Qnil;
@@ -2119,9 +2199,9 @@ If STRING is nil or a null string, the logical name NAME is deleted.")
2119 CHECK_STRING (string, 1); 2199 CHECK_STRING (string, 1);
2120 2200
2121 if (XSTRING (string)->size == 0) 2201 if (XSTRING (string)->size == 0)
2122 delete_logical_name (XSTRING (varname)->data); 2202 delete_logical_name (XSTRING (varname)->data);
2123 else 2203 else
2124 define_logical_name (XSTRING (varname)->data, XSTRING (string)->data); 2204 define_logical_name (XSTRING (varname)->data, XSTRING (string)->data);
2125 } 2205 }
2126 2206
2127 return string; 2207 return string;
@@ -2160,14 +2240,14 @@ On Unix, this is a name starting with a `/' or a `~'.")
2160 2240
2161 CHECK_STRING (filename, 0); 2241 CHECK_STRING (filename, 0);
2162 ptr = XSTRING (filename)->data; 2242 ptr = XSTRING (filename)->data;
2163 if (*ptr == '/' || *ptr == '~' 2243 if (IS_DIRECTORY_SEP (*ptr) || *ptr == '~'
2164#ifdef VMS 2244#ifdef VMS
2165/* ??? This criterion is probably wrong for '<'. */ 2245/* ??? This criterion is probably wrong for '<'. */
2166 || index (ptr, ':') || index (ptr, '<') 2246 || index (ptr, ':') || index (ptr, '<')
2167 || (*ptr == '[' && (ptr[1] != '-' || (ptr[2] != '.' && ptr[2] != ']')) 2247 || (*ptr == '[' && (ptr[1] != '-' || (ptr[2] != '.' && ptr[2] != ']'))
2168 && ptr[1] != '.') 2248 && ptr[1] != '.')
2169#endif /* VMS */ 2249#endif /* VMS */
2170#ifdef MSDOS 2250#ifdef DOS_NT
2171 || (*ptr != 0 && ptr[1] == ':' && (ptr[2] == '/' || ptr[2] == '\\')) 2251 || (*ptr != 0 && ptr[1] == ':' && (ptr[2] == '/' || ptr[2] == '\\'))
2172#endif 2252#endif
2173 ) 2253 )
@@ -2462,7 +2542,7 @@ DEFUN ("file-modes", Ffile_modes, Sfile_modes, 1, 1, 0,
2462 2542
2463 if (stat (XSTRING (abspath)->data, &st) < 0) 2543 if (stat (XSTRING (abspath)->data, &st) < 0)
2464 return Qnil; 2544 return Qnil;
2465#ifdef MSDOS 2545#ifdef DOS_NT
2466 { 2546 {
2467 int len; 2547 int len;
2468 char *suffix; 2548 char *suffix;
@@ -2473,7 +2553,7 @@ DEFUN ("file-modes", Ffile_modes, Sfile_modes, 1, 1, 0,
2473 || stricmp (suffix, ".bat") == 0)) 2553 || stricmp (suffix, ".bat") == 0))
2474 st.st_mode |= S_IEXEC; 2554 st.st_mode |= S_IEXEC;
2475 } 2555 }
2476#endif /* MSDOS */ 2556#endif /* DOS_NT */
2477 2557
2478 return make_number (st.st_mode & 07777); 2558 return make_number (st.st_mode & 07777);
2479} 2559}
@@ -2514,7 +2594,7 @@ Only the 12 low bits of MODE are used.")
2514 } 2594 }
2515 2595
2516 if (chmod (XSTRING (abspath)->data, XINT (mode)) < 0) 2596 if (chmod (XSTRING (abspath)->data, XINT (mode)) < 0)
2517 report_file_error ("Doing chmod", Fcons (abspath, Qnil)); 2597 report_file_error ("Doing chmod", Fcons (abspath, Qnil));
2518 2598
2519 /* reset the old accessed and modified times. */ 2599 /* reset the old accessed and modified times. */
2520 tvp[0].tv_sec = st.st_atime + 1; /* +1 due to an Apollo roundoff bug */ 2600 tvp[0].tv_sec = st.st_atime + 1; /* +1 due to an Apollo roundoff bug */
@@ -2523,7 +2603,7 @@ Only the 12 low bits of MODE are used.")
2523 tvp[1].tv_usec = 0; 2603 tvp[1].tv_usec = 0;
2524 2604
2525 if (utimes (XSTRING (abspath)->data, tvp) < 0) 2605 if (utimes (XSTRING (abspath)->data, tvp) < 0)
2526 report_file_error ("Doing utimes", Fcons (abspath, Qnil)); 2606 report_file_error ("Doing utimes", Fcons (abspath, Qnil));
2527 } 2607 }
2528#endif /* APOLLO */ 2608#endif /* APOLLO */
2529 2609
@@ -2612,9 +2692,9 @@ otherwise, if FILE2 does not exist, the answer is t.")
2612 return (mtime1 > st.st_mtime) ? Qt : Qnil; 2692 return (mtime1 > st.st_mtime) ? Qt : Qnil;
2613} 2693}
2614 2694
2615#ifdef MSDOS 2695#ifdef DOS_NT
2616Lisp_Object Qfind_buffer_file_type; 2696Lisp_Object Qfind_buffer_file_type;
2617#endif 2697#endif /* DOS_NT */
2618 2698
2619DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, 2699DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents,
2620 1, 5, 0, 2700 1, 5, 0,
@@ -2729,7 +2809,7 @@ and (2) it puts less data in the undo list.")
2729 with the file contents. Avoid replacing text at the 2809 with the file contents. Avoid replacing text at the
2730 beginning or end of the buffer that matches the file contents; 2810 beginning or end of the buffer that matches the file contents;
2731 that preserves markers pointing to the unchanged parts. */ 2811 that preserves markers pointing to the unchanged parts. */
2732#ifdef MSDOS 2812#ifdef DOS_NT
2733 /* On MSDOS, replace mode doesn't really work, except for binary files, 2813 /* On MSDOS, replace mode doesn't really work, except for binary files,
2734 and it's not worth supporting just for them. */ 2814 and it's not worth supporting just for them. */
2735 if (!NILP (replace)) 2815 if (!NILP (replace))
@@ -2739,7 +2819,7 @@ and (2) it puts less data in the undo list.")
2739 XSETFASTINT (end, st.st_size); 2819 XSETFASTINT (end, st.st_size);
2740 del_range_1 (BEGV, ZV, 0); 2820 del_range_1 (BEGV, ZV, 0);
2741 } 2821 }
2742#else /* MSDOS */ 2822#else /* not DOS_NT */
2743 if (!NILP (replace)) 2823 if (!NILP (replace))
2744 { 2824 {
2745 unsigned char buffer[1 << 14]; 2825 unsigned char buffer[1 << 14];
@@ -2837,7 +2917,7 @@ and (2) it puts less data in the undo list.")
2837 /* Insert from the file at the proper position. */ 2917 /* Insert from the file at the proper position. */
2838 SET_PT (same_at_start); 2918 SET_PT (same_at_start);
2839 } 2919 }
2840#endif /* MSDOS */ 2920#endif /* not DOS_NT */
2841 2921
2842 total = XINT (end) - XINT (beg); 2922 total = XINT (end) - XINT (beg);
2843 2923
@@ -2866,13 +2946,14 @@ and (2) it puts less data in the undo list.")
2866 how_much = 0; 2946 how_much = 0;
2867 while (inserted < total) 2947 while (inserted < total)
2868 { 2948 {
2869 int try = min (total - inserted, 64 << 10); 2949 /* try is reserved in some compilers (Microsoft C) */
2950 int trytry = min (total - inserted, 64 << 10);
2870 int this; 2951 int this;
2871 2952
2872 /* Allow quitting out of the actual I/O. */ 2953 /* Allow quitting out of the actual I/O. */
2873 immediate_quit = 1; 2954 immediate_quit = 1;
2874 QUIT; 2955 QUIT;
2875 this = read (fd, &FETCH_CHAR (point + inserted - 1) + 1, try); 2956 this = read (fd, &FETCH_CHAR (point + inserted - 1) + 1, trytry);
2876 immediate_quit = 0; 2957 immediate_quit = 0;
2877 2958
2878 if (this <= 0) 2959 if (this <= 0)
@@ -2888,7 +2969,7 @@ and (2) it puts less data in the undo list.")
2888 inserted += this; 2969 inserted += this;
2889 } 2970 }
2890 2971
2891#ifdef MSDOS 2972#ifdef DOS_NT
2892 /* Demacs 1.1.1 91/10/16 HIRANO Satoshi, MW July 1993 */ 2973 /* Demacs 1.1.1 91/10/16 HIRANO Satoshi, MW July 1993 */
2893 /* Determine file type from name and remove LFs from CR-LFs if the file 2974 /* Determine file type from name and remove LFs from CR-LFs if the file
2894 is deemed to be a text file. */ 2975 is deemed to be a text file. */
@@ -2906,7 +2987,7 @@ and (2) it puts less data in the undo list.")
2906 inserted -= reduced_size; 2987 inserted -= reduced_size;
2907 } 2988 }
2908 } 2989 }
2909#endif 2990#endif /* DOS_NT */
2910 2991
2911 if (inserted > 0) 2992 if (inserted > 0)
2912 { 2993 {
@@ -3034,7 +3115,7 @@ to the file, instead of any buffer contents, and END is ignored.")
3034 int count = specpdl_ptr - specpdl; 3115 int count = specpdl_ptr - specpdl;
3035 int count1; 3116 int count1;
3036#ifdef VMS 3117#ifdef VMS
3037 unsigned char *fname = 0; /* If non-0, original filename (must rename) */ 3118 unsigned char *fname = 0; /* If non-0, original filename (must rename) */
3038#endif /* VMS */ 3119#endif /* VMS */
3039 Lisp_Object handler; 3120 Lisp_Object handler;
3040 Lisp_Object visit_file; 3121 Lisp_Object visit_file;
@@ -3042,10 +3123,10 @@ to the file, instead of any buffer contents, and END is ignored.")
3042 int visiting, quietly; 3123 int visiting, quietly;
3043 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 3124 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
3044 struct buffer *given_buffer; 3125 struct buffer *given_buffer;
3045#ifdef MSDOS 3126#ifdef DOS_NT
3046 int buffer_file_type 3127 int buffer_file_type
3047 = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY; 3128 = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY;
3048#endif 3129#endif /* DOS_NT */
3049 3130
3050 if (!NILP (start) && !STRINGP (start)) 3131 if (!NILP (start) && !STRINGP (start))
3051 validate_region (&start, &end); 3132 validate_region (&start, &end);
@@ -3114,24 +3195,24 @@ to the file, instead of any buffer contents, and END is ignored.")
3114 fn = XSTRING (filename)->data; 3195 fn = XSTRING (filename)->data;
3115 desc = -1; 3196 desc = -1;
3116 if (!NILP (append)) 3197 if (!NILP (append))
3117#ifdef MSDOS 3198#ifdef DOS_NT
3118 desc = open (fn, O_WRONLY | buffer_file_type); 3199 desc = open (fn, O_WRONLY | buffer_file_type);
3119#else 3200#else /* not DOS_NT */
3120 desc = open (fn, O_WRONLY); 3201 desc = open (fn, O_WRONLY);
3121#endif 3202#endif /* not DOS_NT */
3122 3203
3123 if (desc < 0) 3204 if (desc < 0)
3124#ifdef VMS 3205#ifdef VMS
3125 if (auto_saving) /* Overwrite any previous version of autosave file */ 3206 if (auto_saving) /* Overwrite any previous version of autosave file */
3126 { 3207 {
3127 vms_truncate (fn); /* if fn exists, truncate to zero length */ 3208 vms_truncate (fn); /* if fn exists, truncate to zero length */
3128 desc = open (fn, O_RDWR); 3209 desc = open (fn, O_RDWR);
3129 if (desc < 0) 3210 if (desc < 0)
3130 desc = creat_copy_attrs (STRINGP (current_buffer->filename) 3211 desc = creat_copy_attrs (STRINGP (current_buffer->filename)
3131 ? XSTRING (current_buffer->filename)->data : 0, 3212 ? XSTRING (current_buffer->filename)->data : 0,
3132 fn); 3213 fn);
3133 } 3214 }
3134 else /* Write to temporary name and rename if no errors */ 3215 else /* Write to temporary name and rename if no errors */
3135 { 3216 {
3136 Lisp_Object temp_name; 3217 Lisp_Object temp_name;
3137 temp_name = Ffile_name_directory (filename); 3218 temp_name = Ffile_name_directory (filename);
@@ -3167,13 +3248,13 @@ to the file, instead of any buffer contents, and END is ignored.")
3167 desc = creat (fn, 0666); 3248 desc = creat (fn, 0666);
3168 } 3249 }
3169#else /* not VMS */ 3250#else /* not VMS */
3170#ifdef MSDOS 3251#ifdef DOS_NT
3171 desc = open (fn, 3252 desc = open (fn,
3172 O_WRONLY | O_TRUNC | O_CREAT | buffer_file_type, 3253 O_WRONLY | O_TRUNC | O_CREAT | buffer_file_type,
3173 S_IREAD | S_IWRITE); 3254 S_IREAD | S_IWRITE);
3174#else /* not MSDOS */ 3255#else /* not DOS_NT */
3175 desc = creat (fn, auto_saving ? auto_save_mode_bits : 0666); 3256 desc = creat (fn, auto_saving ? auto_save_mode_bits : 0666);
3176#endif /* not MSDOS */ 3257#endif /* not DOS_NT */
3177#endif /* not VMS */ 3258#endif /* not VMS */
3178 3259
3179 UNGCPRO; 3260 UNGCPRO;
@@ -3651,13 +3732,13 @@ Non-nil second argument means save only current buffer.")
3651 3732
3652 if (STRINGP (Vauto_save_list_file_name)) 3733 if (STRINGP (Vauto_save_list_file_name))
3653 { 3734 {
3654#ifdef MSDOS 3735#ifdef DOS_NT
3655 listdesc = open (XSTRING (Vauto_save_list_file_name)->data, 3736 listdesc = open (XSTRING (Vauto_save_list_file_name)->data,
3656 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT, 3737 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT,
3657 S_IREAD | S_IWRITE); 3738 S_IREAD | S_IWRITE);
3658#else /* not MSDOS */ 3739#else /* not DOS_NT */
3659 listdesc = creat (XSTRING (Vauto_save_list_file_name)->data, 0666); 3740 listdesc = creat (XSTRING (Vauto_save_list_file_name)->data, 0666);
3660#endif /* not MSDOS */ 3741#endif /* not DOS_NT */
3661 } 3742 }
3662 else 3743 else
3663 listdesc = -1; 3744 listdesc = -1;
@@ -3937,7 +4018,7 @@ DIR defaults to current buffer's directory default.")
3937 if (homedir != 0 4018 if (homedir != 0
3938 && STRINGP (dir) 4019 && STRINGP (dir)
3939 && !strncmp (homedir, XSTRING (dir)->data, strlen (homedir)) 4020 && !strncmp (homedir, XSTRING (dir)->data, strlen (homedir))
3940 && XSTRING (dir)->data[strlen (homedir)] == '/') 4021 && IS_DIRECTORY_SEP (XSTRING (dir)->data[strlen (homedir)]))
3941 { 4022 {
3942 dir = make_string (XSTRING (dir)->data + strlen (homedir) - 1, 4023 dir = make_string (XSTRING (dir)->data + strlen (homedir) - 1,
3943 XSTRING (dir)->size - strlen (homedir) + 1); 4024 XSTRING (dir)->size - strlen (homedir) + 1);
@@ -3998,7 +4079,7 @@ DIR defaults to current buffer's directory default.")
3998 return Fsubstitute_in_file_name (val); 4079 return Fsubstitute_in_file_name (val);
3999} 4080}
4000 4081
4001#if 0 /* Old version */ 4082#if 0 /* Old version */
4002DEFUN ("read-file-name", Fread_file_name, Sread_file_name, 1, 5, 0, 4083DEFUN ("read-file-name", Fread_file_name, Sread_file_name, 1, 5, 0,
4003 /* Don't confuse make-docfile by having two doc strings for this function. 4084 /* Don't confuse make-docfile by having two doc strings for this function.
4004 make-docfile does not pay attention to #if, for good reason! */ 4085 make-docfile does not pay attention to #if, for good reason! */
@@ -4126,10 +4207,10 @@ syms_of_fileio ()
4126 Qfile_already_exists = intern("file-already-exists"); 4207 Qfile_already_exists = intern("file-already-exists");
4127 staticpro (&Qfile_already_exists); 4208 staticpro (&Qfile_already_exists);
4128 4209
4129#ifdef MSDOS 4210#ifdef DOS_NT
4130 Qfind_buffer_file_type = intern ("find-buffer-file-type"); 4211 Qfind_buffer_file_type = intern ("find-buffer-file-type");
4131 staticpro (&Qfind_buffer_file_type); 4212 staticpro (&Qfind_buffer_file_type);
4132#endif 4213#endif /* DOS_NT */
4133 4214
4134 Qcar_less_than_car = intern ("car-less-than-car"); 4215 Qcar_less_than_car = intern ("car-less-than-car");
4135 staticpro (&Qcar_less_than_car); 4216 staticpro (&Qcar_less_than_car);