aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/fileio.c84
1 files changed, 52 insertions, 32 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 9c24a7caf38..697e2281d6d 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -35,8 +35,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
35#include <perror.h> 35#include <perror.h>
36#include <stddef.h> 36#include <stddef.h>
37#include <string.h> 37#include <string.h>
38#else
39#include <sys/dir.h>
40#endif 38#endif
41 39
42#include <errno.h> 40#include <errno.h>
@@ -174,7 +172,7 @@ find_file_handler (filename)
174 Lisp_Object string; 172 Lisp_Object string;
175 string = XCONS (elt)->car; 173 string = XCONS (elt)->car;
176 if (XTYPE (string) == Lisp_String 174 if (XTYPE (string) == Lisp_String
177 && fast_string_match (string, filename)) 175 && fast_string_match (string, filename) >= 0)
178 return XCONS (elt)->cdr; 176 return XCONS (elt)->cdr;
179 } 177 }
180 } 178 }
@@ -584,7 +582,7 @@ See also the function `substitute-in-file-name'.")
584 call the corresponding file handler. */ 582 call the corresponding file handler. */
585 handler = find_file_handler (name); 583 handler = find_file_handler (name);
586 if (!NILP (handler)) 584 if (!NILP (handler))
587 return call2 (handler, Qexpand_file_name, name); 585 return call3 (handler, Qexpand_file_name, name, defalt);
588 586
589#ifdef VMS 587#ifdef VMS
590 /* Filenames on VMS are always upper case. */ 588 /* Filenames on VMS are always upper case. */
@@ -1875,9 +1873,9 @@ See also `file-readable-p' and `file-attributes'.")
1875 1873
1876 /* If the file name has special constructs in it, 1874 /* If the file name has special constructs in it,
1877 call the corresponding file handler. */ 1875 call the corresponding file handler. */
1878 handler = find_file_handler (filename); 1876 handler = find_file_handler (abspath);
1879 if (!NILP (handler)) 1877 if (!NILP (handler))
1880 return call2 (handler, Qfile_exists_p, filename); 1878 return call2 (handler, Qfile_exists_p, abspath);
1881 1879
1882 return (access (XSTRING (abspath)->data, 0) >= 0) ? Qt : Qnil; 1880 return (access (XSTRING (abspath)->data, 0) >= 0) ? Qt : Qnil;
1883} 1881}
@@ -1897,9 +1895,9 @@ For directories this means you can change to that directory.")
1897 1895
1898 /* If the file name has special constructs in it, 1896 /* If the file name has special constructs in it,
1899 call the corresponding file handler. */ 1897 call the corresponding file handler. */
1900 handler = find_file_handler (filename); 1898 handler = find_file_handler (abspath);
1901 if (!NILP (handler)) 1899 if (!NILP (handler))
1902 return call2 (handler, Qfile_executable_p, filename); 1900 return call2 (handler, Qfile_executable_p, abspath);
1903 1901
1904 return (access (XSTRING (abspath)->data, 1) >= 0) ? Qt : Qnil; 1902 return (access (XSTRING (abspath)->data, 1) >= 0) ? Qt : Qnil;
1905} 1903}
@@ -1918,9 +1916,9 @@ See also `file-exists-p' and `file-attributes'.")
1918 1916
1919 /* If the file name has special constructs in it, 1917 /* If the file name has special constructs in it,
1920 call the corresponding file handler. */ 1918 call the corresponding file handler. */
1921 handler = find_file_handler (filename); 1919 handler = find_file_handler (abspath);
1922 if (!NILP (handler)) 1920 if (!NILP (handler))
1923 return call2 (handler, Qfile_readable_p, filename); 1921 return call2 (handler, Qfile_readable_p, abspath);
1924 1922
1925 return (access (XSTRING (abspath)->data, 4) >= 0) ? Qt : Qnil; 1923 return (access (XSTRING (abspath)->data, 4) >= 0) ? Qt : Qnil;
1926} 1924}
@@ -1987,9 +1985,9 @@ DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0,
1987 1985
1988 /* If the file name has special constructs in it, 1986 /* If the file name has special constructs in it,
1989 call the corresponding file handler. */ 1987 call the corresponding file handler. */
1990 handler = find_file_handler (filename); 1988 handler = find_file_handler (abspath);
1991 if (!NILP (handler)) 1989 if (!NILP (handler))
1992 return call2 (handler, Qfile_writable_p, filename); 1990 return call2 (handler, Qfile_writable_p, abspath);
1993 1991
1994 if (access (XSTRING (abspath)->data, 0) >= 0) 1992 if (access (XSTRING (abspath)->data, 0) >= 0)
1995 return (access (XSTRING (abspath)->data, 2) >= 0) ? Qt : Qnil; 1993 return (access (XSTRING (abspath)->data, 2) >= 0) ? Qt : Qnil;
@@ -2017,9 +2015,9 @@ if the directory so specified exists and really is a directory.")
2017 2015
2018 /* If the file name has special constructs in it, 2016 /* If the file name has special constructs in it,
2019 call the corresponding file handler. */ 2017 call the corresponding file handler. */
2020 handler = find_file_handler (filename); 2018 handler = find_file_handler (abspath);
2021 if (!NILP (handler)) 2019 if (!NILP (handler))
2022 return call2 (handler, Qfile_directory_p, filename); 2020 return call2 (handler, Qfile_directory_p, abspath);
2023 2021
2024 if (stat (XSTRING (abspath)->data, &st) < 0) 2022 if (stat (XSTRING (abspath)->data, &st) < 0)
2025 return Qnil; 2023 return Qnil;
@@ -2064,9 +2062,9 @@ DEFUN ("file-modes", Ffile_modes, Sfile_modes, 1, 1, 0,
2064 2062
2065 /* If the file name has special constructs in it, 2063 /* If the file name has special constructs in it,
2066 call the corresponding file handler. */ 2064 call the corresponding file handler. */
2067 handler = find_file_handler (filename); 2065 handler = find_file_handler (abspath);
2068 if (!NILP (handler)) 2066 if (!NILP (handler))
2069 return call2 (handler, Qfile_modes, filename); 2067 return call2 (handler, Qfile_modes, abspath);
2070 2068
2071 if (stat (XSTRING (abspath)->data, &st) < 0) 2069 if (stat (XSTRING (abspath)->data, &st) < 0)
2072 return Qnil; 2070 return Qnil;
@@ -2087,9 +2085,9 @@ Only the 12 low bits of MODE are used.")
2087 2085
2088 /* If the file name has special constructs in it, 2086 /* If the file name has special constructs in it,
2089 call the corresponding file handler. */ 2087 call the corresponding file handler. */
2090 handler = find_file_handler (filename); 2088 handler = find_file_handler (abspath);
2091 if (!NILP (handler)) 2089 if (!NILP (handler))
2092 return call3 (handler, Qset_file_modes, filename, mode); 2090 return call3 (handler, Qset_file_modes, abspath, mode);
2093 2091
2094#ifndef APOLLO 2092#ifndef APOLLO
2095 if (chmod (XSTRING (abspath)->data, XINT (mode)) < 0) 2093 if (chmod (XSTRING (abspath)->data, XINT (mode)) < 0)
@@ -2179,12 +2177,16 @@ otherwise, if FILE2 does not exist, the answer is t.")
2179 struct stat st; 2177 struct stat st;
2180 int mtime1; 2178 int mtime1;
2181 Lisp_Object handler; 2179 Lisp_Object handler;
2180 struct gcpro gcpro1, gcpro2;
2182 2181
2183 CHECK_STRING (file1, 0); 2182 CHECK_STRING (file1, 0);
2184 CHECK_STRING (file2, 0); 2183 CHECK_STRING (file2, 0);
2185 2184
2185 abspath1 = Qnil;
2186 GCPRO2 (abspath1, file2);
2186 abspath1 = expand_and_dir_to_file (file1, current_buffer->directory); 2187 abspath1 = expand_and_dir_to_file (file1, current_buffer->directory);
2187 abspath2 = expand_and_dir_to_file (file2, current_buffer->directory); 2188 abspath2 = expand_and_dir_to_file (file2, current_buffer->directory);
2189 UNGCPRO;
2188 2190
2189 /* If the file name has special constructs in it, 2191 /* If the file name has special constructs in it,
2190 call the corresponding file handler. */ 2192 call the corresponding file handler. */
@@ -2392,6 +2394,7 @@ to the file, instead of any buffer contents, and END is ignored.")
2392 unsigned char *fname = 0; /* If non-0, original filename (must rename) */ 2394 unsigned char *fname = 0; /* If non-0, original filename (must rename) */
2393#endif /* VMS */ 2395#endif /* VMS */
2394 Lisp_Object handler; 2396 Lisp_Object handler;
2397 struct gcpro gcpro1, gcpro2;
2395 2398
2396 /* Special kludge to simplify auto-saving */ 2399 /* Special kludge to simplify auto-saving */
2397 if (NILP (start)) 2400 if (NILP (start))
@@ -2402,8 +2405,8 @@ to the file, instead of any buffer contents, and END is ignored.")
2402 else if (XTYPE (start) != Lisp_String) 2405 else if (XTYPE (start) != Lisp_String)
2403 validate_region (&start, &end); 2406 validate_region (&start, &end);
2404 2407
2408 GCPRO2 (start, filename);
2405 filename = Fexpand_file_name (filename, Qnil); 2409 filename = Fexpand_file_name (filename, Qnil);
2406 fn = XSTRING (filename)->data;
2407 2410
2408 /* If the file name has special constructs in it, 2411 /* If the file name has special constructs in it,
2409 call the corresponding file handler. */ 2412 call the corresponding file handler. */
@@ -2432,6 +2435,7 @@ to the file, instead of any buffer contents, and END is ignored.")
2432 XFASTINT (current_buffer->save_length) = Z - BEG; 2435 XFASTINT (current_buffer->save_length) = Z - BEG;
2433 current_buffer->filename = filename; 2436 current_buffer->filename = filename;
2434 } 2437 }
2438 UNGCPRO;
2435 return val; 2439 return val;
2436 } 2440 }
2437 2441
@@ -2440,6 +2444,7 @@ to the file, instead of any buffer contents, and END is ignored.")
2440 lock_file (filename); 2444 lock_file (filename);
2441#endif /* CLASH_DETECTION */ 2445#endif /* CLASH_DETECTION */
2442 2446
2447 fn = XSTRING (filename)->data;
2443 desc = -1; 2448 desc = -1;
2444 if (!NILP (append)) 2449 if (!NILP (append))
2445 desc = open (fn, O_WRONLY); 2450 desc = open (fn, O_WRONLY);
@@ -2494,6 +2499,8 @@ to the file, instead of any buffer contents, and END is ignored.")
2494 desc = creat (fn, auto_saving ? auto_save_mode_bits : 0666); 2499 desc = creat (fn, auto_saving ? auto_save_mode_bits : 0666);
2495#endif /* not VMS */ 2500#endif /* not VMS */
2496 2501
2502 UNGCPRO;
2503
2497 if (desc < 0) 2504 if (desc < 0)
2498 { 2505 {
2499#ifdef CLASH_DETECTION 2506#ifdef CLASH_DETECTION
@@ -2700,7 +2707,7 @@ This means that the file has not been changed since it was visited or saved.")
2700 call the corresponding file handler. */ 2707 call the corresponding file handler. */
2701 handler = find_file_handler (b->filename); 2708 handler = find_file_handler (b->filename);
2702 if (!NILP (handler)) 2709 if (!NILP (handler))
2703 return call2 (handler, Qverify_visited_file_modtime, b->filename); 2710 return call2 (handler, Qverify_visited_file_modtime, buf);
2704 2711
2705 if (stat (XSTRING (b->filename)->data, &st) < 0) 2712 if (stat (XSTRING (b->filename)->data, &st) < 0)
2706 { 2713 {
@@ -2901,36 +2908,46 @@ DEFUN ("read-file-name-internal", Fread_file_name_internal, Sread_file_name_inte
2901 lambda for verify final value */ 2908 lambda for verify final value */
2902{ 2909{
2903 Lisp_Object name, specdir, realdir, val, orig_string; 2910 Lisp_Object name, specdir, realdir, val, orig_string;
2911 int changed;
2912 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
2913
2914 realdir = dir;
2915 name = string;
2916 orig_string = Qnil;
2917 specdir = Qnil;
2918 changed = 0;
2919 /* No need to protect ACTION--we only compare it with t and nil. */
2920 GCPRO4 (string, realdir, name, specdir);
2904 2921
2905 if (XSTRING (string)->size == 0) 2922 if (XSTRING (string)->size == 0)
2906 { 2923 {
2907 orig_string = Qnil;
2908 name = string;
2909 realdir = dir;
2910 if (EQ (action, Qlambda)) 2924 if (EQ (action, Qlambda))
2911 return Qnil; 2925 {
2926 UNGCPRO;
2927 return Qnil;
2928 }
2912 } 2929 }
2913 else 2930 else
2914 { 2931 {
2915 orig_string = string; 2932 orig_string = string;
2916 string = Fsubstitute_in_file_name (string); 2933 string = Fsubstitute_in_file_name (string);
2934 changed = NILP (Fstring_equal (string, orig_string));
2917 name = Ffile_name_nondirectory (string); 2935 name = Ffile_name_nondirectory (string);
2918 realdir = Ffile_name_directory (string); 2936 val = Ffile_name_directory (string);
2919 if (NILP (realdir)) 2937 if (! NILP (val))
2920 realdir = dir; 2938 realdir = Fexpand_file_name (val, realdir);
2921 else
2922 realdir = Fexpand_file_name (realdir, dir);
2923 } 2939 }
2924 2940
2925 if (NILP (action)) 2941 if (NILP (action))
2926 { 2942 {
2927 specdir = Ffile_name_directory (string); 2943 specdir = Ffile_name_directory (string);
2928 val = Ffile_name_completion (name, realdir); 2944 val = Ffile_name_completion (name, realdir);
2945 UNGCPRO;
2929 if (XTYPE (val) != Lisp_String) 2946 if (XTYPE (val) != Lisp_String)
2930 { 2947 {
2931 if (NILP (Fstring_equal (string, orig_string))) 2948 if (changed)
2932 return string; 2949 return string;
2933 return (val); 2950 return val;
2934 } 2951 }
2935 2952
2936 if (!NILP (specdir)) 2953 if (!NILP (specdir))
@@ -2962,8 +2979,9 @@ DEFUN ("read-file-name-internal", Fread_file_name_internal, Sread_file_name_inte
2962 } 2979 }
2963 } 2980 }
2964#endif /* Not VMS */ 2981#endif /* Not VMS */
2965 return (val); 2982 return val;
2966 } 2983 }
2984 UNGCPRO;
2967 2985
2968 if (EQ (action, Qt)) 2986 if (EQ (action, Qt))
2969 return Ffile_name_all_completions (name, realdir); 2987 return Ffile_name_all_completions (name, realdir);
@@ -3208,6 +3226,8 @@ passed to that primitive. For example, if you do\n\
3208 (file-exists-p FILENAME)\n\ 3226 (file-exists-p FILENAME)\n\
3209and FILENAME is handled by HANDLER, then HANDLER is called like this:\n\ 3227and FILENAME is handled by HANDLER, then HANDLER is called like this:\n\
3210 (funcall HANDLER 'file-exists-p FILENAME)"); 3228 (funcall HANDLER 'file-exists-p FILENAME)");
3229 Vfile_name_handler_alist = Qnil;
3230
3211 defsubr (&Sfile_name_directory); 3231 defsubr (&Sfile_name_directory);
3212 defsubr (&Sfile_name_nondirectory); 3232 defsubr (&Sfile_name_nondirectory);
3213 defsubr (&Sfile_name_as_directory); 3233 defsubr (&Sfile_name_as_directory);