Mercurial > hg > xemacs-beta
comparison src/fileio.c @ 114:8619ce7e4c50 r20-1b9
Import from CVS: tag r20-1b9
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:21:54 +0200 |
parents | fe104dbd9147 |
children | 9f59509498e1 |
comparison
equal
deleted
inserted
replaced
113:2ec2fe4a4c89 | 114:8619ce7e4c50 |
---|---|
113 /* signal a file error when errno contains a meaningful value. */ | 113 /* signal a file error when errno contains a meaningful value. */ |
114 | 114 |
115 DOESNT_RETURN | 115 DOESNT_RETURN |
116 report_file_error (CONST char *string, Lisp_Object data) | 116 report_file_error (CONST char *string, Lisp_Object data) |
117 { | 117 { |
118 /* #### dmoore - This uses current_buffer, better make sure no one | |
119 has GC'd the current buffer. File handlers are giving me a headache | |
120 maybe I'll just always protect current_buffer around all of those | |
121 calls. */ | |
122 | |
118 /* mrb: #### Needs to be fixed at a lower level; errstring needs to | 123 /* mrb: #### Needs to be fixed at a lower level; errstring needs to |
119 be MULEized. The following at least prevents a crash... */ | 124 be MULEized. The following at least prevents a crash... */ |
120 Lisp_Object errstring = build_ext_string (strerror (errno), FORMAT_BINARY); | 125 Lisp_Object errstring = build_ext_string (strerror (errno), FORMAT_BINARY); |
121 | 126 |
122 /* System error messages are capitalized. Downcase the initial | 127 /* System error messages are capitalized. Downcase the initial |
376 CHECK_STRING (result); | 381 CHECK_STRING (result); |
377 return (result); | 382 return (result); |
378 } | 383 } |
379 | 384 |
380 static Lisp_Object | 385 static Lisp_Object |
386 call2_check_string_or_nil (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1) | |
387 { | |
388 /* This function can GC */ | |
389 Lisp_Object result = call2 (fn, arg0, arg1); | |
390 if (!NILP (result)) | |
391 CHECK_STRING (result); | |
392 return (result); | |
393 } | |
394 | |
395 static Lisp_Object | |
381 call3_check_string (Lisp_Object fn, Lisp_Object arg0, | 396 call3_check_string (Lisp_Object fn, Lisp_Object arg0, |
382 Lisp_Object arg1, Lisp_Object arg2) | 397 Lisp_Object arg1, Lisp_Object arg2) |
383 { | 398 { |
384 /* This function can GC */ | 399 /* This function can GC */ |
385 Lisp_Object result = call3 (fn, arg0, arg1, arg2); | 400 Lisp_Object result = call3 (fn, arg0, arg1, arg2); |
406 | 421 |
407 /* If the file name has special constructs in it, | 422 /* If the file name has special constructs in it, |
408 call the corresponding file handler. */ | 423 call the corresponding file handler. */ |
409 handler = Ffind_file_name_handler (file, Qfile_name_directory); | 424 handler = Ffind_file_name_handler (file, Qfile_name_directory); |
410 if (!NILP (handler)) | 425 if (!NILP (handler)) |
411 { | 426 return (call2_check_string_or_nil (handler, Qfile_name_directory, |
412 Lisp_Object retval = call2 (handler, Qfile_name_directory, | 427 file)); |
413 file); | |
414 | |
415 if (!NILP (retval)) | |
416 CHECK_STRING (retval); | |
417 return retval; | |
418 } | |
419 | 428 |
420 #ifdef FILE_SYSTEM_CASE | 429 #ifdef FILE_SYSTEM_CASE |
421 file = FILE_SYSTEM_CASE (file); | 430 file = FILE_SYSTEM_CASE (file); |
422 #endif | 431 #endif |
423 beg = XSTRING_DATA (file); | 432 beg = XSTRING_DATA (file); |
881 int drive = -1; | 890 int drive = -1; |
882 int relpath = 0; | 891 int relpath = 0; |
883 Bufbyte *tmp, *defdir; | 892 Bufbyte *tmp, *defdir; |
884 #endif /* DOS_NT */ | 893 #endif /* DOS_NT */ |
885 Lisp_Object handler; | 894 Lisp_Object handler; |
895 struct gcpro gcpro1; | |
886 | 896 |
887 CHECK_STRING (name); | 897 CHECK_STRING (name); |
888 | 898 |
889 /* If the file name has special constructs in it, | 899 /* If the file name has special constructs in it, |
890 call the corresponding file handler. */ | 900 call the corresponding file handler. */ |
909 else | 919 else |
910 CHECK_STRING (defalt); | 920 CHECK_STRING (defalt); |
911 | 921 |
912 if (!NILP (defalt)) | 922 if (!NILP (defalt)) |
913 { | 923 { |
924 struct gcpro gcpro1; | |
925 | |
926 GCPRO1 (defalt); /* might be current_buffer->directory */ | |
914 handler = Ffind_file_name_handler (defalt, Qexpand_file_name); | 927 handler = Ffind_file_name_handler (defalt, Qexpand_file_name); |
928 UNGCPRO; | |
915 if (!NILP (handler)) | 929 if (!NILP (handler)) |
916 return call3 (handler, Qexpand_file_name, name, defalt); | 930 return call3 (handler, Qexpand_file_name, name, defalt); |
917 } | 931 } |
918 | 932 |
919 /* Make sure DEFALT is properly expanded. | 933 /* Make sure DEFALT is properly expanded. |
932 && IS_DIRECTORY_SEP (XSTRING_BYTE (defalt, 0)) | 946 && IS_DIRECTORY_SEP (XSTRING_BYTE (defalt, 0)) |
933 && IS_DEVICE_SEP (XSTRING_BYTE (defalt, 1)))) | 947 && IS_DEVICE_SEP (XSTRING_BYTE (defalt, 1)))) |
934 { | 948 { |
935 struct gcpro gcpro1; | 949 struct gcpro gcpro1; |
936 | 950 |
937 GCPRO1 (name); | 951 GCPRO1 (defalt); /* may be current_buffer->directory */ |
938 defalt = Fexpand_file_name (defalt, Qnil); | 952 defalt = Fexpand_file_name (defalt, Qnil); |
939 UNGCPRO; | 953 UNGCPRO; |
940 } | 954 } |
941 | 955 |
942 #ifdef VMS | 956 #ifdef VMS |
945 #endif | 959 #endif |
946 #ifdef FILE_SYSTEM_CASE | 960 #ifdef FILE_SYSTEM_CASE |
947 name = FILE_SYSTEM_CASE (name); | 961 name = FILE_SYSTEM_CASE (name); |
948 #endif | 962 #endif |
949 | 963 |
964 /* #### dmoore - this is ugly, clean this up. Looks like nm | |
965 pointing into name should be safe during all of this, though. */ | |
950 nm = XSTRING_DATA (name); | 966 nm = XSTRING_DATA (name); |
951 | 967 |
952 #ifdef MSDOS | 968 #ifdef MSDOS |
953 /* First map all backslashes to slashes. */ | 969 /* First map all backslashes to slashes. */ |
954 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm)); | 970 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm)); |
1389 Lisp_Object expanded_name; | 1405 Lisp_Object expanded_name; |
1390 Lisp_Object handler; | 1406 Lisp_Object handler; |
1391 | 1407 |
1392 CHECK_STRING (filename); | 1408 CHECK_STRING (filename); |
1393 | 1409 |
1394 GCPRO1 (filename); | |
1395 expanded_name = Fexpand_file_name (filename, defalt); | 1410 expanded_name = Fexpand_file_name (filename, defalt); |
1396 UNGCPRO; | |
1397 | 1411 |
1398 if (!STRINGP (expanded_name)) | 1412 if (!STRINGP (expanded_name)) |
1399 return Qnil; | 1413 return Qnil; |
1400 | 1414 |
1401 GCPRO1 (expanded_name); | 1415 GCPRO1 (expanded_name); |
1526 | 1540 |
1527 /* If the file name has special constructs in it, | 1541 /* If the file name has special constructs in it, |
1528 call the corresponding file handler. */ | 1542 call the corresponding file handler. */ |
1529 handler = Ffind_file_name_handler (string, Qsubstitute_in_file_name); | 1543 handler = Ffind_file_name_handler (string, Qsubstitute_in_file_name); |
1530 if (!NILP (handler)) | 1544 if (!NILP (handler)) |
1531 { | 1545 return (call2_check_string_or_nil (handler, Qsubstitute_in_file_name, |
1532 Lisp_Object retval = call2 (handler, Qsubstitute_in_file_name, | 1546 string)); |
1533 string); | |
1534 | |
1535 if (!NILP (retval)) | |
1536 CHECK_STRING (retval); | |
1537 return retval; | |
1538 } | |
1539 | 1547 |
1540 nm = XSTRING_DATA (string); | 1548 nm = XSTRING_DATA (string); |
1541 #ifdef MSDOS | 1549 #ifdef MSDOS |
1542 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm)); | 1550 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm)); |
1543 substituted = !strcmp (nm, XSTRING_DATA (string)); | 1551 substituted = !strcmp (nm, XSTRING_DATA (string)); |
1982 (dirname)) | 1990 (dirname)) |
1983 { | 1991 { |
1984 /* This function can GC */ | 1992 /* This function can GC */ |
1985 char dir [MAXPATHLEN]; | 1993 char dir [MAXPATHLEN]; |
1986 Lisp_Object handler; | 1994 Lisp_Object handler; |
1987 | |
1988 struct gcpro gcpro1; | 1995 struct gcpro gcpro1; |
1989 | 1996 |
1990 GCPRO1 (dirname); | |
1991 CHECK_STRING (dirname); | 1997 CHECK_STRING (dirname); |
1992 dirname = Fexpand_file_name (dirname, Qnil); | 1998 dirname = Fexpand_file_name (dirname, Qnil); |
1993 | 1999 |
2000 GCPRO1 (dirname); | |
1994 handler = Ffind_file_name_handler (dirname, Qmake_directory_internal); | 2001 handler = Ffind_file_name_handler (dirname, Qmake_directory_internal); |
1995 UNGCPRO; | 2002 UNGCPRO; |
1996 if (!NILP (handler)) | 2003 if (!NILP (handler)) |
1997 return (call2 (handler, Qmake_directory_internal, | 2004 return (call2 (handler, Qmake_directory_internal, dirname)); |
1998 dirname)); | |
1999 | 2005 |
2000 if (XSTRING_LENGTH (dirname) > (sizeof (dir) - 1)) | 2006 if (XSTRING_LENGTH (dirname) > (sizeof (dir) - 1)) |
2001 { | 2007 { |
2002 return Fsignal (Qfile_error, | 2008 return Fsignal (Qfile_error, |
2003 list3 (build_translated_string ("Creating directory"), | 2009 list3 (build_translated_string ("Creating directory"), |
2029 { | 2035 { |
2030 /* This function can GC */ | 2036 /* This function can GC */ |
2031 Lisp_Object handler; | 2037 Lisp_Object handler; |
2032 struct gcpro gcpro1; | 2038 struct gcpro gcpro1; |
2033 | 2039 |
2040 CHECK_STRING (dirname); | |
2041 | |
2034 GCPRO1 (dirname); | 2042 GCPRO1 (dirname); |
2035 CHECK_STRING (dirname); | 2043 dirname = Fexpand_file_name (dirname, Qnil); |
2036 dirname = | 2044 dirname = Fdirectory_file_name (dirname); |
2037 Fdirectory_file_name (Fexpand_file_name (dirname, Qnil)); | |
2038 | 2045 |
2039 handler = Ffind_file_name_handler (dirname, Qdelete_directory); | 2046 handler = Ffind_file_name_handler (dirname, Qdelete_directory); |
2040 UNGCPRO; | 2047 UNGCPRO; |
2041 if (!NILP (handler)) | 2048 if (!NILP (handler)) |
2042 return (call2 (handler, Qdelete_directory, dirname)); | 2049 return (call2 (handler, Qdelete_directory, dirname)); |
2055 { | 2062 { |
2056 /* This function can GC */ | 2063 /* This function can GC */ |
2057 Lisp_Object handler; | 2064 Lisp_Object handler; |
2058 struct gcpro gcpro1; | 2065 struct gcpro gcpro1; |
2059 | 2066 |
2060 GCPRO1 (filename); | |
2061 CHECK_STRING (filename); | 2067 CHECK_STRING (filename); |
2062 filename = Fexpand_file_name (filename, Qnil); | 2068 filename = Fexpand_file_name (filename, Qnil); |
2063 | 2069 |
2070 GCPRO1 (filename); | |
2064 handler = Ffind_file_name_handler (filename, Qdelete_file); | 2071 handler = Ffind_file_name_handler (filename, Qdelete_file); |
2065 UNGCPRO; | 2072 UNGCPRO; |
2066 if (!NILP (handler)) | 2073 if (!NILP (handler)) |
2067 return call2 (handler, Qdelete_file, filename); | 2074 return call2 (handler, Qdelete_file, filename); |
2068 | 2075 |
2549 if (stat ((char *) XSTRING_DATA (abspath), &statbuf) >= 0) | 2556 if (stat ((char *) XSTRING_DATA (abspath), &statbuf) >= 0) |
2550 return (check_writable ((char *) XSTRING_DATA (abspath)) | 2557 return (check_writable ((char *) XSTRING_DATA (abspath)) |
2551 ? Qt : Qnil); | 2558 ? Qt : Qnil); |
2552 | 2559 |
2553 | 2560 |
2561 GCPRO1 (abspath); | |
2554 dir = Ffile_name_directory (abspath); | 2562 dir = Ffile_name_directory (abspath); |
2563 UNGCPRO; | |
2555 #if defined (VMS) || defined (MSDOS) | 2564 #if defined (VMS) || defined (MSDOS) |
2556 if (!NILP (dir)) | 2565 if (!NILP (dir)) |
2557 dir = Fdirectory_file_name (dir); | 2566 { |
2567 GCPRO1(dir); | |
2568 dir = Fdirectory_file_name (dir); | |
2569 UNGCPRO; | |
2570 } | |
2558 #endif /* VMS or MSDOS */ | 2571 #endif /* VMS or MSDOS */ |
2559 return (check_writable (!NILP (dir) ? (char *) XSTRING_DATA (dir) | 2572 return (check_writable (!NILP (dir) ? (char *) XSTRING_DATA (dir) |
2560 : "") | 2573 : "") |
2561 ? Qt : Qnil); | 2574 ? Qt : Qnil); |
2562 } | 2575 } |
2624 Lisp_Object abspath; | 2637 Lisp_Object abspath; |
2625 struct stat st; | 2638 struct stat st; |
2626 Lisp_Object handler; | 2639 Lisp_Object handler; |
2627 struct gcpro gcpro1; | 2640 struct gcpro gcpro1; |
2628 | 2641 |
2629 GCPRO1 (filename); | 2642 GCPRO1 (current_buffer->directory); |
2630 abspath = expand_and_dir_to_file (filename, | 2643 abspath = expand_and_dir_to_file (filename, |
2631 current_buffer->directory); | 2644 current_buffer->directory); |
2632 UNGCPRO; | 2645 UNGCPRO; |
2633 | 2646 |
2634 /* If the file name has special constructs in it, | 2647 /* If the file name has special constructs in it, |
2663 handler = Ffind_file_name_handler (filename, Qfile_accessible_directory_p); | 2676 handler = Ffind_file_name_handler (filename, Qfile_accessible_directory_p); |
2664 if (!NILP (handler)) | 2677 if (!NILP (handler)) |
2665 return call2 (handler, Qfile_accessible_directory_p, | 2678 return call2 (handler, Qfile_accessible_directory_p, |
2666 filename); | 2679 filename); |
2667 | 2680 |
2681 /* #### dmoore - this gcpro on filename should be unneccesary since | |
2682 the caller should ahve already protected it. */ | |
2668 GCPRO1 (filename); | 2683 GCPRO1 (filename); |
2669 if (NILP (Ffile_directory_p (filename))) | 2684 if (NILP (Ffile_directory_p (filename))) |
2670 { | 2685 { |
2671 UNGCPRO; | 2686 UNGCPRO; |
2672 return (Qnil); | 2687 return (Qnil); |
2680 "Return t if file FILENAME is the name of a regular file. | 2695 "Return t if file FILENAME is the name of a regular file. |
2681 This is the sort of file that holds an ordinary stream of data bytes. | 2696 This is the sort of file that holds an ordinary stream of data bytes. |
2682 */ | 2697 */ |
2683 (filename)) | 2698 (filename)) |
2684 { | 2699 { |
2685 REGISTER Lisp_Object abspath; | 2700 Lisp_Object abspath; |
2686 struct stat st; | 2701 struct stat st; |
2687 Lisp_Object handler; | 2702 Lisp_Object handler; |
2688 | 2703 struct gcpro gcpro1; |
2704 | |
2705 GCPRO1 (current_buffer->directory); | |
2689 abspath = expand_and_dir_to_file (filename, current_buffer->directory); | 2706 abspath = expand_and_dir_to_file (filename, current_buffer->directory); |
2707 UNGCPRO; | |
2690 | 2708 |
2691 /* If the file name has special constructs in it, | 2709 /* If the file name has special constructs in it, |
2692 call the corresponding file handler. */ | 2710 call the corresponding file handler. */ |
2711 GCPRO1 (abspath); | |
2693 handler = Ffind_file_name_handler (abspath, Qfile_regular_p); | 2712 handler = Ffind_file_name_handler (abspath, Qfile_regular_p); |
2713 UNGCPRO; | |
2694 if (!NILP (handler)) | 2714 if (!NILP (handler)) |
2695 return call2 (handler, Qfile_regular_p, abspath); | 2715 return call2 (handler, Qfile_regular_p, abspath); |
2696 | 2716 |
2697 if (stat ((char *) XSTRING_DATA (abspath), &st) < 0) | 2717 if (stat ((char *) XSTRING_DATA (abspath), &st) < 0) |
2698 return Qnil; | 2718 return Qnil; |
2708 Lisp_Object abspath; | 2728 Lisp_Object abspath; |
2709 struct stat st; | 2729 struct stat st; |
2710 Lisp_Object handler; | 2730 Lisp_Object handler; |
2711 struct gcpro gcpro1; | 2731 struct gcpro gcpro1; |
2712 | 2732 |
2713 GCPRO1 (filename); | 2733 GCPRO1 (current_buffer->directory); |
2714 abspath = expand_and_dir_to_file (filename, | 2734 abspath = expand_and_dir_to_file (filename, |
2715 current_buffer->directory); | 2735 current_buffer->directory); |
2716 UNGCPRO; | 2736 UNGCPRO; |
2717 | 2737 |
2718 /* If the file name has special constructs in it, | 2738 /* If the file name has special constructs in it, |
2740 (filename, mode)) | 2760 (filename, mode)) |
2741 { | 2761 { |
2742 /* This function can GC */ | 2762 /* This function can GC */ |
2743 Lisp_Object abspath; | 2763 Lisp_Object abspath; |
2744 Lisp_Object handler; | 2764 Lisp_Object handler; |
2745 struct gcpro gcpro1, gcpro2; | 2765 struct gcpro gcpro1; |
2746 | 2766 |
2747 GCPRO2 (filename, mode); | 2767 GCPRO1 (current_buffer->directory); |
2748 abspath = Fexpand_file_name (filename, current_buffer->directory); | 2768 abspath = Fexpand_file_name (filename, current_buffer->directory); |
2749 CHECK_INT (mode); | 2769 CHECK_INT (mode); |
2750 UNGCPRO; | 2770 UNGCPRO; |
2751 | 2771 |
2752 /* If the file name has special constructs in it, | 2772 /* If the file name has special constructs in it, |
2819 /* This function can GC */ | 2839 /* This function can GC */ |
2820 Lisp_Object abspath1, abspath2; | 2840 Lisp_Object abspath1, abspath2; |
2821 struct stat st; | 2841 struct stat st; |
2822 int mtime1; | 2842 int mtime1; |
2823 Lisp_Object handler; | 2843 Lisp_Object handler; |
2824 struct gcpro gcpro1, gcpro2; | 2844 struct gcpro gcpro1, gcpro2, gcpro3; |
2825 | 2845 |
2826 CHECK_STRING (file1); | 2846 CHECK_STRING (file1); |
2827 CHECK_STRING (file2); | 2847 CHECK_STRING (file2); |
2828 | 2848 |
2829 abspath1 = Qnil; | 2849 abspath1 = Qnil; |
2830 GCPRO2 (abspath1, file2); | 2850 abspath2 = Qnil; |
2831 abspath1 = expand_and_dir_to_file (file1, | 2851 |
2832 current_buffer->directory); | 2852 GCPRO3 (abspath1, abspath2, current_buffer->directory); |
2833 abspath2 = expand_and_dir_to_file (file2, | 2853 abspath1 = expand_and_dir_to_file (file1, current_buffer->directory); |
2834 current_buffer->directory); | 2854 abspath2 = expand_and_dir_to_file (file2, current_buffer->directory); |
2835 UNGCPRO; | |
2836 | 2855 |
2837 /* If the file name has special constructs in it, | 2856 /* If the file name has special constructs in it, |
2838 call the corresponding file handler. */ | 2857 call the corresponding file handler. */ |
2839 GCPRO2 (abspath1, abspath2); | |
2840 handler = Ffind_file_name_handler (abspath1, Qfile_newer_than_file_p); | 2858 handler = Ffind_file_name_handler (abspath1, Qfile_newer_than_file_p); |
2841 if (NILP (handler)) | 2859 if (NILP (handler)) |
2842 handler = Ffind_file_name_handler (abspath2, Qfile_newer_than_file_p); | 2860 handler = Ffind_file_name_handler (abspath2, Qfile_newer_than_file_p); |
2843 UNGCPRO; | 2861 UNGCPRO; |
2844 if (!NILP (handler)) | 2862 if (!NILP (handler)) |
2888 struct stat st; | 2906 struct stat st; |
2889 int fd; | 2907 int fd; |
2890 int saverrno = 0; | 2908 int saverrno = 0; |
2891 Charcount inserted = 0; | 2909 Charcount inserted = 0; |
2892 int speccount; | 2910 int speccount; |
2893 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | 2911 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
2894 Lisp_Object handler = Qnil, val; | 2912 Lisp_Object handler = Qnil, val; |
2895 int total; | 2913 int total; |
2896 Bufbyte read_buf[READ_BUF_SIZE]; | 2914 Bufbyte read_buf[READ_BUF_SIZE]; |
2897 int mc_count; | 2915 int mc_count; |
2898 struct buffer *buf = current_buffer; | 2916 struct buffer *buf = current_buffer; |
2917 Lisp_Object curbuf; | |
2899 int not_regular = 0; | 2918 int not_regular = 0; |
2900 | 2919 |
2901 if (buf->base_buffer && ! NILP (visit)) | 2920 if (buf->base_buffer && ! NILP (visit)) |
2902 error ("Cannot do file visiting in an indirect buffer"); | 2921 error ("Cannot do file visiting in an indirect buffer"); |
2903 | 2922 |
2904 /* No need to call Fbarf_if_buffer_read_only() here. | 2923 /* No need to call Fbarf_if_buffer_read_only() here. |
2905 That's called in begin_multiple_change() or wherever. */ | 2924 That's called in begin_multiple_change() or wherever. */ |
2906 | 2925 |
2907 val = Qnil; | 2926 val = Qnil; |
2908 | 2927 |
2909 GCPRO4 (filename, val, visit, handler); | 2928 /* #### dmoore - should probably check in various places to see if |
2929 curbuf was killed and if so signal an error? */ | |
2930 | |
2931 XSETBUFFER (curbuf, buf); | |
2932 | |
2933 GCPRO5 (filename, val, visit, handler, curbuf); | |
2910 | 2934 |
2911 mc_count = (NILP (replace)) ? | 2935 mc_count = (NILP (replace)) ? |
2912 begin_multiple_change (buf, BUF_PT (buf), BUF_PT (buf)) : | 2936 begin_multiple_change (buf, BUF_PT (buf), BUF_PT (buf)) : |
2913 begin_multiple_change (buf, BUF_BEG (buf), BUF_Z (buf)); | 2937 begin_multiple_change (buf, BUF_BEG (buf), BUF_Z (buf)); |
2914 | 2938 |
3356 Lisp_Object visit_file = Qnil; | 3380 Lisp_Object visit_file = Qnil; |
3357 Lisp_Object annotations = Qnil; | 3381 Lisp_Object annotations = Qnil; |
3358 struct buffer *given_buffer; | 3382 struct buffer *given_buffer; |
3359 Bufpos start1, end1; | 3383 Bufpos start1, end1; |
3360 | 3384 |
3385 /* #### dmoore - if Fexpand_file_name or handlers kill the buffer, | |
3386 we should signal an error rather than blissfully continuing | |
3387 along. ARGH, this function is going to lose lose lose. We need | |
3388 to protect the current_buffer from being destroyed, but the | |
3389 multiple return points make this a pain in the butt. */ | |
3390 | |
3361 #ifdef DOS_NT | 3391 #ifdef DOS_NT |
3362 int buffer_file_type | 3392 int buffer_file_type |
3363 = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY; | 3393 = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY; |
3364 #endif /* DOS_NT */ | 3394 #endif /* DOS_NT */ |
3365 | 3395 |
3374 get_buffer_range_char (current_buffer, start, end, &start1, &end1, 0); | 3404 get_buffer_range_char (current_buffer, start, end, &start1, &end1, 0); |
3375 | 3405 |
3376 { | 3406 { |
3377 Lisp_Object handler; | 3407 Lisp_Object handler; |
3378 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; | 3408 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
3409 | |
3379 GCPRO5 (start, filename, visit, visit_file, lockname); | 3410 GCPRO5 (start, filename, visit, visit_file, lockname); |
3380 | 3411 |
3381 if (visiting_other) | 3412 if (visiting_other) |
3382 visit_file = Fexpand_file_name (visit, Qnil); | 3413 visit_file = Fexpand_file_name (visit, Qnil); |
3383 else | 3414 else |
3413 } | 3444 } |
3414 | 3445 |
3415 #ifdef CLASH_DETECTION | 3446 #ifdef CLASH_DETECTION |
3416 if (!auto_saving) | 3447 if (!auto_saving) |
3417 { | 3448 { |
3418 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | 3449 Lisp_Object curbuf; |
3419 GCPRO4 (start, filename, visit_file, lockname); | 3450 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
3451 | |
3452 XSETBUFFER (curbuf, current_buffer); | |
3453 GCPRO5 (start, filename, visit_file, lockname, curbuf); | |
3420 lock_file (lockname); | 3454 lock_file (lockname); |
3421 UNGCPRO; | 3455 UNGCPRO; |
3422 } | 3456 } |
3423 #endif /* CLASH_DETECTION */ | 3457 #endif /* CLASH_DETECTION */ |
3424 | 3458 |
4059 else | 4093 else |
4060 { | 4094 { |
4061 Lisp_Object filename; | 4095 Lisp_Object filename; |
4062 struct stat st; | 4096 struct stat st; |
4063 Lisp_Object handler; | 4097 Lisp_Object handler; |
4064 struct gcpro gcpro1, gcpro2; | 4098 struct gcpro gcpro1, gcpro2, gcpro3; |
4065 | 4099 |
4066 GCPRO2 (filename, time_list); | 4100 GCPRO3 (filename, time_list, current_buffer->filename); |
4067 filename = Fexpand_file_name (current_buffer->filename, | 4101 filename = Fexpand_file_name (current_buffer->filename, Qnil); |
4068 Qnil); | |
4069 | 4102 |
4070 /* If the file name has special constructs in it, | 4103 /* If the file name has special constructs in it, |
4071 call the corresponding file handler. */ | 4104 call the corresponding file handler. */ |
4072 handler = Ffind_file_name_handler (filename, Qset_visited_file_modtime); | 4105 handler = Ffind_file_name_handler (filename, Qset_visited_file_modtime); |
4073 UNGCPRO; | 4106 UNGCPRO; |
4115 } | 4148 } |
4116 | 4149 |
4117 if (!set_time_to_use) | 4150 if (!set_time_to_use) |
4118 { | 4151 { |
4119 Lisp_Object filename = Qnil; | 4152 Lisp_Object filename = Qnil; |
4120 struct gcpro gcpro1, gcpro2; | 4153 struct gcpro gcpro1; |
4121 GCPRO2 (buf, filename); | 4154 GCPRO1 (filename); |
4155 /* #### dmoore - do we need to protect XBUFFER (buf)->filename? | |
4156 What if a ^(*&^&*^*& handler renames a buffer? I think I'm | |
4157 getting a headache now. */ | |
4122 | 4158 |
4123 if (STRINGP (XBUFFER (buf)->filename)) | 4159 if (STRINGP (XBUFFER (buf)->filename)) |
4124 filename = Fexpand_file_name (XBUFFER (buf)->filename, | 4160 filename = Fexpand_file_name (XBUFFER (buf)->filename, Qnil); |
4125 Qnil); | |
4126 else | 4161 else |
4127 filename = Qnil; | 4162 filename = Qnil; |
4128 | |
4129 UNGCPRO; | |
4130 | 4163 |
4131 if (!NILP (filename) && !NILP (Ffile_exists_p (filename))) | 4164 if (!NILP (filename) && !NILP (Ffile_exists_p (filename))) |
4132 { | 4165 { |
4133 Lisp_Object handler; | 4166 Lisp_Object handler; |
4134 | 4167 |
4135 /* If the file name has special constructs in it, | 4168 /* If the file name has special constructs in it, |
4136 call the corresponding file handler. */ | 4169 call the corresponding file handler. */ |
4137 GCPRO1 (filename); | |
4138 handler = Ffind_file_name_handler (filename, Qset_buffer_modtime); | 4170 handler = Ffind_file_name_handler (filename, Qset_buffer_modtime); |
4139 UNGCPRO; | 4171 UNGCPRO; |
4140 if (!NILP (handler)) | 4172 if (!NILP (handler)) |
4141 /* The handler can find the file name the same way we did. */ | 4173 /* The handler can find the file name the same way we did. */ |
4142 return (call2 (handler, Qset_buffer_modtime, Qnil)); | 4174 return (call2 (handler, Qset_buffer_modtime, Qnil)); |
4147 else | 4179 else |
4148 time_to_use = time ((time_t *) 0); | 4180 time_to_use = time ((time_t *) 0); |
4149 } | 4181 } |
4150 } | 4182 } |
4151 else | 4183 else |
4152 time_to_use = time ((time_t *) 0); | 4184 { |
4185 UNGCPRO; | |
4186 time_to_use = time ((time_t *) 0); | |
4187 } | |
4153 } | 4188 } |
4154 | 4189 |
4155 XBUFFER (buf)->modtime = time_to_use; | 4190 XBUFFER (buf)->modtime = time_to_use; |
4156 | 4191 |
4157 return Qnil; | 4192 return Qnil; |
4158 } | 4193 } |
4159 | 4194 |
4160 | 4195 |
4161 static Lisp_Object | 4196 static Lisp_Object |