comparison src/fileio.c @ 410:de805c49cfc1 r21-2-35

Import from CVS: tag r21-2-35
author cvs
date Mon, 13 Aug 2007 11:19:21 +0200
parents 2f8bb876ab1d
children 697ef44129c6
comparison
equal deleted inserted replaced
409:301b9ebbdf3b 410:de805c49cfc1
22 /* Synched up with: Mule 2.0, FSF 19.30. */ 22 /* Synched up with: Mule 2.0, FSF 19.30. */
23 /* More syncing: FSF Emacs 19.34.6 by Marc Paquette <marcpa@cam.org> */ 23 /* More syncing: FSF Emacs 19.34.6 by Marc Paquette <marcpa@cam.org> */
24 24
25 #include <config.h> 25 #include <config.h>
26 #include "lisp.h" 26 #include "lisp.h"
27 #include <limits.h>
28 27
29 #include "buffer.h" 28 #include "buffer.h"
30 #include "events.h" 29 #include "events.h"
31 #include "frame.h" 30 #include "frame.h"
32 #include "insdel.h" 31 #include "insdel.h"
52 #ifdef HPUX_PRE_8_0 51 #ifdef HPUX_PRE_8_0
53 #include <errnet.h> 52 #include <errnet.h>
54 #endif /* HPUX_PRE_8_0 */ 53 #endif /* HPUX_PRE_8_0 */
55 #endif /* HPUX */ 54 #endif /* HPUX */
56 55
57 #ifdef WINDOWSNT 56 #ifdef WIN32_NATIVE
58 #define NOMINMAX 1
59 #include <direct.h>
60 #include <fcntl.h>
61 #include <stdlib.h>
62 #endif /* not WINDOWSNT */
63
64 #ifdef WINDOWSNT
65 #define CORRECT_DIR_SEPS(s) \
66 do { if ('/' == DIRECTORY_SEP) dostounix_filename (s); \
67 else unixtodos_filename (s); \
68 } while (0)
69 #define IS_DRIVE(x) isalpha (x) 57 #define IS_DRIVE(x) isalpha (x)
70 /* Need to lower-case the drive letter, or else expanded 58 /* Need to lower-case the drive letter, or else expanded
71 filenames will sometimes compare inequal, because 59 filenames will sometimes compare inequal, because
72 `expand-file-name' doesn't always down-case the drive letter. */ 60 `expand-file-name' doesn't always down-case the drive letter. */
73 #define DRIVE_LETTER(x) tolower (x) 61 #define DRIVE_LETTER(x) tolower (x)
74 #endif /* WINDOWSNT */ 62 #endif /* WIN32_NATIVE */
75 63
76 int lisp_to_time (Lisp_Object, time_t *); 64 int lisp_to_time (Lisp_Object, time_t *);
77 Lisp_Object time_to_lisp (time_t); 65 Lisp_Object time_to_lisp (time_t);
78 66
79 /* Nonzero during writing of auto-save files */ 67 /* Nonzero during writing of auto-save files */
430 #endif 418 #endif
431 beg = XSTRING_DATA (file); 419 beg = XSTRING_DATA (file);
432 p = beg + XSTRING_LENGTH (file); 420 p = beg + XSTRING_LENGTH (file);
433 421
434 while (p != beg && !IS_ANY_SEP (p[-1]) 422 while (p != beg && !IS_ANY_SEP (p[-1])
435 #ifdef WINDOWSNT 423 #ifdef WIN32_NATIVE
436 /* only recognize drive specifier at beginning */ 424 /* only recognize drive specifier at beginning */
437 && !(p[-1] == ':' && p == beg + 2) 425 && !(p[-1] == ':' && p == beg + 2)
438 #endif 426 #endif
439 ) p--; 427 ) p--;
440 428
441 if (p == beg) 429 if (p == beg)
442 return Qnil; 430 return Qnil;
443 #ifdef WINDOWSNT 431 #ifdef WIN32_NATIVE
444 /* Expansion of "c:" to drive and default directory. */ 432 /* Expansion of "c:" to drive and default directory. */
445 /* (NT does the right thing.) */ 433 /* (NT does the right thing.) */
446 if (p == beg + 2 && beg[1] == ':') 434 if (p == beg + 2 && beg[1] == ':')
447 { 435 {
448 /* MAXPATHLEN+1 is guaranteed to be enough space for getdefdir. */ 436 /* MAXPATHLEN+1 is guaranteed to be enough space for getdefdir. */
449 Bufbyte *res = (Bufbyte*) alloca (MAXPATHLEN + 1); 437 Bufbyte *res = (Bufbyte*) alloca (MAXPATHLEN + 1);
450 if (getdefdir (toupper (*beg) - 'A' + 1, (char *)res)) 438 if (_getdcwd (toupper (*beg) - 'A' + 1, (char *)res, MAXPATHLEN))
451 { 439 {
452 char *c=((char *) res) + strlen ((char *) res); 440 char *c=((char *) res) + strlen ((char *) res);
453 if (!IS_DIRECTORY_SEP (*c)) 441 if (!IS_DIRECTORY_SEP (*c))
454 { 442 {
455 *c++ = DIRECTORY_SEP; 443 *c++ = DIRECTORY_SEP;
457 } 445 }
458 beg = res; 446 beg = res;
459 p = beg + strlen ((char *) beg); 447 p = beg + strlen ((char *) beg);
460 } 448 }
461 } 449 }
462 #endif /* WINDOWSNT */ 450 #endif /* WIN32_NATIVE */
463 return make_string (beg, p - beg); 451 return make_string (beg, p - beg);
464 } 452 }
465 453
466 DEFUN ("file-name-nondirectory", Ffile_name_nondirectory, 1, 1, 0, /* 454 DEFUN ("file-name-nondirectory", Ffile_name_nondirectory, 1, 1, 0, /*
467 Return file name NAME sans its directory. 455 Return file name NAME sans its directory.
485 473
486 beg = XSTRING_DATA (file); 474 beg = XSTRING_DATA (file);
487 end = p = beg + XSTRING_LENGTH (file); 475 end = p = beg + XSTRING_LENGTH (file);
488 476
489 while (p != beg && !IS_ANY_SEP (p[-1]) 477 while (p != beg && !IS_ANY_SEP (p[-1])
490 #ifdef WINDOWSNT 478 #ifdef WIN32_NATIVE
491 /* only recognize drive specifier at beginning */ 479 /* only recognize drive specifier at beginning */
492 && !(p[-1] == ':' && p == beg + 2) 480 && !(p[-1] == ':' && p == beg + 2)
493 #endif 481 #endif
494 ) p--; 482 ) p--;
495 483
587 /* Process as Unix format: just remove any final slash. 575 /* Process as Unix format: just remove any final slash.
588 But leave "/" unchanged; do not change it to "". */ 576 But leave "/" unchanged; do not change it to "". */
589 strcpy (dst, src); 577 strcpy (dst, src);
590 if (slen > 1 578 if (slen > 1
591 && IS_DIRECTORY_SEP (dst[slen - 1]) 579 && IS_DIRECTORY_SEP (dst[slen - 1])
592 #ifdef WINDOWSNT 580 #ifdef WIN32_NATIVE
593 && !IS_ANY_SEP (dst[slen - 2]) 581 && !IS_ANY_SEP (dst[slen - 2])
594 #endif /* WINDOWSNT */ 582 #endif /* WIN32_NATIVE */
595 ) 583 )
596 dst[slen - 1] = 0; 584 dst[slen - 1] = 0;
597 return 1; 585 return 1;
598 } 586 }
599 587
756 Bufbyte *nm; 744 Bufbyte *nm;
757 745
758 Bufbyte *newdir, *p, *o; 746 Bufbyte *newdir, *p, *o;
759 int tlen; 747 int tlen;
760 Bufbyte *target; 748 Bufbyte *target;
761 #ifdef WINDOWSNT 749 #ifdef WIN32_NATIVE
762 int drive = 0; 750 int drive = 0;
763 int collapse_newdir = 1; 751 int collapse_newdir = 1;
764 #else 752 #else
765 struct passwd *pw; 753 struct passwd *pw;
766 #endif /* WINDOWSNT */ 754 #endif /* WIN32_NATIVE */
767 int length; 755 int length;
768 Lisp_Object handler; 756 Lisp_Object handler;
769 #ifdef __CYGWIN32__ 757 #ifdef CYGWIN
770 char *user; 758 char *user;
771 #endif 759 #endif
772 760
773 CHECK_STRING (name); 761 CHECK_STRING (name);
774 762
806 The EQ test avoids infinite recursion. */ 794 The EQ test avoids infinite recursion. */
807 if (! NILP (default_directory) && !EQ (default_directory, name) 795 if (! NILP (default_directory) && !EQ (default_directory, name)
808 /* Save time in some common cases - as long as default_directory 796 /* Save time in some common cases - as long as default_directory
809 is not relative, it can be canonicalized with name below (if it 797 is not relative, it can be canonicalized with name below (if it
810 is needed at all) without requiring it to be expanded now. */ 798 is needed at all) without requiring it to be expanded now. */
811 #ifdef WINDOWSNT 799 #ifdef WIN32_NATIVE
812 /* Detect MSDOS file names with drive specifiers. */ 800 /* Detect Windows file names with drive specifiers. */
813 && ! (IS_DRIVE (o[0]) && (IS_DEVICE_SEP (o[1]) && IS_DIRECTORY_SEP (o[2]))) 801 && ! (IS_DRIVE (o[0]) && (IS_DEVICE_SEP (o[1]) && IS_DIRECTORY_SEP (o[2])))
814 /* Detect Windows file names in UNC format. */ 802 /* Detect Windows file names in UNC format. */
815 && ! (IS_DIRECTORY_SEP (o[0]) && IS_DIRECTORY_SEP (o[1])) 803 && ! (IS_DIRECTORY_SEP (o[0]) && IS_DIRECTORY_SEP (o[1]))
816 804
817 #else /* not WINDOWSNT */ 805 #else /* not WIN32_NATIVE */
818 806
819 /* Detect Unix absolute file names (/... alone is not absolute on 807 /* Detect Unix absolute file names (/... alone is not absolute on
820 DOS or Windows). */ 808 Windows). */
821 && ! (IS_DIRECTORY_SEP (o[0])) 809 && ! (IS_DIRECTORY_SEP (o[0]))
822 #endif /* not WINDOWSNT */ 810 #endif /* not WIN32_NATIVE */
823 ) 811 )
824 { 812 {
825 struct gcpro gcpro1; 813 struct gcpro gcpro1;
826 814
827 GCPRO1 (name); 815 GCPRO1 (name);
835 823
836 /* #### dmoore - this is ugly, clean this up. Looks like nm pointing 824 /* #### dmoore - this is ugly, clean this up. Looks like nm pointing
837 into name should be safe during all of this, though. */ 825 into name should be safe during all of this, though. */
838 nm = XSTRING_DATA (name); 826 nm = XSTRING_DATA (name);
839 827
840 #ifdef WINDOWSNT 828 #ifdef WIN32_NATIVE
841 /* We will force directory separators to be either all \ or /, so make 829 /* We will force directory separators to be either all \ or /, so make
842 a local copy to modify, even if there ends up being no change. */ 830 a local copy to modify, even if there ends up being no change. */
843 nm = strcpy ((char *)alloca (strlen ((char *)nm) + 1), (char *)nm); 831 nm = strcpy ((char *)alloca (strlen ((char *)nm) + 1), (char *)nm);
844 832
845 /* Find and remove drive specifier if present; this makes nm absolute 833 /* Find and remove drive specifier if present; this makes nm absolute
873 /* If we see "c://somedir", we want to strip the first slash after the 861 /* If we see "c://somedir", we want to strip the first slash after the
874 colon when stripping the drive letter. Otherwise, this expands to 862 colon when stripping the drive letter. Otherwise, this expands to
875 "//somedir". */ 863 "//somedir". */
876 if (drive && IS_DIRECTORY_SEP (nm[0]) && IS_DIRECTORY_SEP (nm[1])) 864 if (drive && IS_DIRECTORY_SEP (nm[0]) && IS_DIRECTORY_SEP (nm[1]))
877 nm++; 865 nm++;
878 #endif /* WINDOWSNT */ 866 #endif /* WIN32_NATIVE */
879 867
880 /* If nm is absolute, look for /./ or /../ sequences; if none are 868 /* If nm is absolute, look for /./ or /../ sequences; if none are
881 found, we can probably return right away. We will avoid allocating 869 found, we can probably return right away. We will avoid allocating
882 a new string if name is already fully expanded. */ 870 a new string if name is already fully expanded. */
883 if ( 871 if (
884 IS_DIRECTORY_SEP (nm[0]) 872 IS_DIRECTORY_SEP (nm[0])
885 #ifdef WINDOWSNT 873 #ifdef WIN32_NATIVE
886 && (drive || IS_DIRECTORY_SEP (nm[1])) 874 && (drive || IS_DIRECTORY_SEP (nm[1]))
887 #endif 875 #endif
888 ) 876 )
889 { 877 {
890 /* If it turns out that the filename we want to return is just a 878 /* If it turns out that the filename we want to return is just a
911 lose = 1; 899 lose = 1;
912 p++; 900 p++;
913 } 901 }
914 if (!lose) 902 if (!lose)
915 { 903 {
916 #ifdef WINDOWSNT 904 #ifdef WIN32_NATIVE
917 /* Make sure directories are all separated with / or \ as 905 /* Make sure directories are all separated with / or \ as
918 desired, but avoid allocation of a new string when not 906 desired, but avoid allocation of a new string when not
919 required. */ 907 required. */
920 CORRECT_DIR_SEPS (nm); 908 CORRECT_DIR_SEPS (nm);
921 if (IS_DIRECTORY_SEP (nm[1])) 909 if (IS_DIRECTORY_SEP (nm[1]))
929 name = make_string (nm - 2, p - nm + 2); 917 name = make_string (nm - 2, p - nm + 2);
930 XSTRING_DATA (name)[0] = DRIVE_LETTER (drive); 918 XSTRING_DATA (name)[0] = DRIVE_LETTER (drive);
931 XSTRING_DATA (name)[1] = ':'; 919 XSTRING_DATA (name)[1] = ':';
932 } 920 }
933 return name; 921 return name;
934 #else /* not WINDOWSNT */ 922 #else /* not WIN32_NATIVE */
935 if (nm == XSTRING_DATA (name)) 923 if (nm == XSTRING_DATA (name))
936 return name; 924 return name;
937 return build_string ((char *) nm); 925 return build_string ((char *) nm);
938 #endif /* not WINDOWSNT */ 926 #endif /* not WIN32_NATIVE */
939 } 927 }
940 } 928 }
941 929
942 /* At this point, nm might or might not be an absolute file name. We 930 /* At this point, nm might or might not be an absolute file name. We
943 need to expand ~ or ~user if present, otherwise prefix nm with 931 need to expand ~ or ~user if present, otherwise prefix nm with
970 TO_INTERNAL_FORMAT (C_STRING, newdir_external, 958 TO_INTERNAL_FORMAT (C_STRING, newdir_external,
971 C_STRING_ALLOCA, (* ((char **) &newdir)), 959 C_STRING_ALLOCA, (* ((char **) &newdir)),
972 Qfile_name); 960 Qfile_name);
973 961
974 nm++; 962 nm++;
975 #ifdef WINDOWSNT 963 #ifdef WIN32_NATIVE
976 collapse_newdir = 0; 964 collapse_newdir = 0;
977 #endif 965 #endif
978 } 966 }
979 else /* ~user/filename */ 967 else /* ~user/filename */
980 { 968 {
989 names the user who runs this instance of XEmacs. While 977 names the user who runs this instance of XEmacs. While
990 NT is single-user (for the moment) you still can have 978 NT is single-user (for the moment) you still can have
991 multiple user profiles users defined, each with its HOME. 979 multiple user profiles users defined, each with its HOME.
992 Therefore, the following should be reworked to handle 980 Therefore, the following should be reworked to handle
993 this case. */ 981 this case. */
994 #ifdef WINDOWSNT 982 #ifdef WIN32_NATIVE
995 /* Now if the file given is "~foo/file" and HOME="c:/", then 983 /* Now if the file given is "~foo/file" and HOME="c:/", then
996 we want the file to be named "c:/file" ("~foo" becomes 984 we want the file to be named "c:/file" ("~foo" becomes
997 "c:/"). The variable o has "~foo", so we can use the 985 "c:/"). The variable o has "~foo", so we can use the
998 length of that string to offset nm. August Hill, 31 Aug 986 length of that string to offset nm. August Hill, 31 Aug
999 1998. */ 987 1998. */
1000 newdir = (Bufbyte *) get_home_directory(); 988 newdir = (Bufbyte *) get_home_directory();
1001 dostounix_filename (newdir); 989 dostounix_filename (newdir);
1002 nm += strlen(o) + 1; 990 nm += strlen(o) + 1;
1003 #else /* not WINDOWSNT */ 991 #else /* not WIN32_NATIVE */
1004 #ifdef __CYGWIN32__ 992 #ifdef CYGWIN
1005 if ((user = user_login_name (NULL)) != NULL) 993 if ((user = user_login_name (NULL)) != NULL)
1006 { 994 {
1007 /* Does the user login name match the ~name? */ 995 /* Does the user login name match the ~name? */
1008 if (strcmp (user, (char *) o + 1) == 0) 996 if (strcmp (user, (char *) o + 1) == 0)
1009 { 997 {
1011 nm = p; 999 nm = p;
1012 } 1000 }
1013 } 1001 }
1014 if (! newdir) 1002 if (! newdir)
1015 { 1003 {
1016 #endif /* __CYGWIN32__ */ 1004 #endif /* CYGWIN */
1017 /* Jamie reports that getpwnam() can get wedged by SIGIO/SIGALARM 1005 /* Jamie reports that getpwnam() can get wedged by SIGIO/SIGALARM
1018 occurring in it. (It can call select()). */ 1006 occurring in it. (It can call select()). */
1019 slow_down_interrupts (); 1007 slow_down_interrupts ();
1020 pw = (struct passwd *) getpwnam ((char *) o + 1); 1008 pw = (struct passwd *) getpwnam ((char *) o + 1);
1021 speed_up_interrupts (); 1009 speed_up_interrupts ();
1022 if (pw) 1010 if (pw)
1023 { 1011 {
1024 newdir = (Bufbyte *) pw -> pw_dir; 1012 newdir = (Bufbyte *) pw -> pw_dir;
1025 nm = p; 1013 nm = p;
1026 } 1014 }
1027 #ifdef __CYGWIN32__ 1015 #ifdef CYGWIN
1028 } 1016 }
1029 #endif 1017 #endif
1030 #endif /* not WINDOWSNT */ 1018 #endif /* not WIN32_NATIVE */
1031 1019
1032 /* If we don't find a user of that name, leave the name 1020 /* If we don't find a user of that name, leave the name
1033 unchanged; don't move nm forward to p. */ 1021 unchanged; don't move nm forward to p. */
1034 } 1022 }
1035 } 1023 }
1036 1024
1037 #ifdef WINDOWSNT 1025 #ifdef WIN32_NATIVE
1038 /* On DOS and Windows, nm is absolute if a drive name was specified; 1026 /* On DOS and Windows, nm is absolute if a drive name was specified;
1039 use the drive's current directory as the prefix if needed. */ 1027 use the drive's current directory as the prefix if needed. */
1040 if (!newdir && drive) 1028 if (!newdir && drive)
1041 { 1029 {
1042 /* Get default directory if needed to make nm absolute. */ 1030 /* Get default directory if needed to make nm absolute. */
1043 if (!IS_DIRECTORY_SEP (nm[0])) 1031 if (!IS_DIRECTORY_SEP (nm[0]))
1044 { 1032 {
1045 newdir = alloca (MAXPATHLEN + 1); 1033 newdir = alloca (MAXPATHLEN + 1);
1046 if (!getdefdir (toupper (drive) - 'A' + 1, newdir)) 1034 if (!_getdcwd (toupper (drive) - 'A' + 1, newdir, MAXPATHLEN))
1047 newdir = NULL; 1035 newdir = NULL;
1048 } 1036 }
1049 if (!newdir) 1037 if (!newdir)
1050 { 1038 {
1051 /* Either nm starts with /, or drive isn't mounted. */ 1039 /* Either nm starts with /, or drive isn't mounted. */
1054 newdir[1] = ':'; 1042 newdir[1] = ':';
1055 newdir[2] = '/'; 1043 newdir[2] = '/';
1056 newdir[3] = 0; 1044 newdir[3] = 0;
1057 } 1045 }
1058 } 1046 }
1059 #endif /* WINDOWSNT */ 1047 #endif /* WIN32_NATIVE */
1060 1048
1061 /* Finally, if no prefix has been specified and nm is not absolute, 1049 /* Finally, if no prefix has been specified and nm is not absolute,
1062 then it must be expanded relative to default_directory. */ 1050 then it must be expanded relative to default_directory. */
1063 1051
1064 if (1 1052 if (1
1065 #ifndef WINDOWSNT 1053 #ifndef WIN32_NATIVE
1066 /* /... alone is not absolute on DOS and Windows. */ 1054 /* /... alone is not absolute on DOS and Windows. */
1067 && !IS_DIRECTORY_SEP (nm[0]) 1055 && !IS_DIRECTORY_SEP (nm[0])
1068 #else 1056 #else
1069 && !(IS_DIRECTORY_SEP (nm[0]) && IS_DIRECTORY_SEP (nm[1])) 1057 && !(IS_DIRECTORY_SEP (nm[0]) && IS_DIRECTORY_SEP (nm[1]))
1070 #endif 1058 #endif
1071 && !newdir) 1059 && !newdir)
1072 { 1060 {
1073 newdir = XSTRING_DATA (default_directory); 1061 newdir = XSTRING_DATA (default_directory);
1074 } 1062 }
1075 1063
1076 #ifdef WINDOWSNT 1064 #ifdef WIN32_NATIVE
1077 if (newdir) 1065 if (newdir)
1078 { 1066 {
1079 /* First ensure newdir is an absolute name. */ 1067 /* First ensure newdir is an absolute name. */
1080 if ( 1068 if (
1081 /* Detect MSDOS file names with drive specifiers. */ 1069 /* Detect Windows file names with drive specifiers. */
1082 ! (IS_DRIVE (newdir[0]) 1070 ! (IS_DRIVE (newdir[0])
1083 && IS_DEVICE_SEP (newdir[1]) && IS_DIRECTORY_SEP (newdir[2])) 1071 && IS_DEVICE_SEP (newdir[1]) && IS_DIRECTORY_SEP (newdir[2]))
1084 /* Detect Windows file names in UNC format. */ 1072 /* Detect Windows file names in UNC format. */
1085 && ! (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1])) 1073 && ! (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1]))
1086 /* Detect drive spec by itself */ 1074 /* Detect drive spec by itself */
1106 nm = tmp; 1094 nm = tmp;
1107 } 1095 }
1108 newdir = alloca (MAXPATHLEN + 1); 1096 newdir = alloca (MAXPATHLEN + 1);
1109 if (drive) 1097 if (drive)
1110 { 1098 {
1111 if (!getdefdir (toupper (drive) - 'A' + 1, newdir)) 1099 if (!_getdcwd (toupper (drive) - 'A' + 1, newdir, MAXPATHLEN))
1112 newdir = "/"; 1100 newdir = "/";
1113 } 1101 }
1114 else 1102 else
1115 getwd (newdir); 1103 getwd (newdir);
1116 } 1104 }
1137 } 1125 }
1138 else 1126 else
1139 newdir = ""; 1127 newdir = "";
1140 } 1128 }
1141 } 1129 }
1142 #endif /* WINDOWSNT */ 1130 #endif /* WIN32_NATIVE */
1143 1131
1144 if (newdir) 1132 if (newdir)
1145 { 1133 {
1146 /* Get rid of any slash at the end of newdir, unless newdir is 1134 /* Get rid of any slash at the end of newdir, unless newdir is
1147 just // (an incomplete UNC name). */ 1135 just // (an incomplete UNC name). */
1148 length = strlen ((char *) newdir); 1136 length = strlen ((char *) newdir);
1149 if (length > 1 && IS_DIRECTORY_SEP (newdir[length - 1]) 1137 if (length > 1 && IS_DIRECTORY_SEP (newdir[length - 1])
1150 #ifdef WINDOWSNT 1138 #ifdef WIN32_NATIVE
1151 && !(length == 2 && IS_DIRECTORY_SEP (newdir[0])) 1139 && !(length == 2 && IS_DIRECTORY_SEP (newdir[0]))
1152 #endif 1140 #endif
1153 ) 1141 )
1154 { 1142 {
1155 Bufbyte *temp = (Bufbyte *) alloca (length); 1143 Bufbyte *temp = (Bufbyte *) alloca (length);
1162 else 1150 else
1163 tlen = 0; 1151 tlen = 0;
1164 1152
1165 /* Now concatenate the directory and name to new space in the stack frame */ 1153 /* Now concatenate the directory and name to new space in the stack frame */
1166 tlen += strlen ((char *) nm) + 1; 1154 tlen += strlen ((char *) nm) + 1;
1167 #ifdef WINDOWSNT 1155 #ifdef WIN32_NATIVE
1168 /* Add reserved space for drive name. (The Microsoft x86 compiler 1156 /* Add reserved space for drive name. (The Microsoft x86 compiler
1169 produces incorrect code if the following two lines are combined.) */ 1157 produces incorrect code if the following two lines are combined.) */
1170 target = (Bufbyte *) alloca (tlen + 2); 1158 target = (Bufbyte *) alloca (tlen + 2);
1171 target += 2; 1159 target += 2;
1172 #else /* not WINDOWSNT */ 1160 #else /* not WIN32_NATIVE */
1173 target = (Bufbyte *) alloca (tlen); 1161 target = (Bufbyte *) alloca (tlen);
1174 #endif /* not WINDOWSNT */ 1162 #endif /* not WIN32_NATIVE */
1175 *target = 0; 1163 *target = 0;
1176 1164
1177 if (newdir) 1165 if (newdir)
1178 { 1166 {
1179 if (nm[0] == 0 || IS_DIRECTORY_SEP (nm[0])) 1167 if (nm[0] == 0 || IS_DIRECTORY_SEP (nm[0]))
1218 /* Keep initial / only if this is the whole name. */ 1206 /* Keep initial / only if this is the whole name. */
1219 if (o == target && IS_ANY_SEP (*o) && p[3] == 0) 1207 if (o == target && IS_ANY_SEP (*o) && p[3] == 0)
1220 ++o; 1208 ++o;
1221 p += 3; 1209 p += 3;
1222 } 1210 }
1223 #ifdef WINDOWSNT 1211 #ifdef WIN32_NATIVE
1224 /* if drive is set, we're not dealing with an UNC, so 1212 /* if drive is set, we're not dealing with an UNC, so
1225 multiple dir-seps are redundant (and reportedly cause trouble 1213 multiple dir-seps are redundant (and reportedly cause trouble
1226 under win95) */ 1214 under win95) */
1227 else if (drive && IS_DIRECTORY_SEP (p[0]) && IS_DIRECTORY_SEP (p[1])) 1215 else if (drive && IS_DIRECTORY_SEP (p[0]) && IS_DIRECTORY_SEP (p[1]))
1228 ++p; 1216 ++p;
1231 { 1219 {
1232 *o++ = *p++; 1220 *o++ = *p++;
1233 } 1221 }
1234 } 1222 }
1235 1223
1236 #ifdef WINDOWSNT 1224 #ifdef WIN32_NATIVE
1237 /* At last, set drive name, except for network file name. */ 1225 /* At last, set drive name, except for network file name. */
1238 if (drive) 1226 if (drive)
1239 { 1227 {
1240 target -= 2; 1228 target -= 2;
1241 target[0] = DRIVE_LETTER (drive); 1229 target[0] = DRIVE_LETTER (drive);
1244 else 1232 else
1245 { 1233 {
1246 assert (IS_DIRECTORY_SEP (target[0]) && IS_DIRECTORY_SEP (target[1])); 1234 assert (IS_DIRECTORY_SEP (target[0]) && IS_DIRECTORY_SEP (target[1]));
1247 } 1235 }
1248 CORRECT_DIR_SEPS (target); 1236 CORRECT_DIR_SEPS (target);
1249 #endif /* WINDOWSNT */ 1237 #endif /* WIN32_NATIVE */
1250 1238
1251 return make_string (target, o - target); 1239 return make_string (target, o - target);
1252 } 1240 }
1253 1241
1254 DEFUN ("file-truename", Ffile_truename, 1, 2, 0, /* 1242 DEFUN ("file-truename", Ffile_truename, 1, 2, 0, /*
1426 /* If /~ or // appears, discard everything through first slash. */ 1414 /* If /~ or // appears, discard everything through first slash. */
1427 1415
1428 for (p = nm; p != endp; p++) 1416 for (p = nm; p != endp; p++)
1429 { 1417 {
1430 if ((p[0] == '~' 1418 if ((p[0] == '~'
1431 #if defined (WINDOWSNT) || defined (__CYGWIN32__) 1419 #if defined (WIN32_NATIVE) || defined (CYGWIN)
1432 /* // at start of file name is meaningful in WindowsNT systems */ 1420 /* // at start of file name is meaningful in WindowsNT systems */
1433 || (IS_DIRECTORY_SEP (p[0]) && p - 1 != nm) 1421 || (IS_DIRECTORY_SEP (p[0]) && p - 1 != nm)
1434 #else /* not (WINDOWSNT || __CYGWIN32__) */ 1422 #else /* not (WIN32_NATIVE || CYGWIN) */
1435 || IS_DIRECTORY_SEP (p[0]) 1423 || IS_DIRECTORY_SEP (p[0])
1436 #endif /* not (WINDOWSNT || __CYGWIN32__) */ 1424 #endif /* not (WIN32_NATIVE || CYGWIN) */
1437 ) 1425 )
1438 && p != nm 1426 && p != nm
1439 && (IS_DIRECTORY_SEP (p[-1]))) 1427 && (IS_DIRECTORY_SEP (p[-1])))
1440 { 1428 {
1441 nm = p; 1429 nm = p;
1442 substituted = 1; 1430 substituted = 1;
1443 } 1431 }
1444 #ifdef WINDOWSNT 1432 #ifdef WIN32_NATIVE
1445 /* see comment in expand-file-name about drive specifiers */ 1433 /* see comment in expand-file-name about drive specifiers */
1446 else if (IS_DRIVE (p[0]) && p[1] == ':' 1434 else if (IS_DRIVE (p[0]) && p[1] == ':'
1447 && p > nm && IS_DIRECTORY_SEP (p[-1])) 1435 && p > nm && IS_DIRECTORY_SEP (p[-1]))
1448 { 1436 {
1449 nm = p; 1437 nm = p;
1450 substituted = 1; 1438 substituted = 1;
1451 } 1439 }
1452 #endif /* WINDOWSNT */ 1440 #endif /* WIN32_NATIVE */
1453 } 1441 }
1454 1442
1455 /* See if any variables are substituted into the string 1443 /* See if any variables are substituted into the string
1456 and find the total length of their values in `total' */ 1444 and find the total length of their values in `total' */
1457 1445
1487 1475
1488 /* Copy out the variable name */ 1476 /* Copy out the variable name */
1489 target = (Bufbyte *) alloca (s - o + 1); 1477 target = (Bufbyte *) alloca (s - o + 1);
1490 strncpy ((char *) target, (char *) o, s - o); 1478 strncpy ((char *) target, (char *) o, s - o);
1491 target[s - o] = 0; 1479 target[s - o] = 0;
1492 #ifdef WINDOWSNT 1480 #ifdef WIN32_NATIVE
1493 strupr (target); /* $home == $HOME etc. */ 1481 strupr (target); /* $home == $HOME etc. */
1494 #endif /* WINDOWSNT */ 1482 #endif /* WIN32_NATIVE */
1495 1483
1496 /* Get variable value */ 1484 /* Get variable value */
1497 o = (Bufbyte *) egetenv ((char *) target); 1485 o = (Bufbyte *) egetenv ((char *) target);
1498 if (!o) goto badvar; 1486 if (!o) goto badvar;
1499 total += strlen ((char *) o); 1487 total += strlen ((char *) o);
1538 1526
1539 /* Copy out the variable name */ 1527 /* Copy out the variable name */
1540 target = (Bufbyte *) alloca (s - o + 1); 1528 target = (Bufbyte *) alloca (s - o + 1);
1541 strncpy ((char *) target, (char *) o, s - o); 1529 strncpy ((char *) target, (char *) o, s - o);
1542 target[s - o] = 0; 1530 target[s - o] = 0;
1543 #ifdef WINDOWSNT 1531 #ifdef WIN32_NATIVE
1544 strupr (target); /* $home == $HOME etc. */ 1532 strupr (target); /* $home == $HOME etc. */
1545 #endif /* WINDOWSNT */ 1533 #endif /* WIN32_NATIVE */
1546 1534
1547 /* Get variable value */ 1535 /* Get variable value */
1548 o = (Bufbyte *) egetenv ((char *) target); 1536 o = (Bufbyte *) egetenv ((char *) target);
1549 if (!o) 1537 if (!o)
1550 goto badvar; 1538 goto badvar;
1557 1545
1558 /* If /~ or // appears, discard everything through first slash. */ 1546 /* If /~ or // appears, discard everything through first slash. */
1559 1547
1560 for (p = xnm; p != x; p++) 1548 for (p = xnm; p != x; p++)
1561 if ((p[0] == '~' 1549 if ((p[0] == '~'
1562 #if defined (WINDOWSNT) 1550 #if defined (WIN32_NATIVE)
1563 || (IS_DIRECTORY_SEP (p[0]) && p - 1 != xnm) 1551 || (IS_DIRECTORY_SEP (p[0]) && p - 1 != xnm)
1564 #else /* not WINDOWSNT */ 1552 #else /* not WIN32_NATIVE */
1565 || IS_DIRECTORY_SEP (p[0]) 1553 || IS_DIRECTORY_SEP (p[0])
1566 #endif /* not WINDOWSNT */ 1554 #endif /* not WIN32_NATIVE */
1567 ) 1555 )
1568 /* don't do p[-1] if that would go off the beginning --jwz */ 1556 /* don't do p[-1] if that would go off the beginning --jwz */
1569 && p != nm && p > xnm && IS_DIRECTORY_SEP (p[-1])) 1557 && p != nm && p > xnm && IS_DIRECTORY_SEP (p[-1]))
1570 xnm = p; 1558 xnm = p;
1571 #ifdef WINDOWSNT 1559 #ifdef WIN32_NATIVE
1572 else if (IS_DRIVE (p[0]) && p[1] == ':' 1560 else if (IS_DRIVE (p[0]) && p[1] == ':'
1573 && p > nm && IS_DIRECTORY_SEP (p[-1])) 1561 && p > nm && IS_DIRECTORY_SEP (p[-1]))
1574 xnm = p; 1562 xnm = p;
1575 #endif 1563 #endif
1576 1564
1741 1729
1742 /* We can only copy regular files and symbolic links. Other files are not 1730 /* We can only copy regular files and symbolic links. Other files are not
1743 copyable by us. */ 1731 copyable by us. */
1744 input_file_statable_p = (fstat (ifd, &st) >= 0); 1732 input_file_statable_p = (fstat (ifd, &st) >= 0);
1745 1733
1746 #ifndef WINDOWSNT 1734 #ifndef WIN32_NATIVE
1747 if (out_st.st_mode != 0 1735 if (out_st.st_mode != 0
1748 && st.st_dev == out_st.st_dev && st.st_ino == out_st.st_ino) 1736 && st.st_dev == out_st.st_dev && st.st_ino == out_st.st_ino)
1749 { 1737 {
1750 errno = 0; 1738 errno = 0;
1751 report_file_error ("Input and output files are the same", 1739 report_file_error ("Input and output files are the same",
1979 || INTP (ok_if_already_exists)) 1967 || INTP (ok_if_already_exists))
1980 barf_or_query_if_file_exists (newname, "rename to it", 1968 barf_or_query_if_file_exists (newname, "rename to it",
1981 INTP (ok_if_already_exists), 0); 1969 INTP (ok_if_already_exists), 0);
1982 1970
1983 /* Syncing with FSF 19.34.6 note: FSF does not have conditional code for 1971 /* Syncing with FSF 19.34.6 note: FSF does not have conditional code for
1984 WINDOWSNT here; I've removed it. --marcpa */ 1972 WIN32_NATIVE here; I've removed it. --marcpa */
1985 1973
1986 /* FSFmacs only calls rename() here under BSD 4.1, and calls 1974 /* We have configure check for rename() and emulate using
1987 link() and unlink() otherwise, but that's bogus. Sometimes 1975 link()/unlink() if necessary. */
1988 rename() succeeds where link()/unlink() fail, and we have
1989 configure check for rename() and emulate using link()/unlink()
1990 if necessary. */
1991 if (0 > rename ((char *) XSTRING_DATA (filename), 1976 if (0 > rename ((char *) XSTRING_DATA (filename),
1992 (char *) XSTRING_DATA (newname))) 1977 (char *) XSTRING_DATA (newname)))
1993 { 1978 {
1994 if (errno == EXDEV) 1979 if (errno == EXDEV)
1995 { 1980 {
2050 /* Syncing with FSF 19.34.6 note: FSF does not report a file error 2035 /* Syncing with FSF 19.34.6 note: FSF does not report a file error
2051 on NT here. --marcpa */ 2036 on NT here. --marcpa */
2052 /* But FSF #defines link as sys_link which is supplied in nt.c. We can't do 2037 /* But FSF #defines link as sys_link which is supplied in nt.c. We can't do
2053 that because sysfile.h defines sys_link depending on ENCAPSULATE_LINK. 2038 that because sysfile.h defines sys_link depending on ENCAPSULATE_LINK.
2054 Reverted to previous behavior pending a working fix. (jhar) */ 2039 Reverted to previous behavior pending a working fix. (jhar) */
2055 #if defined(WINDOWSNT) 2040 #if defined(WIN32_NATIVE)
2056 /* Windows does not support this operation. */ 2041 /* Windows does not support this operation. */
2057 report_file_error ("Adding new name", Flist (2, &filename)); 2042 report_file_error ("Adding new name", Flist (2, &filename));
2058 #else /* not defined(WINDOWSNT) */ 2043 #else /* not defined(WIN32_NATIVE) */
2059 2044
2060 unlink ((char *) XSTRING_DATA (newname)); 2045 unlink ((char *) XSTRING_DATA (newname));
2061 if (0 > link ((char *) XSTRING_DATA (filename), 2046 if (0 > link ((char *) XSTRING_DATA (filename),
2062 (char *) XSTRING_DATA (newname))) 2047 (char *) XSTRING_DATA (newname)))
2063 { 2048 {
2064 report_file_error ("Adding new name", 2049 report_file_error ("Adding new name",
2065 list2 (filename, newname)); 2050 list2 (filename, newname));
2066 } 2051 }
2067 #endif /* defined(WINDOWSNT) */ 2052 #endif /* defined(WIN32_NATIVE) */
2068 2053
2069 UNGCPRO; 2054 UNGCPRO;
2070 return Qnil; 2055 return Qnil;
2071 } 2056 }
2072 2057
2164 Bufbyte *ptr; 2149 Bufbyte *ptr;
2165 2150
2166 CHECK_STRING (filename); 2151 CHECK_STRING (filename);
2167 ptr = XSTRING_DATA (filename); 2152 ptr = XSTRING_DATA (filename);
2168 return (IS_DIRECTORY_SEP (*ptr) || *ptr == '~' 2153 return (IS_DIRECTORY_SEP (*ptr) || *ptr == '~'
2169 #ifdef WINDOWSNT 2154 #ifdef WIN32_NATIVE
2170 || (IS_DRIVE (*ptr) && ptr[1] == ':' && IS_DIRECTORY_SEP (ptr[2])) 2155 || (IS_DRIVE (*ptr) && ptr[1] == ':' && IS_DIRECTORY_SEP (ptr[2]))
2171 #endif 2156 #endif
2172 ) ? Qt : Qnil; 2157 ) ? Qt : Qnil;
2173 } 2158 }
2174 2159
2175 /* Return nonzero if file FILENAME exists and can be executed. */ 2160 /* Return nonzero if file FILENAME exists and can be executed. */
2176 2161
2177 static int 2162 static int
2178 check_executable (char *filename) 2163 check_executable (char *filename)
2179 { 2164 {
2180 #ifdef WINDOWSNT 2165 #ifdef WIN32_NATIVE
2181 struct stat st; 2166 struct stat st;
2182 if (stat (filename, &st) < 0) 2167 if (stat (filename, &st) < 0)
2183 return 0; 2168 return 0;
2184 return ((st.st_mode & S_IEXEC) != 0); 2169 return ((st.st_mode & S_IEXEC) != 0);
2185 #else /* not WINDOWSNT */ 2170 #else /* not WIN32_NATIVE */
2186 #ifdef HAVE_EACCESS 2171 #ifdef HAVE_EACCESS
2187 return eaccess (filename, 1) >= 0; 2172 return eaccess (filename, 1) >= 0;
2188 #else 2173 #else
2189 /* Access isn't quite right because it uses the real uid 2174 /* Access isn't quite right because it uses the real uid
2190 and we really want to test with the effective uid. 2175 and we really want to test with the effective uid.
2191 But Unix doesn't give us a right way to do it. */ 2176 But Unix doesn't give us a right way to do it. */
2192 return access (filename, 1) >= 0; 2177 return access (filename, 1) >= 0;
2193 #endif /* HAVE_EACCESS */ 2178 #endif /* HAVE_EACCESS */
2194 #endif /* not WINDOWSNT */ 2179 #endif /* not WIN32_NATIVE */
2195 } 2180 }
2196 2181
2197 /* Return nonzero if file FILENAME exists and can be written. */ 2182 /* Return nonzero if file FILENAME exists and can be written. */
2198 2183
2199 static int 2184 static int
2282 call the corresponding file handler. */ 2267 call the corresponding file handler. */
2283 handler = Ffind_file_name_handler (abspath, Qfile_readable_p); 2268 handler = Ffind_file_name_handler (abspath, Qfile_readable_p);
2284 if (!NILP (handler)) 2269 if (!NILP (handler))
2285 RETURN_UNGCPRO (call2 (handler, Qfile_readable_p, abspath)); 2270 RETURN_UNGCPRO (call2 (handler, Qfile_readable_p, abspath));
2286 2271
2287 #if defined(WINDOWSNT) || defined(__CYGWIN32__) 2272 #if defined(WIN32_NATIVE) || defined(CYGWIN)
2288 /* Under MS-DOS and Windows, open does not work for directories. */ 2273 /* Under MS-DOS and Windows, open does not work for directories. */
2289 UNGCPRO; 2274 UNGCPRO;
2290 if (access (XSTRING_DATA (abspath), 0) == 0) 2275 if (access (XSTRING_DATA (abspath), 0) == 0)
2291 return Qt; 2276 return Qt;
2292 else 2277 else
2293 return Qnil; 2278 return Qnil;
2294 #else /* not WINDOWSNT */ 2279 #else /* not WIN32_NATIVE */
2295 { 2280 {
2296 int desc = interruptible_open ((char *) XSTRING_DATA (abspath), O_RDONLY | OPEN_BINARY, 0); 2281 int desc = interruptible_open ((char *) XSTRING_DATA (abspath), O_RDONLY | OPEN_BINARY, 0);
2297 UNGCPRO; 2282 UNGCPRO;
2298 if (desc < 0) 2283 if (desc < 0)
2299 return Qnil; 2284 return Qnil;
2300 close (desc); 2285 close (desc);
2301 return Qt; 2286 return Qt;
2302 } 2287 }
2303 #endif /* not WINDOWSNT */ 2288 #endif /* not WIN32_NATIVE */
2304 } 2289 }
2305 2290
2306 /* Having this before file-symlink-p mysteriously caused it to be forgotten 2291 /* Having this before file-symlink-p mysteriously caused it to be forgotten
2307 on the RT/PC. */ 2292 on the RT/PC. */
2308 DEFUN ("file-writable-p", Ffile_writable_p, 1, 1, 0, /* 2293 DEFUN ("file-writable-p", Ffile_writable_p, 1, 1, 0, /*
2443 handler = Ffind_file_name_handler (filename, Qfile_accessible_directory_p); 2428 handler = Ffind_file_name_handler (filename, Qfile_accessible_directory_p);
2444 if (!NILP (handler)) 2429 if (!NILP (handler))
2445 return call2 (handler, Qfile_accessible_directory_p, 2430 return call2 (handler, Qfile_accessible_directory_p,
2446 filename); 2431 filename);
2447 2432
2448 #if !defined(WINDOWSNT) 2433 #if !defined(WIN32_NATIVE)
2449 if (NILP (Ffile_directory_p (filename))) 2434 if (NILP (Ffile_directory_p (filename)))
2450 return (Qnil); 2435 return (Qnil);
2451 else 2436 else
2452 return Ffile_executable_p (filename); 2437 return Ffile_executable_p (filename);
2453 #else 2438 #else
2464 tem = (NILP (Ffile_directory_p (filename)) 2449 tem = (NILP (Ffile_directory_p (filename))
2465 || NILP (Ffile_executable_p (filename))); 2450 || NILP (Ffile_executable_p (filename)));
2466 UNGCPRO; 2451 UNGCPRO;
2467 return tem ? Qnil : Qt; 2452 return tem ? Qnil : Qt;
2468 } 2453 }
2469 #endif /* !defined(WINDOWSNT) */ 2454 #endif /* !defined(WIN32_NATIVE) */
2470 } 2455 }
2471 2456
2472 DEFUN ("file-regular-p", Ffile_regular_p, 1, 1, 0, /* 2457 DEFUN ("file-regular-p", Ffile_regular_p, 1, 1, 0, /*
2473 Return t if file FILENAME is the name of a regular file. 2458 Return t if file FILENAME is the name of a regular file.
2474 This is the sort of file that holds an ordinary stream of data bytes. 2459 This is the sort of file that holds an ordinary stream of data bytes.
2524 2509
2525 if (stat ((char *) XSTRING_DATA (abspath), &st) < 0) 2510 if (stat ((char *) XSTRING_DATA (abspath), &st) < 0)
2526 return Qnil; 2511 return Qnil;
2527 /* Syncing with FSF 19.34.6 note: not in FSF, #if 0'ed out here. */ 2512 /* Syncing with FSF 19.34.6 note: not in FSF, #if 0'ed out here. */
2528 #if 0 2513 #if 0
2529 #ifdef DOS_NT 2514 #ifdef WIN32_NATIVE
2530 if (check_executable (XSTRING_DATA (abspath))) 2515 if (check_executable (XSTRING_DATA (abspath)))
2531 st.st_mode |= S_IEXEC; 2516 st.st_mode |= S_IEXEC;
2532 #endif /* DOS_NT */ 2517 #endif /* WIN32_NATIVE */
2533 #endif /* 0 */ 2518 #endif /* 0 */
2534 2519
2535 return make_int (st.st_mode & 07777); 2520 return make_int (st.st_mode & 07777);
2536 } 2521 }
2537 2522
2601 DEFUN ("unix-sync", Funix_sync, 0, 0, "", /* 2586 DEFUN ("unix-sync", Funix_sync, 0, 0, "", /*
2602 Tell Unix to finish all pending disk updates. 2587 Tell Unix to finish all pending disk updates.
2603 */ 2588 */
2604 ()) 2589 ())
2605 { 2590 {
2606 #ifndef WINDOWSNT 2591 #ifndef WIN32_NATIVE
2607 sync (); 2592 sync ();
2608 #endif 2593 #endif
2609 return Qnil; 2594 return Qnil;
2610 } 2595 }
2611 2596
4309 The value should be either ?/ or ?\\ (any other value is treated as ?\\). 4294 The value should be either ?/ or ?\\ (any other value is treated as ?\\).
4310 This variable affects the built-in functions only on Windows, 4295 This variable affects the built-in functions only on Windows,
4311 on other platforms, it is initialized so that Lisp code can find out 4296 on other platforms, it is initialized so that Lisp code can find out
4312 what the normal separator is. 4297 what the normal separator is.
4313 */ ); 4298 */ );
4314 #ifdef WINDOWSNT 4299 #ifdef WIN32_NATIVE
4315 Vdirectory_sep_char = make_char ('\\'); 4300 Vdirectory_sep_char = make_char ('\\');
4316 #else 4301 #else
4317 Vdirectory_sep_char = make_char ('/'); 4302 Vdirectory_sep_char = make_char ('/');
4318 #endif 4303 #endif
4319 4304