diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 7 | ||||
| -rw-r--r-- | src/lread.c | 55 |
2 files changed, 40 insertions, 22 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 7add267368d..d69f9794eb6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2002-03-29 Eli Zaretskii <eliz@is.elta.co.il> | ||
| 2 | |||
| 3 | * lread.c (openp, Fload): Encode the file name before pasing it | ||
| 4 | to `stat', `access', and `emacs_open'. | ||
| 5 | (openp): GCPRO the encoded file name. Don't recompute Lisp | ||
| 6 | strings unnecessarily. | ||
| 7 | |||
| 1 | 2002-03-29 Kim F. Storm <storm@cua.dk> | 8 | 2002-03-29 Kim F. Storm <storm@cua.dk> |
| 2 | 9 | ||
| 3 | * fns.c (Flax_plist_put): Doc fix. | 10 | * fns.c (Flax_plist_put): Doc fix. |
diff --git a/src/lread.c b/src/lread.c index 81ae1f27a55..86b79fbad30 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -34,6 +34,7 @@ Boston, MA 02111-1307, USA. */ | |||
| 34 | #include "commands.h" | 34 | #include "commands.h" |
| 35 | #include "keyboard.h" | 35 | #include "keyboard.h" |
| 36 | #include "termhooks.h" | 36 | #include "termhooks.h" |
| 37 | #include "coding.h" | ||
| 37 | 38 | ||
| 38 | #ifdef lint | 39 | #ifdef lint |
| 39 | #include <sys/inode.h> | 40 | #include <sys/inode.h> |
| @@ -633,7 +634,7 @@ Return t if file exists. */) | |||
| 633 | int count = specpdl_ptr - specpdl; | 634 | int count = specpdl_ptr - specpdl; |
| 634 | Lisp_Object temp; | 635 | Lisp_Object temp; |
| 635 | struct gcpro gcpro1; | 636 | struct gcpro gcpro1; |
| 636 | Lisp_Object found; | 637 | Lisp_Object found, efound; |
| 637 | /* 1 means we printed the ".el is newer" message. */ | 638 | /* 1 means we printed the ".el is newer" message. */ |
| 638 | int newer = 0; | 639 | int newer = 0; |
| 639 | /* 1 means we are loading a compiled file. */ | 640 | /* 1 means we are loading a compiled file. */ |
| @@ -770,14 +771,18 @@ Return t if file exists. */) | |||
| 770 | 771 | ||
| 771 | compiled = 1; | 772 | compiled = 1; |
| 772 | 773 | ||
| 774 | GCPRO1 (efound); | ||
| 775 | efound = ENCODE_FILE (found); | ||
| 776 | |||
| 773 | #ifdef DOS_NT | 777 | #ifdef DOS_NT |
| 774 | fmode = "rb"; | 778 | fmode = "rb"; |
| 775 | #endif /* DOS_NT */ | 779 | #endif /* DOS_NT */ |
| 776 | stat ((char *)XSTRING (found)->data, &s1); | 780 | stat ((char *)XSTRING (efound)->data, &s1); |
| 777 | XSTRING (found)->data[STRING_BYTES (XSTRING (found)) - 1] = 0; | 781 | XSTRING (efound)->data[STRING_BYTES (XSTRING (efound)) - 1] = 0; |
| 778 | result = stat ((char *)XSTRING (found)->data, &s2); | 782 | result = stat ((char *)XSTRING (efound)->data, &s2); |
| 779 | XSTRING (found)->data[STRING_BYTES (XSTRING (found)) - 1] = 'c'; | 783 | XSTRING (efound)->data[STRING_BYTES (XSTRING (efound)) - 1] = 'c'; |
| 780 | 784 | UNGCPRO; | |
| 785 | |||
| 781 | if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime) | 786 | if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime) |
| 782 | { | 787 | { |
| 783 | /* Make the progress messages mention that source is newer. */ | 788 | /* Make the progress messages mention that source is newer. */ |
| @@ -812,7 +817,10 @@ Return t if file exists. */) | |||
| 812 | 817 | ||
| 813 | #ifdef WINDOWSNT | 818 | #ifdef WINDOWSNT |
| 814 | emacs_close (fd); | 819 | emacs_close (fd); |
| 815 | stream = fopen ((char *) XSTRING (found)->data, fmode); | 820 | GCPRO1 (efound); |
| 821 | efound = ENCODE_FILE (found); | ||
| 822 | stream = fopen ((char *) XSTRING (efound)->data, fmode); | ||
| 823 | UNGCPRO; | ||
| 816 | #else /* not WINDOWSNT */ | 824 | #else /* not WINDOWSNT */ |
| 817 | stream = fdopen (fd, fmode); | 825 | stream = fdopen (fd, fmode); |
| 818 | #endif /* not WINDOWSNT */ | 826 | #endif /* not WINDOWSNT */ |
| @@ -968,8 +976,8 @@ openp (path, str, suffixes, storeptr, exec_only) | |||
| 968 | int want_size; | 976 | int want_size; |
| 969 | Lisp_Object filename; | 977 | Lisp_Object filename; |
| 970 | struct stat st; | 978 | struct stat st; |
| 971 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; | 979 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; |
| 972 | Lisp_Object string, tail; | 980 | Lisp_Object string, tail, encoded_fn; |
| 973 | int max_suffix_len = 0; | 981 | int max_suffix_len = 0; |
| 974 | 982 | ||
| 975 | for (tail = suffixes; CONSP (tail); tail = XCDR (tail)) | 983 | for (tail = suffixes; CONSP (tail); tail = XCDR (tail)) |
| @@ -980,8 +988,8 @@ openp (path, str, suffixes, storeptr, exec_only) | |||
| 980 | } | 988 | } |
| 981 | 989 | ||
| 982 | string = filename = Qnil; | 990 | string = filename = Qnil; |
| 983 | GCPRO5 (str, string, filename, path, suffixes); | 991 | GCPRO6 (str, string, filename, path, suffixes, encoded_fn); |
| 984 | 992 | ||
| 985 | if (storeptr) | 993 | if (storeptr) |
| 986 | *storeptr = Qnil; | 994 | *storeptr = Qnil; |
| 987 | 995 | ||
| @@ -1014,6 +1022,7 @@ openp (path, str, suffixes, storeptr, exec_only) | |||
| 1014 | { | 1022 | { |
| 1015 | int lsuffix = STRING_BYTES (XSTRING (XCAR (tail))); | 1023 | int lsuffix = STRING_BYTES (XSTRING (XCAR (tail))); |
| 1016 | Lisp_Object handler; | 1024 | Lisp_Object handler; |
| 1025 | int exists; | ||
| 1017 | 1026 | ||
| 1018 | /* Concatenate path element/specified name with the suffix. | 1027 | /* Concatenate path element/specified name with the suffix. |
| 1019 | If the directory starts with /:, remove that. */ | 1028 | If the directory starts with /:, remove that. */ |
| @@ -1034,7 +1043,7 @@ openp (path, str, suffixes, storeptr, exec_only) | |||
| 1034 | 1043 | ||
| 1035 | if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */ | 1044 | if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */ |
| 1036 | strncat (fn, XSTRING (XCAR (tail))->data, lsuffix); | 1045 | strncat (fn, XSTRING (XCAR (tail))->data, lsuffix); |
| 1037 | 1046 | ||
| 1038 | /* Check that the file exists and is not a directory. */ | 1047 | /* Check that the file exists and is not a directory. */ |
| 1039 | /* We used to only check for handlers on non-absolute file names: | 1048 | /* We used to only check for handlers on non-absolute file names: |
| 1040 | if (absolute) | 1049 | if (absolute) |
| @@ -1044,41 +1053,43 @@ openp (path, str, suffixes, storeptr, exec_only) | |||
| 1044 | It's not clear why that was the case and it breaks things like | 1053 | It's not clear why that was the case and it breaks things like |
| 1045 | (load "/bar.el") where the file is actually "/bar.el.gz". */ | 1054 | (load "/bar.el") where the file is actually "/bar.el.gz". */ |
| 1046 | handler = Ffind_file_name_handler (filename, Qfile_exists_p); | 1055 | handler = Ffind_file_name_handler (filename, Qfile_exists_p); |
| 1056 | string = build_string (fn); | ||
| 1047 | if (!NILP (handler) && !exec_only) | 1057 | if (!NILP (handler) && !exec_only) |
| 1048 | { | 1058 | { |
| 1049 | int exists; | ||
| 1050 | |||
| 1051 | string = build_string (fn); | ||
| 1052 | exists = !NILP (Ffile_readable_p (string)); | 1059 | exists = !NILP (Ffile_readable_p (string)); |
| 1053 | if (exists && !NILP (Ffile_directory_p (build_string (fn)))) | 1060 | if (exists && !NILP (Ffile_directory_p (string))) |
| 1054 | exists = 0; | 1061 | exists = 0; |
| 1055 | 1062 | ||
| 1056 | if (exists) | 1063 | if (exists) |
| 1057 | { | 1064 | { |
| 1058 | /* We succeeded; return this descriptor and filename. */ | 1065 | /* We succeeded; return this descriptor and filename. */ |
| 1059 | if (storeptr) | 1066 | if (storeptr) |
| 1060 | *storeptr = build_string (fn); | 1067 | *storeptr = string; |
| 1061 | UNGCPRO; | 1068 | UNGCPRO; |
| 1062 | return -2; | 1069 | return -2; |
| 1063 | } | 1070 | } |
| 1064 | } | 1071 | } |
| 1065 | else | 1072 | else |
| 1066 | { | 1073 | { |
| 1067 | int exists = (stat (fn, &st) >= 0 | 1074 | char *pfn; |
| 1068 | && (st.st_mode & S_IFMT) != S_IFDIR); | 1075 | |
| 1076 | encoded_fn = ENCODE_FILE (string); | ||
| 1077 | pfn = XSTRING (encoded_fn)->data; | ||
| 1078 | exists = (stat (pfn, &st) >= 0 | ||
| 1079 | && (st.st_mode & S_IFMT) != S_IFDIR); | ||
| 1069 | if (exists) | 1080 | if (exists) |
| 1070 | { | 1081 | { |
| 1071 | /* Check that we can access or open it. */ | 1082 | /* Check that we can access or open it. */ |
| 1072 | if (exec_only) | 1083 | if (exec_only) |
| 1073 | fd = (access (fn, X_OK) == 0) ? 1 : -1; | 1084 | fd = (access (pfn, X_OK) == 0) ? 1 : -1; |
| 1074 | else | 1085 | else |
| 1075 | fd = emacs_open (fn, O_RDONLY, 0); | 1086 | fd = emacs_open (pfn, O_RDONLY, 0); |
| 1076 | 1087 | ||
| 1077 | if (fd >= 0) | 1088 | if (fd >= 0) |
| 1078 | { | 1089 | { |
| 1079 | /* We succeeded; return this descriptor and filename. */ | 1090 | /* We succeeded; return this descriptor and filename. */ |
| 1080 | if (storeptr) | 1091 | if (storeptr) |
| 1081 | *storeptr = build_string (fn); | 1092 | *storeptr = string; |
| 1082 | UNGCPRO; | 1093 | UNGCPRO; |
| 1083 | return fd; | 1094 | return fd; |
| 1084 | } | 1095 | } |