comparison src/fileio.c @ 40:7e54bd776075 r19-15b103

Import from CVS: tag r19-15b103
author cvs
date Mon, 13 Aug 2007 08:54:25 +0200
parents e04119814345
children 8d2a9b52c682
comparison
equal deleted inserted replaced
39:06f275776fba 40:7e54bd776075
110 /* signal a file error when errno contains a meaningful value. */ 110 /* signal a file error when errno contains a meaningful value. */
111 111
112 DOESNT_RETURN 112 DOESNT_RETURN
113 report_file_error (CONST char *string, Lisp_Object data) 113 report_file_error (CONST char *string, Lisp_Object data)
114 { 114 {
115 /* #### dmoore - This uses current_buffer, better make sure no one
116 has GC'd the current buffer. File handlers are giving me a headache
117 maybe I'll just always protect current_buffer around all of those
118 calls. */
119
115 /* mrb: #### Needs to be fixed at a lower level; errstring needs to 120 /* mrb: #### Needs to be fixed at a lower level; errstring needs to
116 be MULEized. The following at least prevents a crash... */ 121 be MULEized. The following at least prevents a crash... */
117 Lisp_Object errstring = build_ext_string (strerror (errno), FORMAT_BINARY); 122 Lisp_Object errstring = build_ext_string (strerror (errno), FORMAT_BINARY);
118 123
119 /* System error messages are capitalized. Downcase the initial 124 /* System error messages are capitalized. Downcase the initial
373 CHECK_STRING (result); 378 CHECK_STRING (result);
374 return (result); 379 return (result);
375 } 380 }
376 381
377 static Lisp_Object 382 static Lisp_Object
383 call2_check_string_or_nil (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1)
384 {
385 /* This function can GC */
386 Lisp_Object result = call2 (fn, arg0, arg1);
387 if (!NILP (result))
388 CHECK_STRING (result);
389 return (result);
390 }
391
392 static Lisp_Object
378 call3_check_string (Lisp_Object fn, Lisp_Object arg0, 393 call3_check_string (Lisp_Object fn, Lisp_Object arg0,
379 Lisp_Object arg1, Lisp_Object arg2) 394 Lisp_Object arg1, Lisp_Object arg2)
380 { 395 {
381 /* This function can GC */ 396 /* This function can GC */
382 Lisp_Object result = call3 (fn, arg0, arg1, arg2); 397 Lisp_Object result = call3 (fn, arg0, arg1, arg2);
403 418
404 /* If the file name has special constructs in it, 419 /* If the file name has special constructs in it,
405 call the corresponding file handler. */ 420 call the corresponding file handler. */
406 handler = Ffind_file_name_handler (file, Qfile_name_directory); 421 handler = Ffind_file_name_handler (file, Qfile_name_directory);
407 if (!NILP (handler)) 422 if (!NILP (handler))
408 { 423 return (call2_check_string_or_nil (handler, Qfile_name_directory,
409 Lisp_Object retval = call2 (handler, Qfile_name_directory, 424 file));
410 file);
411
412 if (!NILP (retval))
413 CHECK_STRING (retval);
414 return retval;
415 }
416 425
417 #ifdef FILE_SYSTEM_CASE 426 #ifdef FILE_SYSTEM_CASE
418 file = FILE_SYSTEM_CASE (file); 427 file = FILE_SYSTEM_CASE (file);
419 #endif 428 #endif
420 beg = XSTRING_DATA (file); 429 beg = XSTRING_DATA (file);
878 int drive = -1; 887 int drive = -1;
879 int relpath = 0; 888 int relpath = 0;
880 Bufbyte *tmp, *defdir; 889 Bufbyte *tmp, *defdir;
881 #endif /* DOS_NT */ 890 #endif /* DOS_NT */
882 Lisp_Object handler; 891 Lisp_Object handler;
892 struct gcpro gcpro1;
883 893
884 CHECK_STRING (name); 894 CHECK_STRING (name);
885 895
886 /* If the file name has special constructs in it, 896 /* If the file name has special constructs in it,
887 call the corresponding file handler. */ 897 call the corresponding file handler. */
906 else 916 else
907 CHECK_STRING (defalt); 917 CHECK_STRING (defalt);
908 918
909 if (!NILP (defalt)) 919 if (!NILP (defalt))
910 { 920 {
921 struct gcpro gcpro1;
922
923 GCPRO1 (defalt); /* might be current_buffer->directory */
911 handler = Ffind_file_name_handler (defalt, Qexpand_file_name); 924 handler = Ffind_file_name_handler (defalt, Qexpand_file_name);
925 UNGCPRO;
912 if (!NILP (handler)) 926 if (!NILP (handler))
913 return call3 (handler, Qexpand_file_name, name, defalt); 927 return call3 (handler, Qexpand_file_name, name, defalt);
914 } 928 }
915 929
916 /* Make sure DEFALT is properly expanded. 930 /* Make sure DEFALT is properly expanded.
929 && IS_DIRECTORY_SEP (XSTRING_BYTE (defalt, 0)) 943 && IS_DIRECTORY_SEP (XSTRING_BYTE (defalt, 0))
930 && IS_DEVICE_SEP (XSTRING_BYTE (defalt, 1)))) 944 && IS_DEVICE_SEP (XSTRING_BYTE (defalt, 1))))
931 { 945 {
932 struct gcpro gcpro1; 946 struct gcpro gcpro1;
933 947
934 GCPRO1 (name); 948 GCPRO1 (defalt); /* may be current_buffer->directory */
935 defalt = Fexpand_file_name (defalt, Qnil); 949 defalt = Fexpand_file_name (defalt, Qnil);
936 UNGCPRO; 950 UNGCPRO;
937 } 951 }
938 952
939 #ifdef VMS 953 #ifdef VMS
942 #endif 956 #endif
943 #ifdef FILE_SYSTEM_CASE 957 #ifdef FILE_SYSTEM_CASE
944 name = FILE_SYSTEM_CASE (name); 958 name = FILE_SYSTEM_CASE (name);
945 #endif 959 #endif
946 960
961 /* #### dmoore - this is ugly, clean this up. Looks like nm
962 pointing into name should be safe during all of this, though. */
947 nm = XSTRING_DATA (name); 963 nm = XSTRING_DATA (name);
948 964
949 #ifdef MSDOS 965 #ifdef MSDOS
950 /* First map all backslashes to slashes. */ 966 /* First map all backslashes to slashes. */
951 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm)); 967 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm));
1386 Lisp_Object expanded_name; 1402 Lisp_Object expanded_name;
1387 Lisp_Object handler; 1403 Lisp_Object handler;
1388 1404
1389 CHECK_STRING (filename); 1405 CHECK_STRING (filename);
1390 1406
1391 GCPRO1 (filename);
1392 expanded_name = Fexpand_file_name (filename, defalt); 1407 expanded_name = Fexpand_file_name (filename, defalt);
1393 UNGCPRO;
1394 1408
1395 if (!STRINGP (expanded_name)) 1409 if (!STRINGP (expanded_name))
1396 return Qnil; 1410 return Qnil;
1397 1411
1398 GCPRO1 (expanded_name); 1412 GCPRO1 (expanded_name);
1523 1537
1524 /* If the file name has special constructs in it, 1538 /* If the file name has special constructs in it,
1525 call the corresponding file handler. */ 1539 call the corresponding file handler. */
1526 handler = Ffind_file_name_handler (string, Qsubstitute_in_file_name); 1540 handler = Ffind_file_name_handler (string, Qsubstitute_in_file_name);
1527 if (!NILP (handler)) 1541 if (!NILP (handler))
1528 { 1542 return (call2_check_string_or_nil (handler, Qsubstitute_in_file_name,
1529 Lisp_Object retval = call2 (handler, Qsubstitute_in_file_name, 1543 string));
1530 string);
1531
1532 if (!NILP (retval))
1533 CHECK_STRING (retval);
1534 return retval;
1535 }
1536 1544
1537 nm = XSTRING_DATA (string); 1545 nm = XSTRING_DATA (string);
1538 #ifdef MSDOS 1546 #ifdef MSDOS
1539 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm)); 1547 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm));
1540 substituted = !strcmp (nm, XSTRING_DATA (string)); 1548 substituted = !strcmp (nm, XSTRING_DATA (string));
1979 (dirname)) 1987 (dirname))
1980 { 1988 {
1981 /* This function can GC */ 1989 /* This function can GC */
1982 char dir [MAXPATHLEN]; 1990 char dir [MAXPATHLEN];
1983 Lisp_Object handler; 1991 Lisp_Object handler;
1984
1985 struct gcpro gcpro1; 1992 struct gcpro gcpro1;
1986 1993
1987 GCPRO1 (dirname);
1988 CHECK_STRING (dirname); 1994 CHECK_STRING (dirname);
1989 dirname = Fexpand_file_name (dirname, Qnil); 1995 dirname = Fexpand_file_name (dirname, Qnil);
1990 1996
1997 GCPRO1 (dirname);
1991 handler = Ffind_file_name_handler (dirname, Qmake_directory_internal); 1998 handler = Ffind_file_name_handler (dirname, Qmake_directory_internal);
1992 UNGCPRO; 1999 UNGCPRO;
1993 if (!NILP (handler)) 2000 if (!NILP (handler))
1994 return (call2 (handler, Qmake_directory_internal, 2001 return (call2 (handler, Qmake_directory_internal, dirname));
1995 dirname));
1996 2002
1997 if (XSTRING_LENGTH (dirname) > (sizeof (dir) - 1)) 2003 if (XSTRING_LENGTH (dirname) > (sizeof (dir) - 1))
1998 { 2004 {
1999 return Fsignal (Qfile_error, 2005 return Fsignal (Qfile_error,
2000 list3 (build_translated_string ("Creating directory"), 2006 list3 (build_translated_string ("Creating directory"),
2026 { 2032 {
2027 /* This function can GC */ 2033 /* This function can GC */
2028 Lisp_Object handler; 2034 Lisp_Object handler;
2029 struct gcpro gcpro1; 2035 struct gcpro gcpro1;
2030 2036
2037 CHECK_STRING (dirname);
2038
2031 GCPRO1 (dirname); 2039 GCPRO1 (dirname);
2032 CHECK_STRING (dirname); 2040 dirname = Fexpand_file_name (dirname, Qnil);
2033 dirname = 2041 dirname = Fdirectory_file_name (dirname);
2034 Fdirectory_file_name (Fexpand_file_name (dirname, Qnil));
2035 2042
2036 handler = Ffind_file_name_handler (dirname, Qdelete_directory); 2043 handler = Ffind_file_name_handler (dirname, Qdelete_directory);
2037 UNGCPRO; 2044 UNGCPRO;
2038 if (!NILP (handler)) 2045 if (!NILP (handler))
2039 return (call2 (handler, Qdelete_directory, dirname)); 2046 return (call2 (handler, Qdelete_directory, dirname));
2052 { 2059 {
2053 /* This function can GC */ 2060 /* This function can GC */
2054 Lisp_Object handler; 2061 Lisp_Object handler;
2055 struct gcpro gcpro1; 2062 struct gcpro gcpro1;
2056 2063
2057 GCPRO1 (filename);
2058 CHECK_STRING (filename); 2064 CHECK_STRING (filename);
2059 filename = Fexpand_file_name (filename, Qnil); 2065 filename = Fexpand_file_name (filename, Qnil);
2060 2066
2067 GCPRO1 (filename);
2061 handler = Ffind_file_name_handler (filename, Qdelete_file); 2068 handler = Ffind_file_name_handler (filename, Qdelete_file);
2062 UNGCPRO; 2069 UNGCPRO;
2063 if (!NILP (handler)) 2070 if (!NILP (handler))
2064 return call2 (handler, Qdelete_file, filename); 2071 return call2 (handler, Qdelete_file, filename);
2065 2072
2545 if (stat ((char *) XSTRING_DATA (abspath), &statbuf) >= 0) 2552 if (stat ((char *) XSTRING_DATA (abspath), &statbuf) >= 0)
2546 return (check_writable ((char *) XSTRING_DATA (abspath)) 2553 return (check_writable ((char *) XSTRING_DATA (abspath))
2547 ? Qt : Qnil); 2554 ? Qt : Qnil);
2548 2555
2549 2556
2557 GCPRO1 (abspath);
2550 dir = Ffile_name_directory (abspath); 2558 dir = Ffile_name_directory (abspath);
2559 UNGCPRO;
2551 #if defined (VMS) || defined (MSDOS) 2560 #if defined (VMS) || defined (MSDOS)
2552 if (!NILP (dir)) 2561 if (!NILP (dir))
2553 dir = Fdirectory_file_name (dir); 2562 {
2563 GCPRO1(dir);
2564 dir = Fdirectory_file_name (dir);
2565 UNGCPRO;
2566 }
2554 #endif /* VMS or MSDOS */ 2567 #endif /* VMS or MSDOS */
2555 return (check_writable (!NILP (dir) ? (char *) XSTRING_DATA (dir) 2568 return (check_writable (!NILP (dir) ? (char *) XSTRING_DATA (dir)
2556 : "") 2569 : "")
2557 ? Qt : Qnil); 2570 ? Qt : Qnil);
2558 } 2571 }
2620 Lisp_Object abspath; 2633 Lisp_Object abspath;
2621 struct stat st; 2634 struct stat st;
2622 Lisp_Object handler; 2635 Lisp_Object handler;
2623 struct gcpro gcpro1; 2636 struct gcpro gcpro1;
2624 2637
2625 GCPRO1 (filename); 2638 GCPRO1 (current_buffer->directory);
2626 abspath = expand_and_dir_to_file (filename, 2639 abspath = expand_and_dir_to_file (filename,
2627 current_buffer->directory); 2640 current_buffer->directory);
2628 UNGCPRO; 2641 UNGCPRO;
2629 2642
2630 /* If the file name has special constructs in it, 2643 /* If the file name has special constructs in it,
2659 handler = Ffind_file_name_handler (filename, Qfile_accessible_directory_p); 2672 handler = Ffind_file_name_handler (filename, Qfile_accessible_directory_p);
2660 if (!NILP (handler)) 2673 if (!NILP (handler))
2661 return call2 (handler, Qfile_accessible_directory_p, 2674 return call2 (handler, Qfile_accessible_directory_p,
2662 filename); 2675 filename);
2663 2676
2677 /* #### dmoore - this gcpro on filename should be unneccesary since
2678 the caller should ahve already protected it. */
2664 GCPRO1 (filename); 2679 GCPRO1 (filename);
2665 if (NILP (Ffile_directory_p (filename))) 2680 if (NILP (Ffile_directory_p (filename)))
2666 { 2681 {
2667 UNGCPRO; 2682 UNGCPRO;
2668 return (Qnil); 2683 return (Qnil);
2676 "Return t if file FILENAME is the name of a regular file. 2691 "Return t if file FILENAME is the name of a regular file.
2677 This is the sort of file that holds an ordinary stream of data bytes. 2692 This is the sort of file that holds an ordinary stream of data bytes.
2678 */ 2693 */
2679 (filename)) 2694 (filename))
2680 { 2695 {
2681 REGISTER Lisp_Object abspath; 2696 Lisp_Object abspath;
2682 struct stat st; 2697 struct stat st;
2683 Lisp_Object handler; 2698 Lisp_Object handler;
2684 2699 struct gcpro gcpro1;
2700
2701 GCPRO1 (current_buffer->directory);
2685 abspath = expand_and_dir_to_file (filename, current_buffer->directory); 2702 abspath = expand_and_dir_to_file (filename, current_buffer->directory);
2703 UNGCPRO;
2686 2704
2687 /* If the file name has special constructs in it, 2705 /* If the file name has special constructs in it,
2688 call the corresponding file handler. */ 2706 call the corresponding file handler. */
2707 GCPRO1 (abspath);
2689 handler = Ffind_file_name_handler (abspath, Qfile_regular_p); 2708 handler = Ffind_file_name_handler (abspath, Qfile_regular_p);
2709 UNGCPRO;
2690 if (!NILP (handler)) 2710 if (!NILP (handler))
2691 return call2 (handler, Qfile_regular_p, abspath); 2711 return call2 (handler, Qfile_regular_p, abspath);
2692 2712
2693 if (stat ((char *) XSTRING_DATA (abspath), &st) < 0) 2713 if (stat ((char *) XSTRING_DATA (abspath), &st) < 0)
2694 return Qnil; 2714 return Qnil;
2704 Lisp_Object abspath; 2724 Lisp_Object abspath;
2705 struct stat st; 2725 struct stat st;
2706 Lisp_Object handler; 2726 Lisp_Object handler;
2707 struct gcpro gcpro1; 2727 struct gcpro gcpro1;
2708 2728
2709 GCPRO1 (filename); 2729 GCPRO1 (current_buffer->directory);
2710 abspath = expand_and_dir_to_file (filename, 2730 abspath = expand_and_dir_to_file (filename,
2711 current_buffer->directory); 2731 current_buffer->directory);
2712 UNGCPRO; 2732 UNGCPRO;
2713 2733
2714 /* If the file name has special constructs in it, 2734 /* If the file name has special constructs in it,
2736 (filename, mode)) 2756 (filename, mode))
2737 { 2757 {
2738 /* This function can GC */ 2758 /* This function can GC */
2739 Lisp_Object abspath; 2759 Lisp_Object abspath;
2740 Lisp_Object handler; 2760 Lisp_Object handler;
2741 struct gcpro gcpro1, gcpro2; 2761 struct gcpro gcpro1;
2742 2762
2743 GCPRO2 (filename, mode); 2763 GCPRO1 (current_buffer->directory);
2744 abspath = Fexpand_file_name (filename, current_buffer->directory); 2764 abspath = Fexpand_file_name (filename, current_buffer->directory);
2745 CHECK_INT (mode); 2765 CHECK_INT (mode);
2746 UNGCPRO; 2766 UNGCPRO;
2747 2767
2748 /* If the file name has special constructs in it, 2768 /* If the file name has special constructs in it,
2813 /* This function can GC */ 2833 /* This function can GC */
2814 Lisp_Object abspath1, abspath2; 2834 Lisp_Object abspath1, abspath2;
2815 struct stat st; 2835 struct stat st;
2816 int mtime1; 2836 int mtime1;
2817 Lisp_Object handler; 2837 Lisp_Object handler;
2818 struct gcpro gcpro1, gcpro2; 2838 struct gcpro gcpro1, gcpro2, gcpro3;
2819 2839
2820 CHECK_STRING (file1); 2840 CHECK_STRING (file1);
2821 CHECK_STRING (file2); 2841 CHECK_STRING (file2);
2822 2842
2823 abspath1 = Qnil; 2843 abspath1 = Qnil;
2824 GCPRO2 (abspath1, file2); 2844 abspath2 = Qnil;
2825 abspath1 = expand_and_dir_to_file (file1, 2845
2826 current_buffer->directory); 2846 GCPRO3 (abspath1, abspath2, current_buffer->directory);
2827 abspath2 = expand_and_dir_to_file (file2, 2847 abspath1 = expand_and_dir_to_file (file1, current_buffer->directory);
2828 current_buffer->directory); 2848 abspath2 = expand_and_dir_to_file (file2, current_buffer->directory);
2829 UNGCPRO;
2830 2849
2831 /* If the file name has special constructs in it, 2850 /* If the file name has special constructs in it,
2832 call the corresponding file handler. */ 2851 call the corresponding file handler. */
2833 GCPRO2 (abspath1, abspath2);
2834 handler = Ffind_file_name_handler (abspath1, Qfile_newer_than_file_p); 2852 handler = Ffind_file_name_handler (abspath1, Qfile_newer_than_file_p);
2835 if (NILP (handler)) 2853 if (NILP (handler))
2836 handler = Ffind_file_name_handler (abspath2, Qfile_newer_than_file_p); 2854 handler = Ffind_file_name_handler (abspath2, Qfile_newer_than_file_p);
2837 UNGCPRO; 2855 UNGCPRO;
2838 if (!NILP (handler)) 2856 if (!NILP (handler))
2883 struct stat st; 2901 struct stat st;
2884 int fd; 2902 int fd;
2885 int saverrno = 0; 2903 int saverrno = 0;
2886 Charcount inserted = 0; 2904 Charcount inserted = 0;
2887 int speccount; 2905 int speccount;
2888 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 2906 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
2889 Lisp_Object handler = Qnil, val; 2907 Lisp_Object handler = Qnil, val;
2890 int total; 2908 int total;
2891 Bufbyte read_buf[READ_BUF_SIZE]; 2909 Bufbyte read_buf[READ_BUF_SIZE];
2892 int mc_count; 2910 int mc_count;
2893 struct buffer *buf = current_buffer; 2911 struct buffer *buf = current_buffer;
2912 Lisp_Object curbuf;
2894 int not_regular = 0; 2913 int not_regular = 0;
2895 2914
2896 if (buf->base_buffer && ! NILP (visit)) 2915 if (buf->base_buffer && ! NILP (visit))
2897 error ("Cannot do file visiting in an indirect buffer"); 2916 error ("Cannot do file visiting in an indirect buffer");
2898 2917
2899 /* No need to call Fbarf_if_buffer_read_only() here. 2918 /* No need to call Fbarf_if_buffer_read_only() here.
2900 That's called in begin_multiple_change() or wherever. */ 2919 That's called in begin_multiple_change() or wherever. */
2901 2920
2902 val = Qnil; 2921 val = Qnil;
2903 2922
2904 GCPRO4 (filename, val, visit, handler); 2923 /* #### dmoore - should probably check in various places to see if
2924 curbuf was killed and if so signal an error? */
2925
2926 XSETBUFFER (curbuf, buf);
2927
2928 GCPRO5 (filename, val, visit, handler, curbuf);
2905 2929
2906 mc_count = (NILP (replace)) ? 2930 mc_count = (NILP (replace)) ?
2907 begin_multiple_change (buf, BUF_PT (buf), BUF_PT (buf)) : 2931 begin_multiple_change (buf, BUF_PT (buf), BUF_PT (buf)) :
2908 begin_multiple_change (buf, BUF_BEG (buf), BUF_Z (buf)); 2932 begin_multiple_change (buf, BUF_BEG (buf), BUF_Z (buf));
2909 2933
3339 Lisp_Object visit_file = Qnil; 3363 Lisp_Object visit_file = Qnil;
3340 Lisp_Object annotations = Qnil; 3364 Lisp_Object annotations = Qnil;
3341 struct buffer *given_buffer; 3365 struct buffer *given_buffer;
3342 Bufpos start1, end1; 3366 Bufpos start1, end1;
3343 3367
3368 /* #### dmoore - if Fexpand_file_name or handlers kill the buffer,
3369 we should signal an error rather than blissfully continuing
3370 along. ARGH, this function is going to lose lose lose. We need
3371 to protect the current_buffer from being destroyed, but the
3372 multiple return points make this a pain in the butt. */
3373
3344 #ifdef DOS_NT 3374 #ifdef DOS_NT
3345 int buffer_file_type 3375 int buffer_file_type
3346 = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY; 3376 = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY;
3347 #endif /* DOS_NT */ 3377 #endif /* DOS_NT */
3348 3378
3353 get_buffer_range_char (current_buffer, start, end, &start1, &end1, 0); 3383 get_buffer_range_char (current_buffer, start, end, &start1, &end1, 0);
3354 3384
3355 { 3385 {
3356 Lisp_Object handler; 3386 Lisp_Object handler;
3357 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 3387 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
3388
3358 GCPRO5 (start, filename, visit, visit_file, lockname); 3389 GCPRO5 (start, filename, visit, visit_file, lockname);
3359 3390
3360 if (visiting_other) 3391 if (visiting_other)
3361 visit_file = Fexpand_file_name (visit, Qnil); 3392 visit_file = Fexpand_file_name (visit, Qnil);
3362 else 3393 else
3392 } 3423 }
3393 3424
3394 #ifdef CLASH_DETECTION 3425 #ifdef CLASH_DETECTION
3395 if (!auto_saving) 3426 if (!auto_saving)
3396 { 3427 {
3397 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 3428 Lisp_Object curbuf;
3398 GCPRO4 (start, filename, visit_file, lockname); 3429 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
3430
3431 XSETBUFFER (curbuf, current_buffer);
3432 GCPRO5 (start, filename, visit_file, lockname, curbuf);
3399 lock_file (lockname); 3433 lock_file (lockname);
3400 UNGCPRO; 3434 UNGCPRO;
3401 } 3435 }
3402 #endif /* CLASH_DETECTION */ 3436 #endif /* CLASH_DETECTION */
3403 3437
4016 else 4050 else
4017 { 4051 {
4018 Lisp_Object filename; 4052 Lisp_Object filename;
4019 struct stat st; 4053 struct stat st;
4020 Lisp_Object handler; 4054 Lisp_Object handler;
4021 struct gcpro gcpro1, gcpro2; 4055 struct gcpro gcpro1, gcpro2, gcpro3;
4022 4056
4023 GCPRO2 (filename, time_list); 4057 GCPRO3 (filename, time_list, current_buffer->filename);
4024 filename = Fexpand_file_name (current_buffer->filename, 4058 filename = Fexpand_file_name (current_buffer->filename, Qnil);
4025 Qnil);
4026 4059
4027 /* If the file name has special constructs in it, 4060 /* If the file name has special constructs in it,
4028 call the corresponding file handler. */ 4061 call the corresponding file handler. */
4029 handler = Ffind_file_name_handler (filename, Qset_visited_file_modtime); 4062 handler = Ffind_file_name_handler (filename, Qset_visited_file_modtime);
4030 UNGCPRO; 4063 UNGCPRO;
4072 } 4105 }
4073 4106
4074 if (!set_time_to_use) 4107 if (!set_time_to_use)
4075 { 4108 {
4076 Lisp_Object filename = Qnil; 4109 Lisp_Object filename = Qnil;
4077 struct gcpro gcpro1, gcpro2; 4110 struct gcpro gcpro1;
4078 GCPRO2 (buf, filename); 4111 GCPRO1 (filename);
4112 /* #### dmoore - do we need to protect XBUFFER (buf)->filename?
4113 What if a ^(*&^&*^*& handler renames a buffer? I think I'm
4114 getting a headache now. */
4079 4115
4080 if (STRINGP (XBUFFER (buf)->filename)) 4116 if (STRINGP (XBUFFER (buf)->filename))
4081 filename = Fexpand_file_name (XBUFFER (buf)->filename, 4117 filename = Fexpand_file_name (XBUFFER (buf)->filename, Qnil);
4082 Qnil);
4083 else 4118 else
4084 filename = Qnil; 4119 filename = Qnil;
4085
4086 UNGCPRO;
4087 4120
4088 if (!NILP (filename) && !NILP (Ffile_exists_p (filename))) 4121 if (!NILP (filename) && !NILP (Ffile_exists_p (filename)))
4089 { 4122 {
4090 Lisp_Object handler; 4123 Lisp_Object handler;
4091 4124
4092 /* If the file name has special constructs in it, 4125 /* If the file name has special constructs in it,
4093 call the corresponding file handler. */ 4126 call the corresponding file handler. */
4094 GCPRO1 (filename);
4095 handler = Ffind_file_name_handler (filename, Qset_buffer_modtime); 4127 handler = Ffind_file_name_handler (filename, Qset_buffer_modtime);
4096 UNGCPRO; 4128 UNGCPRO;
4097 if (!NILP (handler)) 4129 if (!NILP (handler))
4098 /* The handler can find the file name the same way we did. */ 4130 /* The handler can find the file name the same way we did. */
4099 return (call2 (handler, Qset_buffer_modtime, Qnil)); 4131 return (call2 (handler, Qset_buffer_modtime, Qnil));
4104 else 4136 else
4105 time_to_use = time ((time_t *) 0); 4137 time_to_use = time ((time_t *) 0);
4106 } 4138 }
4107 } 4139 }
4108 else 4140 else
4109 time_to_use = time ((time_t *) 0); 4141 {
4142 UNGCPRO;
4143 time_to_use = time ((time_t *) 0);
4144 }
4110 } 4145 }
4111 4146
4112 XBUFFER (buf)->modtime = time_to_use; 4147 XBUFFER (buf)->modtime = time_to_use;
4113 4148
4114 return Qnil; 4149 return Qnil;
4115 } 4150 }
4116 4151
4117 4152
4118 static Lisp_Object 4153 static Lisp_Object