diff options
| author | Richard M. Stallman | 1997-09-11 00:00:01 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-09-11 00:00:01 +0000 |
| commit | b1d1b865a1b6fc190748a1f74bcc74a0d9ee5fd2 (patch) | |
| tree | 80e236627d08eed79e433250eed6f36de2ffe6bc /src | |
| parent | 222ef66ffdf276f91848895b949ced4b92e566c2 (diff) | |
| download | emacs-b1d1b865a1b6fc190748a1f74bcc74a0d9ee5fd2.tar.gz emacs-b1d1b865a1b6fc190748a1f74bcc74a0d9ee5fd2.zip | |
(ENCODE_FILE): New macro.
(Vfile_name_coding_system): New variable.
(syms_of_fileio): Set up Lisp variable.
(Fset_visited_file_modtime): Use ENCODE_FILE.
(Fcopy_file, Fmake_directory_internal, Fdelete_directory, Fdelete_file)
(Frename_file, Fadd_name_to_file, Ffile_exists_p Ffile_executable_p)
(Ffile_readable_p, Ffile_writable_p, Faccess_file, Ffile_symlink_p)
(Ffile_directory_p, Ffile_accessible_directory_p, Ffile_regular_p)
(Ffile_modes, Fset_file_modes, Ffile_newer_than_file_p, Fwrite_region)
(Finsert_file_contents, Fverify_visited_file_modtime): Likewise.
(Ffile_symlink_p): Decode the file name value.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 224 |
1 files changed, 158 insertions, 66 deletions
diff --git a/src/fileio.c b/src/fileio.c index 0f9eab17e7f..e23b74a1720 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -152,6 +152,14 @@ extern char *strerror (); | |||
| 152 | #define min(a, b) ((a) < (b) ? (a) : (b)) | 152 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
| 153 | #define max(a, b) ((a) > (b) ? (a) : (b)) | 153 | #define max(a, b) ((a) > (b) ? (a) : (b)) |
| 154 | 154 | ||
| 155 | /* Encode the file name NAME using the specified coding system | ||
| 156 | for file names, if any. */ | ||
| 157 | #define ENCODE_FILE(name) \ | ||
| 158 | (! NILP (Vfile_name_coding_system) \ | ||
| 159 | && XFASTINT (Vfile_name_coding_system) != 0 \ | ||
| 160 | ? Fencode_coding_string (name, Vfile_name_coding_system, Qt) \ | ||
| 161 | : name) | ||
| 162 | |||
| 155 | /* Nonzero during writing of auto-save files */ | 163 | /* Nonzero during writing of auto-save files */ |
| 156 | int auto_saving; | 164 | int auto_saving; |
| 157 | 165 | ||
| @@ -159,6 +167,9 @@ int auto_saving; | |||
| 159 | a new file with the same mode as the original */ | 167 | a new file with the same mode as the original */ |
| 160 | int auto_save_mode_bits; | 168 | int auto_save_mode_bits; |
| 161 | 169 | ||
| 170 | /* Coding system for file names, or nil if none. */ | ||
| 171 | Lisp_Object Vfile_name_coding_system; | ||
| 172 | |||
| 162 | /* Alist of elements (REGEXP . HANDLER) for file names | 173 | /* Alist of elements (REGEXP . HANDLER) for file names |
| 163 | whose I/O is done with a special handler. */ | 174 | whose I/O is done with a special handler. */ |
| 164 | Lisp_Object Vfile_name_handler_alist; | 175 | Lisp_Object Vfile_name_handler_alist; |
| @@ -2051,13 +2062,16 @@ A prefix arg makes KEEP-TIME non-nil.") | |||
| 2051 | char buf[16 * 1024]; | 2062 | char buf[16 * 1024]; |
| 2052 | struct stat st, out_st; | 2063 | struct stat st, out_st; |
| 2053 | Lisp_Object handler; | 2064 | Lisp_Object handler; |
| 2054 | struct gcpro gcpro1, gcpro2; | 2065 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
| 2055 | int count = specpdl_ptr - specpdl; | 2066 | int count = specpdl_ptr - specpdl; |
| 2056 | int input_file_statable_p; | 2067 | int input_file_statable_p; |
| 2068 | Lisp_Object encoded_file, encoded_newname; | ||
| 2057 | 2069 | ||
| 2058 | GCPRO2 (file, newname); | 2070 | encoded_file = encoded_newname = Qnil; |
| 2071 | GCPRO4 (file, newname, encoded_file, encoded_newname); | ||
| 2059 | CHECK_STRING (file, 0); | 2072 | CHECK_STRING (file, 0); |
| 2060 | CHECK_STRING (newname, 1); | 2073 | CHECK_STRING (newname, 1); |
| 2074 | |||
| 2061 | file = Fexpand_file_name (file, Qnil); | 2075 | file = Fexpand_file_name (file, Qnil); |
| 2062 | newname = Fexpand_file_name (newname, Qnil); | 2076 | newname = Fexpand_file_name (newname, Qnil); |
| 2063 | 2077 | ||
| @@ -2071,14 +2085,17 @@ A prefix arg makes KEEP-TIME non-nil.") | |||
| 2071 | RETURN_UNGCPRO (call5 (handler, Qcopy_file, file, newname, | 2085 | RETURN_UNGCPRO (call5 (handler, Qcopy_file, file, newname, |
| 2072 | ok_if_already_exists, keep_date)); | 2086 | ok_if_already_exists, keep_date)); |
| 2073 | 2087 | ||
| 2088 | encoded_file = ENCODE_FILE (file); | ||
| 2089 | encoded_newname = ENCODE_FILE (newname); | ||
| 2090 | |||
| 2074 | if (NILP (ok_if_already_exists) | 2091 | if (NILP (ok_if_already_exists) |
| 2075 | || INTEGERP (ok_if_already_exists)) | 2092 | || INTEGERP (ok_if_already_exists)) |
| 2076 | barf_or_query_if_file_exists (newname, "copy to it", | 2093 | barf_or_query_if_file_exists (encoded_newname, "copy to it", |
| 2077 | INTEGERP (ok_if_already_exists), &out_st); | 2094 | INTEGERP (ok_if_already_exists), &out_st); |
| 2078 | else if (stat (XSTRING (newname)->data, &out_st) < 0) | 2095 | else if (stat (XSTRING (encoded_newname)->data, &out_st) < 0) |
| 2079 | out_st.st_mode = 0; | 2096 | out_st.st_mode = 0; |
| 2080 | 2097 | ||
| 2081 | ifd = open (XSTRING (file)->data, O_RDONLY); | 2098 | ifd = open (XSTRING (encoded_file)->data, O_RDONLY); |
| 2082 | if (ifd < 0) | 2099 | if (ifd < 0) |
| 2083 | report_file_error ("Opening input file", Fcons (file, Qnil)); | 2100 | report_file_error ("Opening input file", Fcons (file, Qnil)); |
| 2084 | 2101 | ||
| @@ -2114,13 +2131,13 @@ A prefix arg makes KEEP-TIME non-nil.") | |||
| 2114 | 2131 | ||
| 2115 | #ifdef VMS | 2132 | #ifdef VMS |
| 2116 | /* Create the copy file with the same record format as the input file */ | 2133 | /* Create the copy file with the same record format as the input file */ |
| 2117 | ofd = sys_creat (XSTRING (newname)->data, 0666, ifd); | 2134 | ofd = sys_creat (XSTRING (encoded_newname)->data, 0666, ifd); |
| 2118 | #else | 2135 | #else |
| 2119 | #ifdef MSDOS | 2136 | #ifdef MSDOS |
| 2120 | /* System's default file type was set to binary by _fmode in emacs.c. */ | 2137 | /* System's default file type was set to binary by _fmode in emacs.c. */ |
| 2121 | ofd = creat (XSTRING (newname)->data, S_IREAD | S_IWRITE); | 2138 | ofd = creat (XSTRING (encoded_newname)->data, S_IREAD | S_IWRITE); |
| 2122 | #else /* not MSDOS */ | 2139 | #else /* not MSDOS */ |
| 2123 | ofd = creat (XSTRING (newname)->data, 0666); | 2140 | ofd = creat (XSTRING (encoded_newname)->data, 0666); |
| 2124 | #endif /* not MSDOS */ | 2141 | #endif /* not MSDOS */ |
| 2125 | #endif /* VMS */ | 2142 | #endif /* VMS */ |
| 2126 | if (ofd < 0) | 2143 | if (ofd < 0) |
| @@ -2146,13 +2163,14 @@ A prefix arg makes KEEP-TIME non-nil.") | |||
| 2146 | EMACS_TIME atime, mtime; | 2163 | EMACS_TIME atime, mtime; |
| 2147 | EMACS_SET_SECS_USECS (atime, st.st_atime, 0); | 2164 | EMACS_SET_SECS_USECS (atime, st.st_atime, 0); |
| 2148 | EMACS_SET_SECS_USECS (mtime, st.st_mtime, 0); | 2165 | EMACS_SET_SECS_USECS (mtime, st.st_mtime, 0); |
| 2149 | if (set_file_times (XSTRING (newname)->data, atime, mtime)) | 2166 | if (set_file_times (XSTRING (encoded_newname)->data, |
| 2167 | atime, mtime)) | ||
| 2150 | Fsignal (Qfile_date_error, | 2168 | Fsignal (Qfile_date_error, |
| 2151 | Fcons (build_string ("Cannot set file date"), | 2169 | Fcons (build_string ("Cannot set file date"), |
| 2152 | Fcons (newname, Qnil))); | 2170 | Fcons (newname, Qnil))); |
| 2153 | } | 2171 | } |
| 2154 | #ifndef MSDOS | 2172 | #ifndef MSDOS |
| 2155 | chmod (XSTRING (newname)->data, st.st_mode & 07777); | 2173 | chmod (XSTRING (encoded_newname)->data, st.st_mode & 07777); |
| 2156 | #else /* MSDOS */ | 2174 | #else /* MSDOS */ |
| 2157 | #if defined (__DJGPP__) && __DJGPP__ > 1 | 2175 | #if defined (__DJGPP__) && __DJGPP__ > 1 |
| 2158 | /* In DJGPP v2.0 and later, fstat usually returns true file mode bits, | 2176 | /* In DJGPP v2.0 and later, fstat usually returns true file mode bits, |
| @@ -2160,7 +2178,7 @@ A prefix arg makes KEEP-TIME non-nil.") | |||
| 2160 | get only the READ bit, which will make the copied file read-only, | 2178 | get only the READ bit, which will make the copied file read-only, |
| 2161 | so it's better not to chmod at all. */ | 2179 | so it's better not to chmod at all. */ |
| 2162 | if ((_djstat_flags & _STFAIL_WRITEBIT) == 0) | 2180 | if ((_djstat_flags & _STFAIL_WRITEBIT) == 0) |
| 2163 | chmod (XSTRING (newname)->data, st.st_mode & 07777); | 2181 | chmod (XSTRING (encoded_newname)->data, st.st_mode & 07777); |
| 2164 | #endif /* DJGPP version 2 or newer */ | 2182 | #endif /* DJGPP version 2 or newer */ |
| 2165 | #endif /* MSDOS */ | 2183 | #endif /* MSDOS */ |
| 2166 | } | 2184 | } |
| @@ -2182,6 +2200,7 @@ DEFUN ("make-directory-internal", Fmake_directory_internal, | |||
| 2182 | { | 2200 | { |
| 2183 | unsigned char *dir; | 2201 | unsigned char *dir; |
| 2184 | Lisp_Object handler; | 2202 | Lisp_Object handler; |
| 2203 | Lisp_Object encoded_dir; | ||
| 2185 | 2204 | ||
| 2186 | CHECK_STRING (directory, 0); | 2205 | CHECK_STRING (directory, 0); |
| 2187 | directory = Fexpand_file_name (directory, Qnil); | 2206 | directory = Fexpand_file_name (directory, Qnil); |
| @@ -2190,7 +2209,9 @@ DEFUN ("make-directory-internal", Fmake_directory_internal, | |||
| 2190 | if (!NILP (handler)) | 2209 | if (!NILP (handler)) |
| 2191 | return call2 (handler, Qmake_directory_internal, directory); | 2210 | return call2 (handler, Qmake_directory_internal, directory); |
| 2192 | 2211 | ||
| 2193 | dir = XSTRING (directory)->data; | 2212 | encoded_dir = ENCODE_FILE (directory); |
| 2213 | |||
| 2214 | dir = XSTRING (encoded_dir)->data; | ||
| 2194 | 2215 | ||
| 2195 | #ifdef WINDOWSNT | 2216 | #ifdef WINDOWSNT |
| 2196 | if (mkdir (dir) != 0) | 2217 | if (mkdir (dir) != 0) |
| @@ -2209,15 +2230,19 @@ DEFUN ("delete-directory", Fdelete_directory, Sdelete_directory, 1, 1, "FDelete | |||
| 2209 | { | 2230 | { |
| 2210 | unsigned char *dir; | 2231 | unsigned char *dir; |
| 2211 | Lisp_Object handler; | 2232 | Lisp_Object handler; |
| 2233 | Lisp_Object encoded_dir; | ||
| 2212 | 2234 | ||
| 2213 | CHECK_STRING (directory, 0); | 2235 | CHECK_STRING (directory, 0); |
| 2214 | directory = Fdirectory_file_name (Fexpand_file_name (directory, Qnil)); | 2236 | directory = Fdirectory_file_name (Fexpand_file_name (directory, Qnil)); |
| 2215 | dir = XSTRING (directory)->data; | ||
| 2216 | 2237 | ||
| 2217 | handler = Ffind_file_name_handler (directory, Qdelete_directory); | 2238 | handler = Ffind_file_name_handler (directory, Qdelete_directory); |
| 2218 | if (!NILP (handler)) | 2239 | if (!NILP (handler)) |
| 2219 | return call2 (handler, Qdelete_directory, directory); | 2240 | return call2 (handler, Qdelete_directory, directory); |
| 2220 | 2241 | ||
| 2242 | encoded_dir = ENCODE_FILE (directory); | ||
| 2243 | |||
| 2244 | dir = XSTRING (encoded_dir)->data; | ||
| 2245 | |||
| 2221 | if (rmdir (dir) != 0) | 2246 | if (rmdir (dir) != 0) |
| 2222 | report_file_error ("Removing directory", Flist (1, &directory)); | 2247 | report_file_error ("Removing directory", Flist (1, &directory)); |
| 2223 | 2248 | ||
| @@ -2231,6 +2256,8 @@ If file has multiple names, it continues to exist with the other names.") | |||
| 2231 | Lisp_Object filename; | 2256 | Lisp_Object filename; |
| 2232 | { | 2257 | { |
| 2233 | Lisp_Object handler; | 2258 | Lisp_Object handler; |
| 2259 | Lisp_Object encoded_file; | ||
| 2260 | |||
| 2234 | CHECK_STRING (filename, 0); | 2261 | CHECK_STRING (filename, 0); |
| 2235 | filename = Fexpand_file_name (filename, Qnil); | 2262 | filename = Fexpand_file_name (filename, Qnil); |
| 2236 | 2263 | ||
| @@ -2238,7 +2265,9 @@ If file has multiple names, it continues to exist with the other names.") | |||
| 2238 | if (!NILP (handler)) | 2265 | if (!NILP (handler)) |
| 2239 | return call2 (handler, Qdelete_file, filename); | 2266 | return call2 (handler, Qdelete_file, filename); |
| 2240 | 2267 | ||
| 2241 | if (0 > unlink (XSTRING (filename)->data)) | 2268 | encoded_file = ENCODE_FILE (filename); |
| 2269 | |||
| 2270 | if (0 > unlink (XSTRING (encoded_file)->data)) | ||
| 2242 | report_file_error ("Removing old name", Flist (1, &filename)); | 2271 | report_file_error ("Removing old name", Flist (1, &filename)); |
| 2243 | return Qnil; | 2272 | return Qnil; |
| 2244 | } | 2273 | } |
| @@ -2275,9 +2304,11 @@ This is what happens in interactive use with M-x.") | |||
| 2275 | Lisp_Object args[2]; | 2304 | Lisp_Object args[2]; |
| 2276 | #endif | 2305 | #endif |
| 2277 | Lisp_Object handler; | 2306 | Lisp_Object handler; |
| 2278 | struct gcpro gcpro1, gcpro2; | 2307 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
| 2308 | Lisp_Object encoded_file, encoded_newname; | ||
| 2279 | 2309 | ||
| 2280 | GCPRO2 (file, newname); | 2310 | encoded_file = encoded_newname = Qnil; |
| 2311 | GCPRO4 (file, newname, encoded_file, encoded_newname); | ||
| 2281 | CHECK_STRING (file, 0); | 2312 | CHECK_STRING (file, 0); |
| 2282 | CHECK_STRING (newname, 1); | 2313 | CHECK_STRING (newname, 1); |
| 2283 | file = Fexpand_file_name (file, Qnil); | 2314 | file = Fexpand_file_name (file, Qnil); |
| @@ -2292,15 +2323,18 @@ This is what happens in interactive use with M-x.") | |||
| 2292 | RETURN_UNGCPRO (call4 (handler, Qrename_file, | 2323 | RETURN_UNGCPRO (call4 (handler, Qrename_file, |
| 2293 | file, newname, ok_if_already_exists)); | 2324 | file, newname, ok_if_already_exists)); |
| 2294 | 2325 | ||
| 2326 | encoded_file = ENCODE_FILE (file); | ||
| 2327 | encoded_newname = ENCODE_FILE (newname); | ||
| 2328 | |||
| 2295 | if (NILP (ok_if_already_exists) | 2329 | if (NILP (ok_if_already_exists) |
| 2296 | || INTEGERP (ok_if_already_exists)) | 2330 | || INTEGERP (ok_if_already_exists)) |
| 2297 | barf_or_query_if_file_exists (newname, "rename to it", | 2331 | barf_or_query_if_file_exists (encoded_newname, "rename to it", |
| 2298 | INTEGERP (ok_if_already_exists), 0); | 2332 | INTEGERP (ok_if_already_exists), 0); |
| 2299 | #ifndef BSD4_1 | 2333 | #ifndef BSD4_1 |
| 2300 | if (0 > rename (XSTRING (file)->data, XSTRING (newname)->data)) | 2334 | if (0 > rename (XSTRING (encoded_file)->data, XSTRING (encoded_newname)->data)) |
| 2301 | #else | 2335 | #else |
| 2302 | if (0 > link (XSTRING (file)->data, XSTRING (newname)->data) | 2336 | if (0 > link (XSTRING (encoded_file)->data, XSTRING (encoded_newname)->data) |
| 2303 | || 0 > unlink (XSTRING (file)->data)) | 2337 | || 0 > unlink (XSTRING (encoded_file)->data)) |
| 2304 | #endif | 2338 | #endif |
| 2305 | { | 2339 | { |
| 2306 | if (errno == EXDEV) | 2340 | if (errno == EXDEV) |
| @@ -2340,9 +2374,11 @@ This is what happens in interactive use with M-x.") | |||
| 2340 | Lisp_Object args[2]; | 2374 | Lisp_Object args[2]; |
| 2341 | #endif | 2375 | #endif |
| 2342 | Lisp_Object handler; | 2376 | Lisp_Object handler; |
| 2343 | struct gcpro gcpro1, gcpro2; | 2377 | Lisp_Object encoded_file, encoded_newname; |
| 2378 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | ||
| 2344 | 2379 | ||
| 2345 | GCPRO2 (file, newname); | 2380 | GCPRO4 (file, newname, encoded_file, encoded_newname); |
| 2381 | encoded_file = encoded_newname = Qnil; | ||
| 2346 | CHECK_STRING (file, 0); | 2382 | CHECK_STRING (file, 0); |
| 2347 | CHECK_STRING (newname, 1); | 2383 | CHECK_STRING (newname, 1); |
| 2348 | file = Fexpand_file_name (file, Qnil); | 2384 | file = Fexpand_file_name (file, Qnil); |
| @@ -2362,13 +2398,16 @@ This is what happens in interactive use with M-x.") | |||
| 2362 | RETURN_UNGCPRO (call4 (handler, Qadd_name_to_file, file, | 2398 | RETURN_UNGCPRO (call4 (handler, Qadd_name_to_file, file, |
| 2363 | newname, ok_if_already_exists)); | 2399 | newname, ok_if_already_exists)); |
| 2364 | 2400 | ||
| 2401 | encoded_file = ENCODE_FILE (file); | ||
| 2402 | encoded_newname = ENCODE_FILE (newname); | ||
| 2403 | |||
| 2365 | if (NILP (ok_if_already_exists) | 2404 | if (NILP (ok_if_already_exists) |
| 2366 | || INTEGERP (ok_if_already_exists)) | 2405 | || INTEGERP (ok_if_already_exists)) |
| 2367 | barf_or_query_if_file_exists (newname, "make it a new name", | 2406 | barf_or_query_if_file_exists (encoded_newname, "make it a new name", |
| 2368 | INTEGERP (ok_if_already_exists), 0); | 2407 | INTEGERP (ok_if_already_exists), 0); |
| 2369 | 2408 | ||
| 2370 | unlink (XSTRING (newname)->data); | 2409 | unlink (XSTRING (newname)->data); |
| 2371 | if (0 > link (XSTRING (file)->data, XSTRING (newname)->data)) | 2410 | if (0 > link (XSTRING (encoded_file)->data, XSTRING (encoded_newname)->data)) |
| 2372 | { | 2411 | { |
| 2373 | #ifdef NO_ARG_ARRAY | 2412 | #ifdef NO_ARG_ARRAY |
| 2374 | args[0] = file; | 2413 | args[0] = file; |
| @@ -2398,9 +2437,11 @@ This happens for interactive use with M-x.") | |||
| 2398 | Lisp_Object args[2]; | 2437 | Lisp_Object args[2]; |
| 2399 | #endif | 2438 | #endif |
| 2400 | Lisp_Object handler; | 2439 | Lisp_Object handler; |
| 2401 | struct gcpro gcpro1, gcpro2; | 2440 | Lisp_Object encoded_filename, encoded_linkname; |
| 2441 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | ||
| 2402 | 2442 | ||
| 2403 | GCPRO2 (filename, linkname); | 2443 | GCPRO4 (filename, linkname, encoded_filename, encoded_linkname); |
| 2444 | encoded_filename = encoded_linkname = Qnil; | ||
| 2404 | CHECK_STRING (filename, 0); | 2445 | CHECK_STRING (filename, 0); |
| 2405 | CHECK_STRING (linkname, 1); | 2446 | CHECK_STRING (linkname, 1); |
| 2406 | /* If the link target has a ~, we must expand it to get | 2447 | /* If the link target has a ~, we must expand it to get |
| @@ -2424,17 +2465,22 @@ This happens for interactive use with M-x.") | |||
| 2424 | RETURN_UNGCPRO (call4 (handler, Qmake_symbolic_link, filename, | 2465 | RETURN_UNGCPRO (call4 (handler, Qmake_symbolic_link, filename, |
| 2425 | linkname, ok_if_already_exists)); | 2466 | linkname, ok_if_already_exists)); |
| 2426 | 2467 | ||
| 2468 | encoded_filename = ENCODE_FILE (filename); | ||
| 2469 | encoded_linkname = ENCODE_FILE (linkname); | ||
| 2470 | |||
| 2427 | if (NILP (ok_if_already_exists) | 2471 | if (NILP (ok_if_already_exists) |
| 2428 | || INTEGERP (ok_if_already_exists)) | 2472 | || INTEGERP (ok_if_already_exists)) |
| 2429 | barf_or_query_if_file_exists (linkname, "make it a link", | 2473 | barf_or_query_if_file_exists (encoded_linkname, "make it a link", |
| 2430 | INTEGERP (ok_if_already_exists), 0); | 2474 | INTEGERP (ok_if_already_exists), 0); |
| 2431 | if (0 > symlink (XSTRING (filename)->data, XSTRING (linkname)->data)) | 2475 | if (0 > symlink (XSTRING (encoded_filename)->data, |
| 2476 | XSTRING (encoded_linkname)->data)) | ||
| 2432 | { | 2477 | { |
| 2433 | /* If we didn't complain already, silently delete existing file. */ | 2478 | /* If we didn't complain already, silently delete existing file. */ |
| 2434 | if (errno == EEXIST) | 2479 | if (errno == EEXIST) |
| 2435 | { | 2480 | { |
| 2436 | unlink (XSTRING (linkname)->data); | 2481 | unlink (XSTRING (encoded_linkname)->data); |
| 2437 | if (0 <= symlink (XSTRING (filename)->data, XSTRING (linkname)->data)) | 2482 | if (0 <= symlink (XSTRING (encoded_filename)->data, |
| 2483 | XSTRING (encoded_linkname)->data)) | ||
| 2438 | { | 2484 | { |
| 2439 | UNGCPRO; | 2485 | UNGCPRO; |
| 2440 | return Qnil; | 2486 | return Qnil; |
| @@ -2607,6 +2653,8 @@ See also `file-readable-p' and `file-attributes'.") | |||
| 2607 | if (!NILP (handler)) | 2653 | if (!NILP (handler)) |
| 2608 | return call2 (handler, Qfile_exists_p, absname); | 2654 | return call2 (handler, Qfile_exists_p, absname); |
| 2609 | 2655 | ||
| 2656 | absname = ENCODE_FILE (absname); | ||
| 2657 | |||
| 2610 | return (stat (XSTRING (absname)->data, &statbuf) >= 0) ? Qt : Qnil; | 2658 | return (stat (XSTRING (absname)->data, &statbuf) >= 0) ? Qt : Qnil; |
| 2611 | } | 2659 | } |
| 2612 | 2660 | ||
| @@ -2629,6 +2677,8 @@ For a directory, this means you can access files in that directory.") | |||
| 2629 | if (!NILP (handler)) | 2677 | if (!NILP (handler)) |
| 2630 | return call2 (handler, Qfile_executable_p, absname); | 2678 | return call2 (handler, Qfile_executable_p, absname); |
| 2631 | 2679 | ||
| 2680 | absname = ENCODE_FILE (absname); | ||
| 2681 | |||
| 2632 | return (check_executable (XSTRING (absname)->data) ? Qt : Qnil); | 2682 | return (check_executable (XSTRING (absname)->data) ? Qt : Qnil); |
| 2633 | } | 2683 | } |
| 2634 | 2684 | ||
| @@ -2653,6 +2703,8 @@ See also `file-exists-p' and `file-attributes'.") | |||
| 2653 | if (!NILP (handler)) | 2703 | if (!NILP (handler)) |
| 2654 | return call2 (handler, Qfile_readable_p, absname); | 2704 | return call2 (handler, Qfile_readable_p, absname); |
| 2655 | 2705 | ||
| 2706 | absname = ENCODE_FILE (absname); | ||
| 2707 | |||
| 2656 | #ifdef DOS_NT | 2708 | #ifdef DOS_NT |
| 2657 | /* Under MS-DOS and Windows, open does not work for directories. */ | 2709 | /* Under MS-DOS and Windows, open does not work for directories. */ |
| 2658 | if (access (XSTRING (absname)->data, 0) == 0) | 2710 | if (access (XSTRING (absname)->data, 0) == 0) |
| @@ -2685,7 +2737,7 @@ DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0, | |||
| 2685 | (filename) | 2737 | (filename) |
| 2686 | Lisp_Object filename; | 2738 | Lisp_Object filename; |
| 2687 | { | 2739 | { |
| 2688 | Lisp_Object absname, dir; | 2740 | Lisp_Object absname, dir, encoded; |
| 2689 | Lisp_Object handler; | 2741 | Lisp_Object handler; |
| 2690 | struct stat statbuf; | 2742 | struct stat statbuf; |
| 2691 | 2743 | ||
| @@ -2698,9 +2750,11 @@ DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0, | |||
| 2698 | if (!NILP (handler)) | 2750 | if (!NILP (handler)) |
| 2699 | return call2 (handler, Qfile_writable_p, absname); | 2751 | return call2 (handler, Qfile_writable_p, absname); |
| 2700 | 2752 | ||
| 2701 | if (stat (XSTRING (absname)->data, &statbuf) >= 0) | 2753 | encoded = ENCODE_FILE (absname); |
| 2702 | return (check_writable (XSTRING (absname)->data) | 2754 | if (stat (XSTRING (encoded)->data, &statbuf) >= 0) |
| 2755 | return (check_writable (XSTRING (encoded)->data) | ||
| 2703 | ? Qt : Qnil); | 2756 | ? Qt : Qnil); |
| 2757 | |||
| 2704 | dir = Ffile_name_directory (absname); | 2758 | dir = Ffile_name_directory (absname); |
| 2705 | #ifdef VMS | 2759 | #ifdef VMS |
| 2706 | if (!NILP (dir)) | 2760 | if (!NILP (dir)) |
| @@ -2710,6 +2764,8 @@ DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0, | |||
| 2710 | if (!NILP (dir)) | 2764 | if (!NILP (dir)) |
| 2711 | dir = Fdirectory_file_name (dir); | 2765 | dir = Fdirectory_file_name (dir); |
| 2712 | #endif /* MSDOS */ | 2766 | #endif /* MSDOS */ |
| 2767 | |||
| 2768 | dir = ENCODE_FILE (dir); | ||
| 2713 | return (check_writable (!NILP (dir) ? (char *) XSTRING (dir)->data : "") | 2769 | return (check_writable (!NILP (dir) ? (char *) XSTRING (dir)->data : "") |
| 2714 | ? Qt : Qnil); | 2770 | ? Qt : Qnil); |
| 2715 | } | 2771 | } |
| @@ -2721,7 +2777,7 @@ If there is no error, we return nil.") | |||
| 2721 | (filename, string) | 2777 | (filename, string) |
| 2722 | Lisp_Object filename, string; | 2778 | Lisp_Object filename, string; |
| 2723 | { | 2779 | { |
| 2724 | Lisp_Object handler; | 2780 | Lisp_Object handler, encoded_filename; |
| 2725 | int fd; | 2781 | int fd; |
| 2726 | 2782 | ||
| 2727 | CHECK_STRING (filename, 0); | 2783 | CHECK_STRING (filename, 0); |
| @@ -2732,7 +2788,9 @@ If there is no error, we return nil.") | |||
| 2732 | if (!NILP (handler)) | 2788 | if (!NILP (handler)) |
| 2733 | return call3 (handler, Qaccess_file, filename, string); | 2789 | return call3 (handler, Qaccess_file, filename, string); |
| 2734 | 2790 | ||
| 2735 | fd = open (XSTRING (filename)->data, O_RDONLY); | 2791 | encoded_filename = ENCODE_FILE (filename); |
| 2792 | |||
| 2793 | fd = open (XSTRING (encoded_filename)->data, O_RDONLY); | ||
| 2736 | if (fd < 0) | 2794 | if (fd < 0) |
| 2737 | report_file_error (XSTRING (string)->data, Fcons (filename, Qnil)); | 2795 | report_file_error (XSTRING (string)->data, Fcons (filename, Qnil)); |
| 2738 | close (fd); | 2796 | close (fd); |
| @@ -2763,6 +2821,8 @@ Otherwise returns nil.") | |||
| 2763 | if (!NILP (handler)) | 2821 | if (!NILP (handler)) |
| 2764 | return call2 (handler, Qfile_symlink_p, filename); | 2822 | return call2 (handler, Qfile_symlink_p, filename); |
| 2765 | 2823 | ||
| 2824 | filename = ENCODE_FILE (filename); | ||
| 2825 | |||
| 2766 | bufsize = 100; | 2826 | bufsize = 100; |
| 2767 | while (1) | 2827 | while (1) |
| 2768 | { | 2828 | { |
| @@ -2781,7 +2841,7 @@ Otherwise returns nil.") | |||
| 2781 | } | 2841 | } |
| 2782 | val = make_string (buf, valsize); | 2842 | val = make_string (buf, valsize); |
| 2783 | xfree (buf); | 2843 | xfree (buf); |
| 2784 | return val; | 2844 | return Fdecode_coding_string (val, Vfile_name_coding_system, Qt); |
| 2785 | #else /* not S_IFLNK */ | 2845 | #else /* not S_IFLNK */ |
| 2786 | return Qnil; | 2846 | return Qnil; |
| 2787 | #endif /* not S_IFLNK */ | 2847 | #endif /* not S_IFLNK */ |
| @@ -2804,6 +2864,8 @@ DEFUN ("file-directory-p", Ffile_directory_p, Sfile_directory_p, 1, 1, 0, | |||
| 2804 | if (!NILP (handler)) | 2864 | if (!NILP (handler)) |
| 2805 | return call2 (handler, Qfile_directory_p, absname); | 2865 | return call2 (handler, Qfile_directory_p, absname); |
| 2806 | 2866 | ||
| 2867 | absname = ENCODE_FILE (absname); | ||
| 2868 | |||
| 2807 | if (stat (XSTRING (absname)->data, &st) < 0) | 2869 | if (stat (XSTRING (absname)->data, &st) < 0) |
| 2808 | return Qnil; | 2870 | return Qnil; |
| 2809 | return (st.st_mode & S_IFMT) == S_IFDIR ? Qt : Qnil; | 2871 | return (st.st_mode & S_IFMT) == S_IFDIR ? Qt : Qnil; |
| @@ -2860,6 +2922,8 @@ This is the sort of file that holds an ordinary stream of data bytes.") | |||
| 2860 | if (!NILP (handler)) | 2922 | if (!NILP (handler)) |
| 2861 | return call2 (handler, Qfile_regular_p, absname); | 2923 | return call2 (handler, Qfile_regular_p, absname); |
| 2862 | 2924 | ||
| 2925 | absname = ENCODE_FILE (absname); | ||
| 2926 | |||
| 2863 | if (stat (XSTRING (absname)->data, &st) < 0) | 2927 | if (stat (XSTRING (absname)->data, &st) < 0) |
| 2864 | return Qnil; | 2928 | return Qnil; |
| 2865 | return (st.st_mode & S_IFMT) == S_IFREG ? Qt : Qnil; | 2929 | return (st.st_mode & S_IFMT) == S_IFREG ? Qt : Qnil; |
| @@ -2882,6 +2946,8 @@ DEFUN ("file-modes", Ffile_modes, Sfile_modes, 1, 1, 0, | |||
| 2882 | if (!NILP (handler)) | 2946 | if (!NILP (handler)) |
| 2883 | return call2 (handler, Qfile_modes, absname); | 2947 | return call2 (handler, Qfile_modes, absname); |
| 2884 | 2948 | ||
| 2949 | absname = ENCODE_FILE (absname); | ||
| 2950 | |||
| 2885 | if (stat (XSTRING (absname)->data, &st) < 0) | 2951 | if (stat (XSTRING (absname)->data, &st) < 0) |
| 2886 | return Qnil; | 2952 | return Qnil; |
| 2887 | #if defined (MSDOS) && __DJGPP__ < 2 | 2953 | #if defined (MSDOS) && __DJGPP__ < 2 |
| @@ -2898,7 +2964,7 @@ Only the 12 low bits of MODE are used.") | |||
| 2898 | (filename, mode) | 2964 | (filename, mode) |
| 2899 | Lisp_Object filename, mode; | 2965 | Lisp_Object filename, mode; |
| 2900 | { | 2966 | { |
| 2901 | Lisp_Object absname; | 2967 | Lisp_Object absname, encoded_absname; |
| 2902 | Lisp_Object handler; | 2968 | Lisp_Object handler; |
| 2903 | 2969 | ||
| 2904 | absname = Fexpand_file_name (filename, current_buffer->directory); | 2970 | absname = Fexpand_file_name (filename, current_buffer->directory); |
| @@ -2910,7 +2976,9 @@ Only the 12 low bits of MODE are used.") | |||
| 2910 | if (!NILP (handler)) | 2976 | if (!NILP (handler)) |
| 2911 | return call3 (handler, Qset_file_modes, absname, mode); | 2977 | return call3 (handler, Qset_file_modes, absname, mode); |
| 2912 | 2978 | ||
| 2913 | if (chmod (XSTRING (absname)->data, XINT (mode)) < 0) | 2979 | encoded_absname = ENCODE_FILE (absname); |
| 2980 | |||
| 2981 | if (chmod (XSTRING (encoded_absname)->data, XINT (mode)) < 0) | ||
| 2914 | report_file_error ("Doing chmod", Fcons (absname, Qnil)); | 2982 | report_file_error ("Doing chmod", Fcons (absname, Qnil)); |
| 2915 | 2983 | ||
| 2916 | return Qnil; | 2984 | return Qnil; |
| @@ -2987,6 +3055,11 @@ otherwise, if FILE2 does not exist, the answer is t.") | |||
| 2987 | if (!NILP (handler)) | 3055 | if (!NILP (handler)) |
| 2988 | return call3 (handler, Qfile_newer_than_file_p, absname1, absname2); | 3056 | return call3 (handler, Qfile_newer_than_file_p, absname1, absname2); |
| 2989 | 3057 | ||
| 3058 | GCPRO2 (absname1, absname2); | ||
| 3059 | absname1 = ENCODE_FILE (absname1); | ||
| 3060 | absname2 = ENCODE_FILE (absname2); | ||
| 3061 | UNGCPRO; | ||
| 3062 | |||
| 2990 | if (stat (XSTRING (absname1)->data, &st) < 0) | 3063 | if (stat (XSTRING (absname1)->data, &st) < 0) |
| 2991 | return Qnil; | 3064 | return Qnil; |
| 2992 | 3065 | ||
| @@ -3038,8 +3111,8 @@ This does code conversion according to the value of\n\ | |||
| 3038 | register int how_much; | 3111 | register int how_much; |
| 3039 | register int unprocessed; | 3112 | register int unprocessed; |
| 3040 | int count = specpdl_ptr - specpdl; | 3113 | int count = specpdl_ptr - specpdl; |
| 3041 | struct gcpro gcpro1, gcpro2, gcpro3; | 3114 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
| 3042 | Lisp_Object handler, val, insval; | 3115 | Lisp_Object handler, val, insval, orig_filename; |
| 3043 | Lisp_Object p; | 3116 | Lisp_Object p; |
| 3044 | int total; | 3117 | int total; |
| 3045 | int not_regular = 0; | 3118 | int not_regular = 0; |
| @@ -3056,8 +3129,9 @@ This does code conversion according to the value of\n\ | |||
| 3056 | 3129 | ||
| 3057 | val = Qnil; | 3130 | val = Qnil; |
| 3058 | p = Qnil; | 3131 | p = Qnil; |
| 3132 | orig_filename = Qnil; | ||
| 3059 | 3133 | ||
| 3060 | GCPRO3 (filename, val, p); | 3134 | GCPRO4 (filename, val, p, orig_filename); |
| 3061 | 3135 | ||
| 3062 | CHECK_STRING (filename, 0); | 3136 | CHECK_STRING (filename, 0); |
| 3063 | filename = Fexpand_file_name (filename, Qnil); | 3137 | filename = Fexpand_file_name (filename, Qnil); |
| @@ -3072,6 +3146,9 @@ This does code conversion according to the value of\n\ | |||
| 3072 | goto handled; | 3146 | goto handled; |
| 3073 | } | 3147 | } |
| 3074 | 3148 | ||
| 3149 | orig_filename = filename; | ||
| 3150 | filename = ENCODE_FILE (filename); | ||
| 3151 | |||
| 3075 | fd = -1; | 3152 | fd = -1; |
| 3076 | 3153 | ||
| 3077 | #ifndef APOLLO | 3154 | #ifndef APOLLO |
| @@ -3084,7 +3161,7 @@ This does code conversion according to the value of\n\ | |||
| 3084 | if (fd >= 0) close (fd); | 3161 | if (fd >= 0) close (fd); |
| 3085 | badopen: | 3162 | badopen: |
| 3086 | if (NILP (visit)) | 3163 | if (NILP (visit)) |
| 3087 | report_file_error ("Opening input file", Fcons (filename, Qnil)); | 3164 | report_file_error ("Opening input file", Fcons (orig_filename, Qnil)); |
| 3088 | st.st_mtime = -1; | 3165 | st.st_mtime = -1; |
| 3089 | how_much = 0; | 3166 | how_much = 0; |
| 3090 | goto notfound; | 3167 | goto notfound; |
| @@ -3104,7 +3181,7 @@ This does code conversion according to the value of\n\ | |||
| 3104 | if (! NILP (replace) || ! NILP (beg) || ! NILP (end)) | 3181 | if (! NILP (replace) || ! NILP (beg) || ! NILP (end)) |
| 3105 | Fsignal (Qfile_error, | 3182 | Fsignal (Qfile_error, |
| 3106 | Fcons (build_string ("not a regular file"), | 3183 | Fcons (build_string ("not a regular file"), |
| 3107 | Fcons (filename, Qnil))); | 3184 | Fcons (orig_filename, Qnil))); |
| 3108 | } | 3185 | } |
| 3109 | #endif | 3186 | #endif |
| 3110 | 3187 | ||
| @@ -3170,14 +3247,14 @@ This does code conversion according to the value of\n\ | |||
| 3170 | { | 3247 | { |
| 3171 | if (lseek (fd, st.st_size - (1024 * 3), 0) < 0) | 3248 | if (lseek (fd, st.st_size - (1024 * 3), 0) < 0) |
| 3172 | report_file_error ("Setting file position", | 3249 | report_file_error ("Setting file position", |
| 3173 | Fcons (filename, Qnil)); | 3250 | Fcons (orig_filename, Qnil)); |
| 3174 | nread += read (fd, read_buf + nread, 1024 * 3); | 3251 | nread += read (fd, read_buf + nread, 1024 * 3); |
| 3175 | } | 3252 | } |
| 3176 | } | 3253 | } |
| 3177 | 3254 | ||
| 3178 | if (nread < 0) | 3255 | if (nread < 0) |
| 3179 | error ("IO error reading %s: %s", | 3256 | error ("IO error reading %s: %s", |
| 3180 | XSTRING (filename)->data, strerror (errno)); | 3257 | XSTRING (orig_filename)->data, strerror (errno)); |
| 3181 | else if (nread > 0) | 3258 | else if (nread > 0) |
| 3182 | { | 3259 | { |
| 3183 | val = call1 (Vset_auto_coding_function, | 3260 | val = call1 (Vset_auto_coding_function, |
| @@ -3185,14 +3262,14 @@ This does code conversion according to the value of\n\ | |||
| 3185 | /* Rewind the file for the actual read done later. */ | 3262 | /* Rewind the file for the actual read done later. */ |
| 3186 | if (lseek (fd, 0, 0) < 0) | 3263 | if (lseek (fd, 0, 0) < 0) |
| 3187 | report_file_error ("Setting file position", | 3264 | report_file_error ("Setting file position", |
| 3188 | Fcons (filename, Qnil)); | 3265 | Fcons (orig_filename, Qnil)); |
| 3189 | } | 3266 | } |
| 3190 | } | 3267 | } |
| 3191 | if (NILP (val)) | 3268 | if (NILP (val)) |
| 3192 | { | 3269 | { |
| 3193 | Lisp_Object args[6], coding_systems; | 3270 | Lisp_Object args[6], coding_systems; |
| 3194 | 3271 | ||
| 3195 | args[0] = Qinsert_file_contents, args[1] = filename, | 3272 | args[0] = Qinsert_file_contents, args[1] = orig_filename, |
| 3196 | args[2] = visit, args[3] = beg, args[4] = end, args[5] = replace; | 3273 | args[2] = visit, args[3] = beg, args[4] = end, args[5] = replace; |
| 3197 | coding_systems = Ffind_operation_coding_system (6, args); | 3274 | coding_systems = Ffind_operation_coding_system (6, args); |
| 3198 | if (CONSP (coding_systems)) val = XCONS (coding_systems)->car; | 3275 | if (CONSP (coding_systems)) val = XCONS (coding_systems)->car; |
| @@ -3230,7 +3307,7 @@ This does code conversion according to the value of\n\ | |||
| 3230 | { | 3307 | { |
| 3231 | if (lseek (fd, XINT (beg), 0) < 0) | 3308 | if (lseek (fd, XINT (beg), 0) < 0) |
| 3232 | report_file_error ("Setting file position", | 3309 | report_file_error ("Setting file position", |
| 3233 | Fcons (filename, Qnil)); | 3310 | Fcons (orig_filename, Qnil)); |
| 3234 | } | 3311 | } |
| 3235 | 3312 | ||
| 3236 | immediate_quit = 1; | 3313 | immediate_quit = 1; |
| @@ -3244,7 +3321,7 @@ This does code conversion according to the value of\n\ | |||
| 3244 | nread = read (fd, buffer, sizeof buffer); | 3321 | nread = read (fd, buffer, sizeof buffer); |
| 3245 | if (nread < 0) | 3322 | if (nread < 0) |
| 3246 | error ("IO error reading %s: %s", | 3323 | error ("IO error reading %s: %s", |
| 3247 | XSTRING (filename)->data, strerror (errno)); | 3324 | XSTRING (orig_filename)->data, strerror (errno)); |
| 3248 | else if (nread == 0) | 3325 | else if (nread == 0) |
| 3249 | break; | 3326 | break; |
| 3250 | 3327 | ||
| @@ -3309,7 +3386,7 @@ This does code conversion according to the value of\n\ | |||
| 3309 | trial = min (curpos, sizeof buffer); | 3386 | trial = min (curpos, sizeof buffer); |
| 3310 | if (lseek (fd, curpos - trial, 0) < 0) | 3387 | if (lseek (fd, curpos - trial, 0) < 0) |
| 3311 | report_file_error ("Setting file position", | 3388 | report_file_error ("Setting file position", |
| 3312 | Fcons (filename, Qnil)); | 3389 | Fcons (orig_filename, Qnil)); |
| 3313 | 3390 | ||
| 3314 | total_read = 0; | 3391 | total_read = 0; |
| 3315 | while (total_read < trial) | 3392 | while (total_read < trial) |
| @@ -3317,7 +3394,7 @@ This does code conversion according to the value of\n\ | |||
| 3317 | nread = read (fd, buffer + total_read, trial - total_read); | 3394 | nread = read (fd, buffer + total_read, trial - total_read); |
| 3318 | if (nread <= 0) | 3395 | if (nread <= 0) |
| 3319 | error ("IO error reading %s: %s", | 3396 | error ("IO error reading %s: %s", |
| 3320 | XSTRING (filename)->data, strerror (errno)); | 3397 | XSTRING (orig_filename)->data, strerror (errno)); |
| 3321 | total_read += nread; | 3398 | total_read += nread; |
| 3322 | } | 3399 | } |
| 3323 | /* Scan this bufferful from the end, comparing with | 3400 | /* Scan this bufferful from the end, comparing with |
| @@ -3403,7 +3480,7 @@ This does code conversion according to the value of\n\ | |||
| 3403 | { | 3480 | { |
| 3404 | free (conversion_buffer); | 3481 | free (conversion_buffer); |
| 3405 | report_file_error ("Setting file position", | 3482 | report_file_error ("Setting file position", |
| 3406 | Fcons (filename, Qnil)); | 3483 | Fcons (orig_filename, Qnil)); |
| 3407 | } | 3484 | } |
| 3408 | 3485 | ||
| 3409 | total = st.st_size; /* Total bytes in the file. */ | 3486 | total = st.st_size; /* Total bytes in the file. */ |
| @@ -3475,7 +3552,7 @@ This does code conversion according to the value of\n\ | |||
| 3475 | 3552 | ||
| 3476 | if (how_much == -1) | 3553 | if (how_much == -1) |
| 3477 | error ("IO error reading %s: %s", | 3554 | error ("IO error reading %s: %s", |
| 3478 | XSTRING (filename)->data, strerror (errno)); | 3555 | XSTRING (orig_filename)->data, strerror (errno)); |
| 3479 | else if (how_much == -2) | 3556 | else if (how_much == -2) |
| 3480 | error ("maximum buffer size exceeded"); | 3557 | error ("maximum buffer size exceeded"); |
| 3481 | } | 3558 | } |
| @@ -3562,7 +3639,8 @@ This does code conversion according to the value of\n\ | |||
| 3562 | if (XINT (beg) != 0 || !NILP (replace)) | 3639 | if (XINT (beg) != 0 || !NILP (replace)) |
| 3563 | { | 3640 | { |
| 3564 | if (lseek (fd, XINT (beg), 0) < 0) | 3641 | if (lseek (fd, XINT (beg), 0) < 0) |
| 3565 | report_file_error ("Setting file position", Fcons (filename, Qnil)); | 3642 | report_file_error ("Setting file position", |
| 3643 | Fcons (orig_filename, Qnil)); | ||
| 3566 | } | 3644 | } |
| 3567 | 3645 | ||
| 3568 | /* In the following loop, HOW_MUCH contains the total bytes read so | 3646 | /* In the following loop, HOW_MUCH contains the total bytes read so |
| @@ -3677,7 +3755,7 @@ This does code conversion according to the value of\n\ | |||
| 3677 | is deemed to be a text file. */ | 3755 | is deemed to be a text file. */ |
| 3678 | { | 3756 | { |
| 3679 | current_buffer->buffer_file_type | 3757 | current_buffer->buffer_file_type |
| 3680 | = call1 (Qfind_buffer_file_type, filename); | 3758 | = call1 (Qfind_buffer_file_type, orig_filename); |
| 3681 | if (NILP (current_buffer->buffer_file_type)) | 3759 | if (NILP (current_buffer->buffer_file_type)) |
| 3682 | { | 3760 | { |
| 3683 | int reduced_size | 3761 | int reduced_size |
| @@ -3708,7 +3786,7 @@ This does code conversion according to the value of\n\ | |||
| 3708 | 3786 | ||
| 3709 | if (how_much == -1) | 3787 | if (how_much == -1) |
| 3710 | error ("IO error reading %s: %s", | 3788 | error ("IO error reading %s: %s", |
| 3711 | XSTRING (filename)->data, strerror (errno)); | 3789 | XSTRING (orig_filename)->data, strerror (errno)); |
| 3712 | else if (how_much == -2) | 3790 | else if (how_much == -2) |
| 3713 | error ("maximum buffer size exceeded"); | 3791 | error ("maximum buffer size exceeded"); |
| 3714 | 3792 | ||
| @@ -3726,7 +3804,7 @@ This does code conversion according to the value of\n\ | |||
| 3726 | if (NILP (handler)) | 3804 | if (NILP (handler)) |
| 3727 | { | 3805 | { |
| 3728 | current_buffer->modtime = st.st_mtime; | 3806 | current_buffer->modtime = st.st_mtime; |
| 3729 | current_buffer->filename = filename; | 3807 | current_buffer->filename = orig_filename; |
| 3730 | } | 3808 | } |
| 3731 | 3809 | ||
| 3732 | SAVE_MODIFF = MODIFF; | 3810 | SAVE_MODIFF = MODIFF; |
| @@ -3743,11 +3821,11 @@ This does code conversion according to the value of\n\ | |||
| 3743 | if (not_regular) | 3821 | if (not_regular) |
| 3744 | Fsignal (Qfile_error, | 3822 | Fsignal (Qfile_error, |
| 3745 | Fcons (build_string ("not a regular file"), | 3823 | Fcons (build_string ("not a regular file"), |
| 3746 | Fcons (filename, Qnil))); | 3824 | Fcons (orig_filename, Qnil))); |
| 3747 | 3825 | ||
| 3748 | /* If visiting nonexistent file, return nil. */ | 3826 | /* If visiting nonexistent file, return nil. */ |
| 3749 | if (current_buffer->modtime == -1) | 3827 | if (current_buffer->modtime == -1) |
| 3750 | report_file_error ("Opening input file", Fcons (filename, Qnil)); | 3828 | report_file_error ("Opening input file", Fcons (orig_filename, Qnil)); |
| 3751 | } | 3829 | } |
| 3752 | 3830 | ||
| 3753 | /* Decode file format */ | 3831 | /* Decode file format */ |
| @@ -3786,7 +3864,7 @@ This does code conversion according to the value of\n\ | |||
| 3786 | } | 3864 | } |
| 3787 | 3865 | ||
| 3788 | if (NILP (val)) | 3866 | if (NILP (val)) |
| 3789 | val = Fcons (filename, | 3867 | val = Fcons (orig_filename, |
| 3790 | Fcons (make_number (inserted), | 3868 | Fcons (make_number (inserted), |
| 3791 | Qnil)); | 3869 | Qnil)); |
| 3792 | 3870 | ||
| @@ -3853,6 +3931,7 @@ to the file, instead of any buffer contents, and END is ignored.") | |||
| 3853 | Lisp_Object handler; | 3931 | Lisp_Object handler; |
| 3854 | Lisp_Object visit_file; | 3932 | Lisp_Object visit_file; |
| 3855 | Lisp_Object annotations; | 3933 | Lisp_Object annotations; |
| 3934 | Lisp_Object encoded_filename; | ||
| 3856 | int visiting, quietly; | 3935 | int visiting, quietly; |
| 3857 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; | 3936 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
| 3858 | struct buffer *given_buffer; | 3937 | struct buffer *given_buffer; |
| @@ -3869,7 +3948,7 @@ to the file, instead of any buffer contents, and END is ignored.") | |||
| 3869 | 3948 | ||
| 3870 | GCPRO4 (start, filename, visit, lockname); | 3949 | GCPRO4 (start, filename, visit, lockname); |
| 3871 | 3950 | ||
| 3872 | /* Decide the coding-system to be encoded to. */ | 3951 | /* Decide the coding-system to encode the data with. */ |
| 3873 | { | 3952 | { |
| 3874 | Lisp_Object val; | 3953 | Lisp_Object val; |
| 3875 | 3954 | ||
| @@ -3995,7 +4074,9 @@ to the file, instead of any buffer contents, and END is ignored.") | |||
| 3995 | } | 4074 | } |
| 3996 | #endif /* CLASH_DETECTION */ | 4075 | #endif /* CLASH_DETECTION */ |
| 3997 | 4076 | ||
| 3998 | fn = XSTRING (filename)->data; | 4077 | encoded_filename = ENCODE_FILE (filename); |
| 4078 | |||
| 4079 | fn = XSTRING (encoded_filename)->data; | ||
| 3999 | desc = -1; | 4080 | desc = -1; |
| 4000 | if (!NILP (append)) | 4081 | if (!NILP (append)) |
| 4001 | #ifdef DOS_NT | 4082 | #ifdef DOS_NT |
| @@ -4004,7 +4085,7 @@ to the file, instead of any buffer contents, and END is ignored.") | |||
| 4004 | desc = open (fn, O_WRONLY); | 4085 | desc = open (fn, O_WRONLY); |
| 4005 | #endif /* not DOS_NT */ | 4086 | #endif /* not DOS_NT */ |
| 4006 | 4087 | ||
| 4007 | if (desc < 0 && (NILP (append) || errno == ENOENT) ) | 4088 | if (desc < 0 && (NILP (append) || errno == ENOENT)) |
| 4008 | #ifdef VMS | 4089 | #ifdef VMS |
| 4009 | if (auto_saving) /* Overwrite any previous version of autosave file */ | 4090 | if (auto_saving) /* Overwrite any previous version of autosave file */ |
| 4010 | { | 4091 | { |
| @@ -4228,7 +4309,8 @@ to the file, instead of any buffer contents, and END is ignored.") | |||
| 4228 | current_buffer->modtime = st.st_mtime; | 4309 | current_buffer->modtime = st.st_mtime; |
| 4229 | 4310 | ||
| 4230 | if (failure) | 4311 | if (failure) |
| 4231 | error ("IO error writing %s: %s", fn, strerror (save_errno)); | 4312 | error ("IO error writing %s: %s", XSTRING (filename)->data, |
| 4313 | strerror (save_errno)); | ||
| 4232 | 4314 | ||
| 4233 | if (visiting) | 4315 | if (visiting) |
| 4234 | { | 4316 | { |
| @@ -4427,6 +4509,7 @@ This means that the file has not been changed since it was visited or saved.") | |||
| 4427 | struct buffer *b; | 4509 | struct buffer *b; |
| 4428 | struct stat st; | 4510 | struct stat st; |
| 4429 | Lisp_Object handler; | 4511 | Lisp_Object handler; |
| 4512 | Lisp_Object filename; | ||
| 4430 | 4513 | ||
| 4431 | CHECK_BUFFER (buf, 0); | 4514 | CHECK_BUFFER (buf, 0); |
| 4432 | b = XBUFFER (buf); | 4515 | b = XBUFFER (buf); |
| @@ -4441,7 +4524,9 @@ This means that the file has not been changed since it was visited or saved.") | |||
| 4441 | if (!NILP (handler)) | 4524 | if (!NILP (handler)) |
| 4442 | return call2 (handler, Qverify_visited_file_modtime, buf); | 4525 | return call2 (handler, Qverify_visited_file_modtime, buf); |
| 4443 | 4526 | ||
| 4444 | if (stat (XSTRING (b->filename)->data, &st) < 0) | 4527 | filename = ENCODE_FILE (b->filename); |
| 4528 | |||
| 4529 | if (stat (XSTRING (filename)->data, &st) < 0) | ||
| 4445 | { | 4530 | { |
| 4446 | /* If the file doesn't exist now and didn't exist before, | 4531 | /* If the file doesn't exist now and didn't exist before, |
| 4447 | we say that it isn't modified, provided the error is a tame one. */ | 4532 | we say that it isn't modified, provided the error is a tame one. */ |
| @@ -4506,7 +4591,10 @@ An argument specifies the modification time value to use\n\ | |||
| 4506 | if (!NILP (handler)) | 4591 | if (!NILP (handler)) |
| 4507 | /* The handler can find the file name the same way we did. */ | 4592 | /* The handler can find the file name the same way we did. */ |
| 4508 | return call2 (handler, Qset_visited_file_modtime, Qnil); | 4593 | return call2 (handler, Qset_visited_file_modtime, Qnil); |
| 4509 | else if (stat (XSTRING (filename)->data, &st) >= 0) | 4594 | |
| 4595 | filename = ENCODE_FILE (filename); | ||
| 4596 | |||
| 4597 | if (stat (XSTRING (filename)->data, &st) >= 0) | ||
| 4510 | current_buffer->modtime = st.st_mtime; | 4598 | current_buffer->modtime = st.st_mtime; |
| 4511 | } | 4599 | } |
| 4512 | 4600 | ||
| @@ -5134,6 +5222,10 @@ syms_of_fileio () | |||
| 5134 | staticpro (&Qfind_buffer_file_type); | 5222 | staticpro (&Qfind_buffer_file_type); |
| 5135 | #endif /* DOS_NT */ | 5223 | #endif /* DOS_NT */ |
| 5136 | 5224 | ||
| 5225 | DEFVAR_LISP ("file-name-coding-system", &Vfile_name_coding_system, | ||
| 5226 | "*Coding system for encoding file names."); | ||
| 5227 | Vfile_name_coding_system = Qnil; | ||
| 5228 | |||
| 5137 | DEFVAR_LISP ("auto-save-file-format", &Vauto_save_file_format, | 5229 | DEFVAR_LISP ("auto-save-file-format", &Vauto_save_file_format, |
| 5138 | "*Format in which to write auto-save files.\n\ | 5230 | "*Format in which to write auto-save files.\n\ |
| 5139 | Should be a list of symbols naming formats that are defined in `format-alist'.\n\ | 5231 | Should be a list of symbols naming formats that are defined in `format-alist'.\n\ |