comparison src/fileio.c @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents ee648375d8d6
children 54cc21c15cbb
comparison
equal deleted inserted replaced
69:804d1389bcd6 70:131b0175ea99
30 #include "insdel.h" 30 #include "insdel.h"
31 #include "lstream.h" 31 #include "lstream.h"
32 #include "redisplay.h" 32 #include "redisplay.h"
33 #include "sysdep.h" 33 #include "sysdep.h"
34 #include "window.h" /* minibuf_level */ 34 #include "window.h" /* minibuf_level */
35 #ifdef MULE
36 #include "mule-coding.h"
37 #endif
35 38
36 #ifdef HAVE_LIBGEN_H /* Must come before sysfile.h */ 39 #ifdef HAVE_LIBGEN_H /* Must come before sysfile.h */
37 #include <libgen.h> 40 #include <libgen.h>
38 #endif 41 #endif
39 #include "sysfile.h" 42 #include "sysfile.h"
110 /* signal a file error when errno contains a meaningful value. */ 113 /* signal a file error when errno contains a meaningful value. */
111 114
112 DOESNT_RETURN 115 DOESNT_RETURN
113 report_file_error (CONST char *string, Lisp_Object data) 116 report_file_error (CONST char *string, Lisp_Object data)
114 { 117 {
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
120 /* mrb: #### Needs to be fixed at a lower level; errstring needs to 118 /* mrb: #### Needs to be fixed at a lower level; errstring needs to
121 be MULEized. The following at least prevents a crash... */ 119 be MULEized. The following at least prevents a crash... */
122 Lisp_Object errstring = build_ext_string (strerror (errno), FORMAT_BINARY); 120 Lisp_Object errstring = build_ext_string (strerror (errno), FORMAT_BINARY);
123 121
124 /* System error messages are capitalized. Downcase the initial 122 /* System error messages are capitalized. Downcase the initial
125 unless it is followed by a slash. */ 123 unless it is followed by a slash. */
126 if (string_char_length (XSTRING (errstring)) >= 2 124 if (string_char (XSTRING (errstring), 1) != '/')
127 && string_char (XSTRING (errstring), 1) != '/')
128 set_string_char (XSTRING (errstring), 0, 125 set_string_char (XSTRING (errstring), 0,
129 DOWNCASE (current_buffer, 126 DOWNCASE (current_buffer,
130 string_char (XSTRING (errstring), 0))); 127 string_char (XSTRING (errstring), 0)));
131 128
132 signal_error (Qfile_error, 129 signal_error (Qfile_error,
338 but we still do run any other handlers. This lets handlers 335 but we still do run any other handlers. This lets handlers
339 use the standard functions without calling themselves recursively. 336 use the standard functions without calling themselves recursively.
340 */ 337 */
341 (filename, operation)) 338 (filename, operation))
342 { 339 {
343 /* This function does not GC */
344 /* This function must not munge the match data. */ 340 /* This function must not munge the match data. */
345 Lisp_Object chain, inhibited_handlers; 341 Lisp_Object chain, inhibited_handlers;
346 342
347 CHECK_STRING (filename); 343 CHECK_STRING (filename);
348 344
373 } 369 }
374 370
375 static Lisp_Object 371 static Lisp_Object
376 call2_check_string (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1) 372 call2_check_string (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1)
377 { 373 {
378 /* This function can call lisp */ 374 /* This function can GC */
379 Lisp_Object result = call2 (fn, arg0, arg1); 375 Lisp_Object result = call2 (fn, arg0, arg1);
380 CHECK_STRING (result); 376 CHECK_STRING (result);
381 return (result); 377 return (result);
382 } 378 }
383 379
384 static Lisp_Object 380 static Lisp_Object
385 call2_check_string_or_nil (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1)
386 {
387 /* This function can call lisp */
388 Lisp_Object result = call2 (fn, arg0, arg1);
389 if (!NILP (result))
390 CHECK_STRING (result);
391 return (result);
392 }
393
394 static Lisp_Object
395 call3_check_string (Lisp_Object fn, Lisp_Object arg0, 381 call3_check_string (Lisp_Object fn, Lisp_Object arg0,
396 Lisp_Object arg1, Lisp_Object arg2) 382 Lisp_Object arg1, Lisp_Object arg2)
397 { 383 {
398 /* This function can call lisp */ 384 /* This function can GC */
399 Lisp_Object result = call3 (fn, arg0, arg1, arg2); 385 Lisp_Object result = call3 (fn, arg0, arg1, arg2);
400 CHECK_STRING (result); 386 CHECK_STRING (result);
401 return (result); 387 return (result);
402 } 388 }
403 389
409 Given a Unix syntax file name, returns a string ending in slash; 395 Given a Unix syntax file name, returns a string ending in slash;
410 on VMS, perhaps instead a string ending in `:', `]' or `>'. 396 on VMS, perhaps instead a string ending in `:', `]' or `>'.
411 */ 397 */
412 (file)) 398 (file))
413 { 399 {
414 /* This function can GC. GC checked 1997.04.06. */ 400 /* This function can GC */
415 Bufbyte *beg; 401 Bufbyte *beg;
416 Bufbyte *p; 402 Bufbyte *p;
417 Lisp_Object handler; 403 Lisp_Object handler;
418 404
419 CHECK_STRING (file); 405 CHECK_STRING (file);
420 406
421 /* If the file name has special constructs in it, 407 /* If the file name has special constructs in it,
422 call the corresponding file handler. */ 408 call the corresponding file handler. */
423 handler = Ffind_file_name_handler (file, Qfile_name_directory); 409 handler = Ffind_file_name_handler (file, Qfile_name_directory);
424 if (!NILP (handler)) 410 if (!NILP (handler))
425 return (call2_check_string_or_nil (handler, Qfile_name_directory, 411 {
426 file)); 412 Lisp_Object retval = call2 (handler, Qfile_name_directory,
413 file);
414
415 if (!NILP (retval))
416 CHECK_STRING (retval);
417 return retval;
418 }
427 419
428 #ifdef FILE_SYSTEM_CASE 420 #ifdef FILE_SYSTEM_CASE
429 file = FILE_SYSTEM_CASE (file); 421 file = FILE_SYSTEM_CASE (file);
430 #endif 422 #endif
431 beg = XSTRING_DATA (file); 423 beg = XSTRING_DATA (file);
477 this is everything after the last slash, 469 this is everything after the last slash,
478 or the entire name if it contains no slash. 470 or the entire name if it contains no slash.
479 */ 471 */
480 (file)) 472 (file))
481 { 473 {
482 /* This function can GC. GC checked 1997.04.06. */ 474 /* This function can GC */
483 Bufbyte *beg, *p, *end; 475 Bufbyte *beg, *p, *end;
484 Lisp_Object handler; 476 Lisp_Object handler;
485 477
486 CHECK_STRING (file); 478 CHECK_STRING (file);
487 479
511 If FILENAME is a directly usable file itself, return 503 If FILENAME is a directly usable file itself, return
512 (file-name-directory FILENAME). 504 (file-name-directory FILENAME).
513 The `call-process' and `start-process' functions use this function to 505 The `call-process' and `start-process' functions use this function to
514 get a current directory to run processes in. 506 get a current directory to run processes in.
515 */ 507 */
516 (filename)) 508 (filename))
517 { 509 {
518 /* This function can GC. GC checked 1997.04.06. */ 510 /* This function can GC */
519 Lisp_Object handler; 511 Lisp_Object handler;
520 512
521 /* If the file name has special constructs in it, 513 /* If the file name has special constructs in it,
522 call the corresponding file handler. */ 514 call the corresponding file handler. */
523 handler = Ffind_file_name_handler (filename, Qunhandled_file_name_directory); 515 handler = Ffind_file_name_handler (filename, Qunhandled_file_name_directory);
613 For a Unix-syntax file name, just appends a slash. 605 For a Unix-syntax file name, just appends a slash.
614 On VMS, converts \"[X]FOO.DIR\" to \"[X.FOO]\", etc. 606 On VMS, converts \"[X]FOO.DIR\" to \"[X.FOO]\", etc.
615 */ 607 */
616 (file)) 608 (file))
617 { 609 {
618 /* This function can GC. GC checked 1997.04.06. */ 610 /* This function can GC */
619 char *buf; 611 char *buf;
620 Lisp_Object handler; 612 Lisp_Object handler;
621 613
622 CHECK_STRING (file); 614 CHECK_STRING (file);
623 615
799 On VMS, given a VMS-syntax directory name such as \"[X.Y]\", 791 On VMS, given a VMS-syntax directory name such as \"[X.Y]\",
800 it returns a file name such as \"[X]Y.DIR.1\". 792 it returns a file name such as \"[X]Y.DIR.1\".
801 */ 793 */
802 (directory)) 794 (directory))
803 { 795 {
804 /* This function can GC. GC checked 1997.04.06. */ 796 /* This function can GC */
805 char *buf; 797 char *buf;
806 Lisp_Object handler; 798 Lisp_Object handler;
807 799
808 CHECK_STRING (directory); 800 CHECK_STRING (directory);
809 801
867 An initial `~USER/' expands to USER's home directory. 859 An initial `~USER/' expands to USER's home directory.
868 See also the function `substitute-in-file-name'. 860 See also the function `substitute-in-file-name'.
869 */ 861 */
870 (name, defalt)) 862 (name, defalt))
871 { 863 {
872 /* This function can GC. GC checked 1997.04.06. */ 864 /* This function can GC */
873 Bufbyte *nm; 865 Bufbyte *nm;
874 866
875 Bufbyte *newdir, *p, *o; 867 Bufbyte *newdir, *p, *o;
876 int tlen; 868 int tlen;
877 Bufbyte *target; 869 Bufbyte *target;
917 else 909 else
918 CHECK_STRING (defalt); 910 CHECK_STRING (defalt);
919 911
920 if (!NILP (defalt)) 912 if (!NILP (defalt))
921 { 913 {
922 struct gcpro gcpro1;
923
924 GCPRO1 (defalt); /* might be current_buffer->directory */
925 handler = Ffind_file_name_handler (defalt, Qexpand_file_name); 914 handler = Ffind_file_name_handler (defalt, Qexpand_file_name);
926 UNGCPRO;
927 if (!NILP (handler)) 915 if (!NILP (handler))
928 return call3 (handler, Qexpand_file_name, name, defalt); 916 return call3 (handler, Qexpand_file_name, name, defalt);
929 } 917 }
930 918
931 /* Make sure DEFALT is properly expanded. 919 /* Make sure DEFALT is properly expanded.
936 that would need adjusting, and people would add new pointers to 924 that would need adjusting, and people would add new pointers to
937 the code and forget to adjust them, resulting in intermittent bugs. 925 the code and forget to adjust them, resulting in intermittent bugs.
938 Putting this call here avoids all that crud. 926 Putting this call here avoids all that crud.
939 927
940 The EQ test avoids infinite recursion. */ 928 The EQ test avoids infinite recursion. */
941 if (! NILP(defalt) && !EQ (defalt, name) 929 if (! NILP (defalt) && !EQ (defalt, name)
942 /* This saves time in a common case. */ 930 /* This saves time in a common case. */
943 && ! (XSTRING_LENGTH (defalt) >= 3 931 && ! (XSTRING_LENGTH (defalt) >= 3
944 && (IS_DIRECTORY_SEP (XSTRING_BYTE (defalt, 0)) 932 && IS_DIRECTORY_SEP (string_byte (XSTRING (defalt), 0))
945 || IS_DEVICE_SEP (XSTRING_BYTE (defalt, 1))))) 933 && IS_DEVICE_SEP (string_byte (XSTRING (defalt), 1))))
946 { 934 {
947 struct gcpro gcpro1; 935 struct gcpro gcpro1;
948 936
949 GCPRO1 (defalt); /* may be current_buffer->directory */ 937 GCPRO1 (name);
950 defalt = Fexpand_file_name (defalt, Qnil); 938 defalt = Fexpand_file_name (defalt, Qnil);
951 UNGCPRO; 939 UNGCPRO;
952 } 940 }
953 941
954 #ifdef VMS 942 #ifdef VMS
957 #endif 945 #endif
958 #ifdef FILE_SYSTEM_CASE 946 #ifdef FILE_SYSTEM_CASE
959 name = FILE_SYSTEM_CASE (name); 947 name = FILE_SYSTEM_CASE (name);
960 #endif 948 #endif
961 949
962 /* #### dmoore - this is ugly, clean this up. Looks like nm
963 pointing into name should be safe during all of this, though. */
964 nm = XSTRING_DATA (name); 950 nm = XSTRING_DATA (name);
965 951
966 #ifdef MSDOS 952 #ifdef MSDOS
967 /* First map all backslashes to slashes. */ 953 /* First map all backslashes to slashes. */
968 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm)); 954 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm));
1396 No component of the resulting pathname will be a symbolic link, as 1382 No component of the resulting pathname will be a symbolic link, as
1397 in the realpath() function. 1383 in the realpath() function.
1398 */ 1384 */
1399 (filename, defalt)) 1385 (filename, defalt))
1400 { 1386 {
1401 /* This function can GC. GC checked 1997.04.06. */ 1387 /* This function can GC */
1388 struct gcpro gcpro1;
1402 Lisp_Object expanded_name; 1389 Lisp_Object expanded_name;
1403 Lisp_Object handler; 1390 Lisp_Object handler;
1404 struct gcpro gcpro1;
1405 1391
1406 CHECK_STRING (filename); 1392 CHECK_STRING (filename);
1407 1393
1394 GCPRO1 (filename);
1408 expanded_name = Fexpand_file_name (filename, defalt); 1395 expanded_name = Fexpand_file_name (filename, defalt);
1396 UNGCPRO;
1409 1397
1410 if (!STRINGP (expanded_name)) 1398 if (!STRINGP (expanded_name))
1411 return Qnil; 1399 return Qnil;
1412 1400
1413 GCPRO1 (expanded_name); 1401 GCPRO1 (expanded_name);
1487 } 1475 }
1488 } 1476 }
1489 1477
1490 { 1478 {
1491 int rlen = strlen (resolved_path); 1479 int rlen = strlen (resolved_path);
1492 if (elen > 0 && XSTRING_BYTE (expanded_name, elen - 1) == '/' 1480 if (elen > 0 && string_byte (XSTRING (expanded_name), elen - 1) == '/'
1493 && !(rlen > 0 && resolved_path[rlen - 1] == '/')) 1481 && !(rlen > 0 && resolved_path[rlen - 1] == '/'))
1494 { 1482 {
1495 if (rlen + 1 > countof (resolved_path)) 1483 if (rlen + 1 > countof (resolved_path))
1496 goto toolong; 1484 goto toolong;
1497 resolved_path[rlen] = '/'; 1485 resolved_path[rlen] = '/';
1523 On VMS, `$' substitution is not done; this function does little and only 1511 On VMS, `$' substitution is not done; this function does little and only
1524 duplicates what `expand-file-name' does. 1512 duplicates what `expand-file-name' does.
1525 */ 1513 */
1526 (string)) 1514 (string))
1527 { 1515 {
1528 /* This function can GC. GC checked 1997.04.06. */
1529 Bufbyte *nm; 1516 Bufbyte *nm;
1530 1517
1531 Bufbyte *s, *p, *o, *x, *endp; 1518 Bufbyte *s, *p, *o, *x, *endp;
1532 Bufbyte *target = 0; 1519 Bufbyte *target = 0;
1533 int total = 0; 1520 int total = 0;
1539 1526
1540 /* If the file name has special constructs in it, 1527 /* If the file name has special constructs in it,
1541 call the corresponding file handler. */ 1528 call the corresponding file handler. */
1542 handler = Ffind_file_name_handler (string, Qsubstitute_in_file_name); 1529 handler = Ffind_file_name_handler (string, Qsubstitute_in_file_name);
1543 if (!NILP (handler)) 1530 if (!NILP (handler))
1544 return (call2_check_string_or_nil (handler, Qsubstitute_in_file_name, 1531 {
1545 string)); 1532 Lisp_Object retval = call2 (handler, Qsubstitute_in_file_name,
1533 string);
1534
1535 if (!NILP (retval))
1536 CHECK_STRING (retval);
1537 return retval;
1538 }
1546 1539
1547 nm = XSTRING_DATA (string); 1540 nm = XSTRING_DATA (string);
1548 #ifdef MSDOS 1541 #ifdef MSDOS
1549 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm)); 1542 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm));
1550 substituted = !strcmp (nm, XSTRING_DATA (string)); 1543 substituted = !strcmp (nm, XSTRING_DATA (string));
1734 /* (directory-file-name (expand-file-name FOO)) */ 1727 /* (directory-file-name (expand-file-name FOO)) */
1735 1728
1736 Lisp_Object 1729 Lisp_Object
1737 expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir) 1730 expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir)
1738 { 1731 {
1739 /* This function can call lisp */ 1732 /* This function can GC */
1740 Lisp_Object abspath; 1733 Lisp_Object abspath;
1741 struct gcpro gcpro1; 1734 struct gcpro gcpro1;
1742 1735
1736 GCPRO1 (filename);
1743 abspath = Fexpand_file_name (filename, defdir); 1737 abspath = Fexpand_file_name (filename, defdir);
1744 GCPRO1 (abspath);
1745 #ifdef VMS 1738 #ifdef VMS
1746 { 1739 {
1747 Bufbyte c = 1740 Bufbyte c =
1748 XSTRING_BYTE (abspath, XSTRING_LENGTH (abspath) - 1); 1741 string_byte (XSTRING (abspath), XSTRING_LENGTH (abspath) - 1);
1749 if (c == ':' || c == ']' || c == '>') 1742 if (c == ':' || c == ']' || c == '>')
1750 abspath = Fdirectory_file_name (abspath); 1743 abspath = Fdirectory_file_name (abspath);
1751 } 1744 }
1752 #else 1745 #else
1753 /* Remove final slash, if any (unless path is root). 1746 /* Remove final slash, if any (unless path is root).
1754 stat behaves differently depending! */ 1747 stat behaves differently depending! */
1755 if (XSTRING_LENGTH (abspath) > 1 1748 if (XSTRING_LENGTH (abspath) > 1
1756 && IS_DIRECTORY_SEP (XSTRING_BYTE (abspath, XSTRING_LENGTH (abspath) - 1)) 1749 && IS_DIRECTORY_SEP (string_byte (XSTRING (abspath),
1757 && !IS_DEVICE_SEP (XSTRING_BYTE (abspath, XSTRING_LENGTH (abspath) - 2))) 1750 XSTRING_LENGTH (abspath) - 1))
1751 && !IS_DEVICE_SEP (string_byte (XSTRING (abspath),
1752 XSTRING_LENGTH (abspath) - 2)))
1758 /* We cannot take shortcuts; they might be wrong for magic file names. */ 1753 /* We cannot take shortcuts; they might be wrong for magic file names. */
1759 abspath = Fdirectory_file_name (abspath); 1754 abspath = Fdirectory_file_name (abspath);
1760 #endif 1755 #endif
1761 UNGCPRO; 1756 UNGCPRO;
1762 return abspath; 1757 return abspath;
1772 1767
1773 static void 1768 static void
1774 barf_or_query_if_file_exists (Lisp_Object absname, CONST char *querystring, 1769 barf_or_query_if_file_exists (Lisp_Object absname, CONST char *querystring,
1775 int interactive, struct stat *statptr) 1770 int interactive, struct stat *statptr)
1776 { 1771 {
1777 /* This function can call lisp */
1778 struct stat statbuf; 1772 struct stat statbuf;
1779 1773
1780 /* stat is a good way to tell whether the file exists, 1774 /* stat is a good way to tell whether the file exists,
1781 regardless of what access permissions it has. */ 1775 regardless of what access permissions it has. */
1782 if (stat ((char *) XSTRING_DATA (absname), &statbuf) >= 0) 1776 if (stat ((char *) XSTRING_DATA (absname), &statbuf) >= 0)
1783 { 1777 {
1784 Lisp_Object tem; 1778 Lisp_Object tem;
1785 1779 struct gcpro gcpro1;
1780
1781 GCPRO1 (absname);
1786 if (interactive) 1782 if (interactive)
1787 { 1783 tem = call1
1788 Lisp_Object prompt; 1784 (Qyes_or_no_p,
1789 struct gcpro gcpro1; 1785 (emacs_doprnt_string_c
1790
1791 prompt = emacs_doprnt_string_c
1792 ((CONST Bufbyte *) GETTEXT ("File %s already exists; %s anyway? "), 1786 ((CONST Bufbyte *) GETTEXT ("File %s already exists; %s anyway? "),
1793 Qnil, -1, XSTRING_DATA (absname), 1787 Qnil, -1, XSTRING_DATA (absname),
1794 GETTEXT (querystring)); 1788 GETTEXT (querystring))));
1795
1796 GCPRO1 (prompt);
1797 tem = call1 (Qyes_or_no_p, prompt);
1798 UNGCPRO;
1799 }
1800 else 1789 else
1801 tem = Qnil; 1790 tem = Qnil;
1802 1791 UNGCPRO;
1803 if (NILP (tem)) 1792 if (NILP (tem))
1804 Fsignal (Qfile_already_exists, 1793 Fsignal (Qfile_already_exists,
1805 list2 (build_translated_string ("File already exists"), 1794 list2 (build_translated_string ("File already exists"),
1806 absname)); 1795 absname));
1807 if (statptr) 1796 if (statptr)
1824 This is what happens in interactive use with M-x. 1813 This is what happens in interactive use with M-x.
1825 Fourth arg KEEP-TIME non-nil means give the new file the same 1814 Fourth arg KEEP-TIME non-nil means give the new file the same
1826 last-modified time as the old one. (This works on only some systems.) 1815 last-modified time as the old one. (This works on only some systems.)
1827 A prefix arg makes KEEP-TIME non-nil. 1816 A prefix arg makes KEEP-TIME non-nil.
1828 */ 1817 */
1829 (filename, newname, ok_if_already_exists, keep_time)) 1818 (filename, newname, ok_if_already_exists, keep_date))
1830 { 1819 {
1831 /* This function can GC. GC checked 1997.04.06. */ 1820 /* This function can GC */
1832 int ifd, ofd, n; 1821 int ifd, ofd, n;
1833 char buf[16 * 1024]; 1822 char buf[16 * 1024];
1834 struct stat st, out_st; 1823 struct stat st, out_st;
1835 Lisp_Object handler; 1824 Lisp_Object handler;
1836 int speccount = specpdl_depth (); 1825 int speccount = specpdl_depth ();
1852 handler = Ffind_file_name_handler (newname, Qcopy_file); 1841 handler = Ffind_file_name_handler (newname, Qcopy_file);
1853 if (!NILP (handler)) 1842 if (!NILP (handler))
1854 { 1843 {
1855 UNGCPRO; 1844 UNGCPRO;
1856 return call5 (handler, Qcopy_file, filename, newname, 1845 return call5 (handler, Qcopy_file, filename, newname,
1857 ok_if_already_exists, keep_time); 1846 ok_if_already_exists, keep_date);
1858 } 1847 }
1859 1848
1860 /* When second argument is a directory, copy the file into it. 1849 /* When second argument is a directory, copy the file into it.
1861 (copy-file "foo" "bar/") == (copy-file "foo" "bar/foo") 1850 (copy-file "foo" "bar/") == (copy-file "foo" "bar/foo")
1862 */ 1851 */
1868 1857
1869 args[0] = newname; 1858 args[0] = newname;
1870 args[1] = Qnil; args[2] = Qnil; 1859 args[1] = Qnil; args[2] = Qnil;
1871 NGCPRO1 (*args); 1860 NGCPRO1 (*args);
1872 ngcpro1.nvars = 3; 1861 ngcpro1.nvars = 3;
1873 if (XSTRING_BYTE (newname, XSTRING_LENGTH (newname) - 1) != '/') 1862 if (string_byte (XSTRING (newname),
1863 XSTRING_LENGTH (newname) - 1) != '/')
1874 args[i++] = build_string ("/"); 1864 args[i++] = build_string ("/");
1875 args[i++] = Ffile_name_nondirectory (filename); 1865 args[i++] = Ffile_name_nondirectory (filename);
1876 newname = Fconcat (i, args); 1866 newname = Fconcat (i, args);
1877 NUNGCPRO; 1867 NUNGCPRO;
1878 } 1868 }
1952 if (close (ofd) < 0) 1942 if (close (ofd) < 0)
1953 report_file_error ("I/O error", Fcons (newname, Qnil)); 1943 report_file_error ("I/O error", Fcons (newname, Qnil));
1954 1944
1955 if (input_file_statable_p) 1945 if (input_file_statable_p)
1956 { 1946 {
1957 if (!NILP (keep_time)) 1947 if (!NILP (keep_date))
1958 { 1948 {
1959 EMACS_TIME atime, mtime; 1949 EMACS_TIME atime, mtime;
1960 EMACS_SET_SECS_USECS (atime, st.st_atime, 0); 1950 EMACS_SET_SECS_USECS (atime, st.st_atime, 0);
1961 EMACS_SET_SECS_USECS (mtime, st.st_mtime, 0); 1951 EMACS_SET_SECS_USECS (mtime, st.st_mtime, 0);
1962 if (set_file_times ((char *) XSTRING_DATA (newname), atime, 1952 if (set_file_times ((char *) XSTRING_DATA (newname), atime,
1992 DEFUN ("make-directory-internal", Fmake_directory_internal, 1, 1, 0, /* 1982 DEFUN ("make-directory-internal", Fmake_directory_internal, 1, 1, 0, /*
1993 Create a directory. One argument, a file name string. 1983 Create a directory. One argument, a file name string.
1994 */ 1984 */
1995 (dirname)) 1985 (dirname))
1996 { 1986 {
1997 /* This function can GC. GC checked 1997.04.06 */ 1987 /* This function can GC */
1998 char dir [MAXPATHLEN]; 1988 char dir [MAXPATHLEN];
1999 Lisp_Object handler; 1989 Lisp_Object handler;
1990
2000 struct gcpro gcpro1; 1991 struct gcpro gcpro1;
2001 1992
1993 GCPRO1 (dirname);
2002 CHECK_STRING (dirname); 1994 CHECK_STRING (dirname);
2003 dirname = Fexpand_file_name (dirname, Qnil); 1995 dirname = Fexpand_file_name (dirname, Qnil);
2004 1996
2005 GCPRO1 (dirname);
2006 handler = Ffind_file_name_handler (dirname, Qmake_directory_internal); 1997 handler = Ffind_file_name_handler (dirname, Qmake_directory_internal);
2007 UNGCPRO; 1998 UNGCPRO;
2008 if (!NILP (handler)) 1999 if (!NILP (handler))
2009 return (call2 (handler, Qmake_directory_internal, dirname)); 2000 return (call2 (handler, Qmake_directory_internal,
2001 dirname));
2010 2002
2011 if (XSTRING_LENGTH (dirname) > (sizeof (dir) - 1)) 2003 if (XSTRING_LENGTH (dirname) > (sizeof (dir) - 1))
2012 { 2004 {
2013 return Fsignal (Qfile_error, 2005 return Fsignal (Qfile_error,
2014 list3 (build_translated_string ("Creating directory"), 2006 list3 (build_translated_string ("Creating directory"),
2036 DEFUN ("delete-directory", Fdelete_directory, 1, 1, "FDelete directory: ", /* 2028 DEFUN ("delete-directory", Fdelete_directory, 1, 1, "FDelete directory: ", /*
2037 Delete a directory. One argument, a file name or directory name string. 2029 Delete a directory. One argument, a file name or directory name string.
2038 */ 2030 */
2039 (dirname)) 2031 (dirname))
2040 { 2032 {
2041 /* This function can GC. GC checked 1997.04.06. */ 2033 /* This function can GC */
2042 Lisp_Object handler; 2034 Lisp_Object handler;
2043 struct gcpro gcpro1; 2035 struct gcpro gcpro1;
2044 2036
2037 GCPRO1 (dirname);
2045 CHECK_STRING (dirname); 2038 CHECK_STRING (dirname);
2046 2039 dirname =
2047 GCPRO1 (dirname); 2040 Fdirectory_file_name (Fexpand_file_name (dirname, Qnil));
2048 dirname = Fexpand_file_name (dirname, Qnil);
2049 dirname = Fdirectory_file_name (dirname);
2050 2041
2051 handler = Ffind_file_name_handler (dirname, Qdelete_directory); 2042 handler = Ffind_file_name_handler (dirname, Qdelete_directory);
2052 UNGCPRO; 2043 UNGCPRO;
2053 if (!NILP (handler)) 2044 if (!NILP (handler))
2054 return (call2 (handler, Qdelete_directory, dirname)); 2045 return (call2 (handler, Qdelete_directory, dirname));
2063 Delete specified file. One argument, a file name string. 2054 Delete specified file. One argument, a file name string.
2064 If file has multiple names, it continues to exist with the other names. 2055 If file has multiple names, it continues to exist with the other names.
2065 */ 2056 */
2066 (filename)) 2057 (filename))
2067 { 2058 {
2068 /* This function can GC. GC checked 1997.04.06. */ 2059 /* This function can GC */
2069 Lisp_Object handler; 2060 Lisp_Object handler;
2070 struct gcpro gcpro1; 2061 struct gcpro gcpro1;
2071 2062
2063 GCPRO1 (filename);
2072 CHECK_STRING (filename); 2064 CHECK_STRING (filename);
2073 filename = Fexpand_file_name (filename, Qnil); 2065 filename = Fexpand_file_name (filename, Qnil);
2074 2066
2075 GCPRO1 (filename);
2076 handler = Ffind_file_name_handler (filename, Qdelete_file); 2067 handler = Ffind_file_name_handler (filename, Qdelete_file);
2077 UNGCPRO; 2068 UNGCPRO;
2078 if (!NILP (handler)) 2069 if (!NILP (handler))
2079 return call2 (handler, Qdelete_file, filename); 2070 return call2 (handler, Qdelete_file, filename);
2080 2071
2092 /* Delete file FILENAME, returning 1 if successful and 0 if failed. */ 2083 /* Delete file FILENAME, returning 1 if successful and 0 if failed. */
2093 2084
2094 int 2085 int
2095 internal_delete_file (Lisp_Object filename) 2086 internal_delete_file (Lisp_Object filename)
2096 { 2087 {
2097 /* This function can GC. GC checked 1997.04.06. */
2098 return NILP (condition_case_1 (Qt, Fdelete_file, filename, 2088 return NILP (condition_case_1 (Qt, Fdelete_file, filename,
2099 internal_delete_file_1, Qnil)); 2089 internal_delete_file_1, Qnil));
2100 } 2090 }
2101 2091
2102 DEFUN ("rename-file", Frename_file, 2, 3, 2092 DEFUN ("rename-file", Frename_file, 2, 3,
2108 A number as third arg means request confirmation if NEWNAME already exists. 2098 A number as third arg means request confirmation if NEWNAME already exists.
2109 This is what happens in interactive use with M-x. 2099 This is what happens in interactive use with M-x.
2110 */ 2100 */
2111 (filename, newname, ok_if_already_exists)) 2101 (filename, newname, ok_if_already_exists))
2112 { 2102 {
2113 /* This function can GC. GC checked 1997.04.06. */ 2103 /* This function can GC */
2114 Lisp_Object handler; 2104 Lisp_Object handler;
2115 struct gcpro gcpro1, gcpro2; 2105 struct gcpro gcpro1, gcpro2;
2116 2106
2117 GCPRO2 (filename, newname); 2107 GCPRO2 (filename, newname);
2118 CHECK_STRING (filename); 2108 CHECK_STRING (filename);
2201 A number as third arg means request confirmation if NEWNAME already exists. 2191 A number as third arg means request confirmation if NEWNAME already exists.
2202 This is what happens in interactive use with M-x. 2192 This is what happens in interactive use with M-x.
2203 */ 2193 */
2204 (filename, newname, ok_if_already_exists)) 2194 (filename, newname, ok_if_already_exists))
2205 { 2195 {
2206 /* This function can GC. GC checked 1997.04.06. */ 2196 /* This function can GC */
2207 Lisp_Object handler; 2197 Lisp_Object handler;
2208 struct gcpro gcpro1, gcpro2; 2198 struct gcpro gcpro1, gcpro2;
2209 2199
2210 GCPRO2 (filename, newname); 2200 GCPRO2 (filename, newname);
2211 CHECK_STRING (filename); 2201 CHECK_STRING (filename);
2258 A number as third arg means request confirmation if LINKNAME already exists. 2248 A number as third arg means request confirmation if LINKNAME already exists.
2259 This happens for interactive use with M-x. 2249 This happens for interactive use with M-x.
2260 */ 2250 */
2261 (filename, linkname, ok_if_already_exists)) 2251 (filename, linkname, ok_if_already_exists))
2262 { 2252 {
2263 /* This function can GC. GC checked 1997.06.04. */ 2253 /* This function can GC */
2264 Lisp_Object handler; 2254 Lisp_Object handler;
2265 struct gcpro gcpro1, gcpro2; 2255 struct gcpro gcpro1, gcpro2;
2266 2256
2267 GCPRO2 (filename, linkname); 2257 GCPRO2 (filename, linkname);
2268 CHECK_STRING (filename); 2258 CHECK_STRING (filename);
2269 CHECK_STRING (linkname); 2259 CHECK_STRING (linkname);
2270 /* If the link target has a ~, we must expand it to get 2260 /* If the link target has a ~, we must expand it to get
2271 a truly valid file name. Otherwise, do not expand; 2261 a truly valid file name. Otherwise, do not expand;
2272 we want to permit links to relative file names. */ 2262 we want to permit links to relative file names. */
2273 if (XSTRING_BYTE (filename, 0) == '~') /* #### Un*x-specific */ 2263 if (string_byte (XSTRING (filename), 0) == '~') /* #### Un*x-specific */
2274 filename = Fexpand_file_name (filename, Qnil); 2264 filename = Fexpand_file_name (filename, Qnil);
2275 linkname = Fexpand_file_name (linkname, Qnil); 2265 linkname = Fexpand_file_name (linkname, Qnil);
2276 2266
2277 /* If the file name has special constructs in it, 2267 /* If the file name has special constructs in it,
2278 call the corresponding file handler. */ 2268 call the corresponding file handler. */
2366 Return t if file FILENAME specifies an absolute path name. 2356 Return t if file FILENAME specifies an absolute path name.
2367 On Unix, this is a name starting with a `/' or a `~'. 2357 On Unix, this is a name starting with a `/' or a `~'.
2368 */ 2358 */
2369 (filename)) 2359 (filename))
2370 { 2360 {
2371 /* This function does not GC */
2372 Bufbyte *ptr; 2361 Bufbyte *ptr;
2373 2362
2374 CHECK_STRING (filename); 2363 CHECK_STRING (filename);
2375 ptr = XSTRING_DATA (filename); 2364 ptr = XSTRING_DATA (filename);
2376 if (IS_DIRECTORY_SEP (*ptr) || *ptr == '~' 2365 if (IS_DIRECTORY_SEP (*ptr) || *ptr == '~'
2446 Return t if file FILENAME exists. (This does not mean you can read it.) 2435 Return t if file FILENAME exists. (This does not mean you can read it.)
2447 See also `file-readable-p' and `file-attributes'. 2436 See also `file-readable-p' and `file-attributes'.
2448 */ 2437 */
2449 (filename)) 2438 (filename))
2450 { 2439 {
2451 /* This function can call lisp */ 2440 /* This function can GC */
2452 Lisp_Object abspath; 2441 Lisp_Object abspath;
2453 Lisp_Object handler; 2442 Lisp_Object handler;
2454 struct stat statbuf; 2443 struct stat statbuf;
2455 struct gcpro gcpro1; 2444 struct gcpro gcpro1;
2456 2445
2446 GCPRO1 (filename);
2457 CHECK_STRING (filename); 2447 CHECK_STRING (filename);
2458 abspath = Fexpand_file_name (filename, Qnil); 2448 abspath = Fexpand_file_name (filename, Qnil);
2449 UNGCPRO;
2459 2450
2460 /* If the file name has special constructs in it, 2451 /* If the file name has special constructs in it,
2461 call the corresponding file handler. */ 2452 call the corresponding file handler. */
2462 GCPRO1 (abspath); 2453 GCPRO1 (abspath);
2463 handler = Ffind_file_name_handler (abspath, Qfile_exists_p); 2454 handler = Ffind_file_name_handler (abspath, Qfile_exists_p);
2474 DEFUN ("file-executable-p", Ffile_executable_p, 1, 1, 0, /* 2465 DEFUN ("file-executable-p", Ffile_executable_p, 1, 1, 0, /*
2475 Return t if FILENAME can be executed by you. 2466 Return t if FILENAME can be executed by you.
2476 For a directory, this means you can access files in that directory. 2467 For a directory, this means you can access files in that directory.
2477 */ 2468 */
2478 (filename)) 2469 (filename))
2479 { 2470
2480 /* This function can call lisp */ 2471 {
2472 /* This function can GC */
2481 Lisp_Object abspath; 2473 Lisp_Object abspath;
2482 Lisp_Object handler; 2474 Lisp_Object handler;
2483 struct gcpro gcpro1; 2475 struct gcpro gcpro1;
2484 2476
2485 GCPRO1 (filename); 2477 GCPRO1 (filename);
2503 Return t if file FILENAME exists and you can read it. 2495 Return t if file FILENAME exists and you can read it.
2504 See also `file-exists-p' and `file-attributes'. 2496 See also `file-exists-p' and `file-attributes'.
2505 */ 2497 */
2506 (filename)) 2498 (filename))
2507 { 2499 {
2508 /* This function can call lisp */ 2500 /* This function can GC */
2509 Lisp_Object abspath; 2501 Lisp_Object abspath;
2510 Lisp_Object handler; 2502 Lisp_Object handler;
2511 int desc; 2503 int desc;
2512 struct gcpro gcpro1; 2504 struct gcpro gcpro1;
2513 2505
2506 GCPRO1 (filename);
2514 CHECK_STRING (filename); 2507 CHECK_STRING (filename);
2515 abspath = Fexpand_file_name (filename, Qnil); 2508 abspath = Fexpand_file_name (filename, Qnil);
2509 UNGCPRO;
2516 2510
2517 /* If the file name has special constructs in it, 2511 /* If the file name has special constructs in it,
2518 call the corresponding file handler. */ 2512 call the corresponding file handler. */
2519 GCPRO1 (abspath); 2513 GCPRO1 (abspath);
2520 handler = Ffind_file_name_handler (abspath, Qfile_readable_p); 2514 handler = Ffind_file_name_handler (abspath, Qfile_readable_p);
2534 DEFUN ("file-writable-p", Ffile_writable_p, 1, 1, 0, /* 2528 DEFUN ("file-writable-p", Ffile_writable_p, 1, 1, 0, /*
2535 Return t if file FILENAME can be written or created by you. 2529 Return t if file FILENAME can be written or created by you.
2536 */ 2530 */
2537 (filename)) 2531 (filename))
2538 { 2532 {
2539 /* This function can call lisp */ 2533 /* This function can GC */
2540 Lisp_Object abspath, dir; 2534 Lisp_Object abspath, dir;
2541 Lisp_Object handler; 2535 Lisp_Object handler;
2542 struct stat statbuf; 2536 struct stat statbuf;
2543 struct gcpro gcpro1; 2537 struct gcpro gcpro1;
2544 2538
2539 GCPRO1 (filename);
2545 CHECK_STRING (filename); 2540 CHECK_STRING (filename);
2546 abspath = Fexpand_file_name (filename, Qnil); 2541 abspath = Fexpand_file_name (filename, Qnil);
2542 UNGCPRO;
2547 2543
2548 /* If the file name has special constructs in it, 2544 /* If the file name has special constructs in it,
2549 call the corresponding file handler. */ 2545 call the corresponding file handler. */
2550 GCPRO1 (abspath); 2546 GCPRO1 (abspath);
2551 handler = Ffind_file_name_handler (abspath, Qfile_writable_p); 2547 handler = Ffind_file_name_handler (abspath, Qfile_writable_p);
2556 if (stat ((char *) XSTRING_DATA (abspath), &statbuf) >= 0) 2552 if (stat ((char *) XSTRING_DATA (abspath), &statbuf) >= 0)
2557 return (check_writable ((char *) XSTRING_DATA (abspath)) 2553 return (check_writable ((char *) XSTRING_DATA (abspath))
2558 ? Qt : Qnil); 2554 ? Qt : Qnil);
2559 2555
2560 2556
2561 GCPRO1 (abspath);
2562 dir = Ffile_name_directory (abspath); 2557 dir = Ffile_name_directory (abspath);
2563 UNGCPRO;
2564 #if defined (VMS) || defined (MSDOS) 2558 #if defined (VMS) || defined (MSDOS)
2565 if (!NILP (dir)) 2559 if (!NILP (dir))
2566 { 2560 dir = Fdirectory_file_name (dir);
2567 GCPRO1(dir);
2568 dir = Fdirectory_file_name (dir);
2569 UNGCPRO;
2570 }
2571 #endif /* VMS or MSDOS */ 2561 #endif /* VMS or MSDOS */
2572 return (check_writable (!NILP (dir) ? (char *) XSTRING_DATA (dir) 2562 return (check_writable (!NILP (dir) ? (char *) XSTRING_DATA (dir)
2573 : "") 2563 : "")
2574 ? Qt : Qnil); 2564 ? Qt : Qnil);
2575 } 2565 }
2579 The value is the name of the file to which it is linked. 2569 The value is the name of the file to which it is linked.
2580 Otherwise returns nil. 2570 Otherwise returns nil.
2581 */ 2571 */
2582 (filename)) 2572 (filename))
2583 { 2573 {
2584 /* This function can call lisp */ 2574 /* This function can GC */
2585 #ifdef S_IFLNK 2575 #ifdef S_IFLNK
2586 char *buf; 2576 char *buf;
2587 int bufsize; 2577 int bufsize;
2588 int valsize; 2578 int valsize;
2589 Lisp_Object val; 2579 Lisp_Object val;
2590 Lisp_Object handler; 2580 Lisp_Object handler;
2591 struct gcpro gcpro1; 2581 struct gcpro gcpro1;
2592 2582
2583 GCPRO1 (filename);
2593 CHECK_STRING (filename); 2584 CHECK_STRING (filename);
2594 filename = Fexpand_file_name (filename, Qnil); 2585 filename = Fexpand_file_name (filename, Qnil);
2586 UNGCPRO;
2595 2587
2596 /* If the file name has special constructs in it, 2588 /* If the file name has special constructs in it,
2597 call the corresponding file handler. */ 2589 call the corresponding file handler. */
2598 GCPRO1 (filename);
2599 handler = Ffind_file_name_handler (filename, Qfile_symlink_p); 2590 handler = Ffind_file_name_handler (filename, Qfile_symlink_p);
2600 UNGCPRO;
2601 if (!NILP (handler)) 2591 if (!NILP (handler))
2602 return call2 (handler, Qfile_symlink_p, filename); 2592 return call2 (handler, Qfile_symlink_p, filename);
2603 2593
2604 bufsize = 100; 2594 bufsize = 100;
2605 while (1) 2595 while (1)
2631 A directory name spec may be given instead; then the value is t 2621 A directory name spec may be given instead; then the value is t
2632 if the directory so specified exists and really is a directory. 2622 if the directory so specified exists and really is a directory.
2633 */ 2623 */
2634 (filename)) 2624 (filename))
2635 { 2625 {
2636 /* This function can call lisp */ 2626 /* This function can GC */
2637 Lisp_Object abspath; 2627 Lisp_Object abspath;
2638 struct stat st; 2628 struct stat st;
2639 Lisp_Object handler; 2629 Lisp_Object handler;
2640 struct gcpro gcpro1; 2630 struct gcpro gcpro1;
2641 2631
2642 GCPRO1 (current_buffer->directory); 2632 GCPRO1 (filename);
2643 abspath = expand_and_dir_to_file (filename, 2633 abspath = expand_and_dir_to_file (filename,
2644 current_buffer->directory); 2634 current_buffer->directory);
2645 UNGCPRO; 2635 UNGCPRO;
2646 2636
2647 /* If the file name has special constructs in it, 2637 /* If the file name has special constructs in it,
2665 if the directory so specified exists and really is a readable and 2655 if the directory so specified exists and really is a readable and
2666 searchable directory. 2656 searchable directory.
2667 */ 2657 */
2668 (filename)) 2658 (filename))
2669 { 2659 {
2670 /* This function can call lisp */ 2660 /* This function can GC */
2671 Lisp_Object handler; 2661 Lisp_Object handler;
2662 struct gcpro gcpro1;
2672 2663
2673 /* If the file name has special constructs in it, 2664 /* If the file name has special constructs in it,
2674 call the corresponding file handler. */ 2665 call the corresponding file handler. */
2675 handler = Ffind_file_name_handler (filename, Qfile_accessible_directory_p); 2666 handler = Ffind_file_name_handler (filename, Qfile_accessible_directory_p);
2676 if (!NILP (handler)) 2667 if (!NILP (handler))
2677 return call2 (handler, Qfile_accessible_directory_p, 2668 return call2 (handler, Qfile_accessible_directory_p,
2678 filename); 2669 filename);
2679 2670
2671 GCPRO1 (filename);
2680 if (NILP (Ffile_directory_p (filename))) 2672 if (NILP (Ffile_directory_p (filename)))
2673 {
2674 UNGCPRO;
2681 return (Qnil); 2675 return (Qnil);
2682 else 2676 }
2683 return Ffile_executable_p (filename); 2677 handler = Ffile_executable_p (filename);
2678 UNGCPRO;
2679 return (handler);
2684 } 2680 }
2685 2681
2686 DEFUN ("file-regular-p", Ffile_regular_p, 1, 1, 0, /* 2682 DEFUN ("file-regular-p", Ffile_regular_p, 1, 1, 0, /*
2687 "Return t if file FILENAME is the name of a regular file. 2683 "Return t if file FILENAME is the name of a regular file.
2688 This is the sort of file that holds an ordinary stream of data bytes. 2684 This is the sort of file that holds an ordinary stream of data bytes.
2689 */ 2685 */
2690 (filename)) 2686 (filename))
2691 { 2687 {
2692 /* This function can call lisp */ 2688 REGISTER Lisp_Object abspath;
2693 Lisp_Object abspath;
2694 struct stat st; 2689 struct stat st;
2695 Lisp_Object handler; 2690 Lisp_Object handler;
2696 struct gcpro gcpro1; 2691
2697
2698 GCPRO1 (current_buffer->directory);
2699 abspath = expand_and_dir_to_file (filename, current_buffer->directory); 2692 abspath = expand_and_dir_to_file (filename, current_buffer->directory);
2700 UNGCPRO;
2701 2693
2702 /* If the file name has special constructs in it, 2694 /* If the file name has special constructs in it,
2703 call the corresponding file handler. */ 2695 call the corresponding file handler. */
2704 GCPRO1 (abspath);
2705 handler = Ffind_file_name_handler (abspath, Qfile_regular_p); 2696 handler = Ffind_file_name_handler (abspath, Qfile_regular_p);
2706 UNGCPRO;
2707 if (!NILP (handler)) 2697 if (!NILP (handler))
2708 return call2 (handler, Qfile_regular_p, abspath); 2698 return call2 (handler, Qfile_regular_p, abspath);
2709 2699
2710 if (stat ((char *) XSTRING_DATA (abspath), &st) < 0) 2700 if (stat ((char *) XSTRING_DATA (abspath), &st) < 0)
2711 return Qnil; 2701 return Qnil;
2715 DEFUN ("file-modes", Ffile_modes, 1, 1, 0, /* 2705 DEFUN ("file-modes", Ffile_modes, 1, 1, 0, /*
2716 Return mode bits of FILE, as an integer. 2706 Return mode bits of FILE, as an integer.
2717 */ 2707 */
2718 (filename)) 2708 (filename))
2719 { 2709 {
2720 /* This function can call lisp */ 2710 /* This function can GC */
2721 Lisp_Object abspath; 2711 Lisp_Object abspath;
2722 struct stat st; 2712 struct stat st;
2723 Lisp_Object handler; 2713 Lisp_Object handler;
2724 struct gcpro gcpro1; 2714 struct gcpro gcpro1;
2725 2715
2726 GCPRO1 (current_buffer->directory); 2716 GCPRO1 (filename);
2727 abspath = expand_and_dir_to_file (filename, 2717 abspath = expand_and_dir_to_file (filename,
2728 current_buffer->directory); 2718 current_buffer->directory);
2729 UNGCPRO; 2719 UNGCPRO;
2730 2720
2731 /* If the file name has special constructs in it, 2721 /* If the file name has special constructs in it,
2750 Set mode bits of FILE to MODE (an integer). 2740 Set mode bits of FILE to MODE (an integer).
2751 Only the 12 low bits of MODE are used. 2741 Only the 12 low bits of MODE are used.
2752 */ 2742 */
2753 (filename, mode)) 2743 (filename, mode))
2754 { 2744 {
2755 /* This function can call lisp */ 2745 /* This function can GC */
2756 Lisp_Object abspath; 2746 Lisp_Object abspath;
2757 Lisp_Object handler; 2747 Lisp_Object handler;
2758 struct gcpro gcpro1; 2748 struct gcpro gcpro1, gcpro2;
2759 2749
2760 GCPRO1 (current_buffer->directory); 2750 GCPRO2 (filename, mode);
2761 abspath = Fexpand_file_name (filename, current_buffer->directory); 2751 abspath = Fexpand_file_name (filename, current_buffer->directory);
2752 CHECK_INT (mode);
2762 UNGCPRO; 2753 UNGCPRO;
2763
2764 CHECK_INT (mode);
2765 2754
2766 /* If the file name has special constructs in it, 2755 /* If the file name has special constructs in it,
2767 call the corresponding file handler. */ 2756 call the corresponding file handler. */
2768 GCPRO1 (abspath); 2757 GCPRO1 (abspath);
2769 handler = Ffind_file_name_handler (abspath, Qset_file_modes); 2758 handler = Ffind_file_name_handler (abspath, Qset_file_modes);
2826 If FILE1 does not exist, the answer is nil; 2815 If FILE1 does not exist, the answer is nil;
2827 otherwise, if FILE2 does not exist, the answer is t. 2816 otherwise, if FILE2 does not exist, the answer is t.
2828 */ 2817 */
2829 (file1, file2)) 2818 (file1, file2))
2830 { 2819 {
2831 /* This function can call lisp */ 2820 /* This function can GC */
2832 Lisp_Object abspath1, abspath2; 2821 Lisp_Object abspath1, abspath2;
2833 struct stat st; 2822 struct stat st;
2834 int mtime1; 2823 int mtime1;
2835 Lisp_Object handler; 2824 Lisp_Object handler;
2836 struct gcpro gcpro1, gcpro2, gcpro3; 2825 struct gcpro gcpro1, gcpro2;
2837 2826
2838 CHECK_STRING (file1); 2827 CHECK_STRING (file1);
2839 CHECK_STRING (file2); 2828 CHECK_STRING (file2);
2840 2829
2841 abspath1 = Qnil; 2830 abspath1 = Qnil;
2842 abspath2 = Qnil; 2831 GCPRO2 (abspath1, file2);
2843 2832 abspath1 = expand_and_dir_to_file (file1,
2844 GCPRO3 (abspath1, abspath2, current_buffer->directory); 2833 current_buffer->directory);
2845 abspath1 = expand_and_dir_to_file (file1, current_buffer->directory); 2834 abspath2 = expand_and_dir_to_file (file2,
2846 abspath2 = expand_and_dir_to_file (file2, current_buffer->directory); 2835 current_buffer->directory);
2836 UNGCPRO;
2847 2837
2848 /* If the file name has special constructs in it, 2838 /* If the file name has special constructs in it,
2849 call the corresponding file handler. */ 2839 call the corresponding file handler. */
2840 GCPRO2 (abspath1, abspath2);
2850 handler = Ffind_file_name_handler (abspath1, Qfile_newer_than_file_p); 2841 handler = Ffind_file_name_handler (abspath1, Qfile_newer_than_file_p);
2851 if (NILP (handler)) 2842 if (NILP (handler))
2852 handler = Ffind_file_name_handler (abspath2, Qfile_newer_than_file_p); 2843 handler = Ffind_file_name_handler (abspath2, Qfile_newer_than_file_p);
2853 UNGCPRO; 2844 UNGCPRO;
2854 if (!NILP (handler)) 2845 if (!NILP (handler))
2874 /* Stack sizes > 2**16 is a good way to elicit compiler bugs */ 2865 /* Stack sizes > 2**16 is a good way to elicit compiler bugs */
2875 /* #define READ_BUF_SIZE (2 << 16) */ 2866 /* #define READ_BUF_SIZE (2 << 16) */
2876 #define READ_BUF_SIZE (1 << 15) 2867 #define READ_BUF_SIZE (1 << 15)
2877 2868
2878 DEFUN ("insert-file-contents-internal", 2869 DEFUN ("insert-file-contents-internal",
2879 Finsert_file_contents_internal, 1, 5, 0, /* 2870 Finsert_file_contents_internal, 1, 7, 0, /*
2880 Insert contents of file FILENAME after point. 2871 Insert contents of file FILENAME after point; no coding-system frobbing.
2881 Returns list of absolute file name and length of data inserted. 2872 This function is identical to `insert-file-contents' except for the
2882 If second argument VISIT is non-nil, the buffer's visited filename 2873 handling of the CODESYS and USED-CODESYS arguments under
2883 and last save file modtime are set, and it is marked unmodified. 2874 XEmacs/Mule. (When Mule support is not present, both functions are
2884 If visiting and the file does not exist, visiting is completed 2875 identical and ignore the CODESYS and USED-CODESYS arguments.)
2885 before the error is signaled. 2876
2886 2877 If support for Mule exists in this Emacs, the file is decoded according
2887 The optional third and fourth arguments BEG and END 2878 to CODESYS; if omitted, no conversion happens. If USED-CODESYS is non-nil,
2888 specify what portion of the file to insert. 2879 it should be a symbol, and the actual coding system that was used for the
2889 If VISIT is non-nil, BEG and END must be nil. 2880 decoding is stored into it. It will in general be different from CODESYS
2890 If optional fifth argument REPLACE is non-nil, 2881 if CODESYS specifies automatic encoding detection or end-of-line detection.
2891 it means replace the current buffer contents (in the accessible portion) 2882
2892 with the file contents. This is better than simply deleting and inserting 2883 Currently BEG and END refer to byte positions (as opposed to character
2893 the whole thing because (1) it preserves some marker positions 2884 positions), even in Mule. (Fixing this is very difficult.)
2894 and (2) it puts less data in the undo list. 2885 */
2895 */ 2886 (filename, visit, beg, end, replace, codesys, used_codesys))
2896 (filename, visit, beg, end, replace)) 2887 {
2897 { 2888 /* This function can GC */
2898 /* This function can call lisp */
2899 /* #### dmoore - this function hasn't been checked for gc recently */
2900 struct stat st; 2889 struct stat st;
2901 int fd; 2890 int fd;
2902 int saverrno = 0; 2891 int saverrno = 0;
2903 Charcount inserted = 0; 2892 Charcount inserted = 0;
2904 int speccount; 2893 int speccount;
2905 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 2894 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
2906 Lisp_Object handler = Qnil, val; 2895 Lisp_Object handler = Qnil, val;
2907 int total; 2896 int total;
2908 Bufbyte read_buf[READ_BUF_SIZE]; 2897 Bufbyte read_buf[READ_BUF_SIZE];
2909 int mc_count; 2898 int mc_count;
2910 struct buffer *buf = current_buffer; 2899 struct buffer *buf = current_buffer;
2911 Lisp_Object curbuf;
2912 int not_regular = 0; 2900 int not_regular = 0;
2913 2901
2914 if (buf->base_buffer && ! NILP (visit)) 2902 if (buf->base_buffer && ! NILP (visit))
2915 error ("Cannot do file visiting in an indirect buffer"); 2903 error ("Cannot do file visiting in an indirect buffer");
2916 2904
2917 /* No need to call Fbarf_if_buffer_read_only() here. 2905 /* No need to call Fbarf_if_buffer_read_only() here.
2918 That's called in begin_multiple_change() or wherever. */ 2906 That's called in begin_multiple_change() or wherever. */
2919 2907
2920 val = Qnil; 2908 val = Qnil;
2921 2909
2922 /* #### dmoore - should probably check in various places to see if 2910 GCPRO4 (filename, val, visit, handler);
2923 curbuf was killed and if so signal an error? */
2924
2925 XSETBUFFER (curbuf, buf);
2926
2927 GCPRO5 (filename, val, visit, handler, curbuf);
2928 2911
2929 mc_count = (NILP (replace)) ? 2912 mc_count = (NILP (replace)) ?
2930 begin_multiple_change (buf, BUF_PT (buf), BUF_PT (buf)) : 2913 begin_multiple_change (buf, BUF_PT (buf), BUF_PT (buf)) :
2931 begin_multiple_change (buf, BUF_BEG (buf), BUF_Z (buf)); 2914 begin_multiple_change (buf, BUF_BEG (buf), BUF_Z (buf));
2932 2915
2938 /* If the file name has special constructs in it, 2921 /* If the file name has special constructs in it,
2939 call the corresponding file handler. */ 2922 call the corresponding file handler. */
2940 handler = Ffind_file_name_handler (filename, Qinsert_file_contents); 2923 handler = Ffind_file_name_handler (filename, Qinsert_file_contents);
2941 if (!NILP (handler)) 2924 if (!NILP (handler))
2942 { 2925 {
2943 val = call6 (handler, Qinsert_file_contents, filename, 2926 val = call8 (handler, Qinsert_file_contents, filename,
2944 visit, beg, end, replace); 2927 visit, beg, end, replace, codesys, used_codesys);
2945 goto handled; 2928 goto handled;
2946 } 2929 }
2930
2931 #ifdef MULE
2932 if (!NILP (used_codesys))
2933 CHECK_SYMBOL (used_codesys);
2934 #endif
2947 2935
2948 if ( (!NILP (beg) || !NILP (end)) && !NILP (visit) ) 2936 if ( (!NILP (beg) || !NILP (end)) && !NILP (visit) )
2949 error ("Attempt to visit less than an entire file"); 2937 error ("Attempt to visit less than an entire file");
2950 2938
2951 if (!NILP (beg)) 2939 if (!NILP (beg))
3162 Lisp_Object stream = make_filedesc_input_stream (fd, 0, total, 3150 Lisp_Object stream = make_filedesc_input_stream (fd, 0, total,
3163 LSTR_ALLOW_QUIT); 3151 LSTR_ALLOW_QUIT);
3164 3152
3165 NGCPRO1 (stream); 3153 NGCPRO1 (stream);
3166 Lstream_set_buffering (XLSTREAM (stream), LSTREAM_BLOCKN_BUFFERED, 65536); 3154 Lstream_set_buffering (XLSTREAM (stream), LSTREAM_BLOCKN_BUFFERED, 65536);
3155 #ifdef MULE
3156 stream = make_decoding_input_stream
3157 (XLSTREAM (stream), Fget_coding_system (codesys));
3158 Lstream_set_character_mode (XLSTREAM (stream));
3159 Lstream_set_buffering (XLSTREAM (stream), LSTREAM_BLOCKN_BUFFERED, 65536);
3160 #endif
3167 3161
3168 record_unwind_protect (close_stream_unwind, stream); 3162 record_unwind_protect (close_stream_unwind, stream);
3169 3163
3170 /* No need to limit the amount of stuff we attempt to read. (It would 3164 /* No need to limit the amount of stuff we attempt to read. (It would
3171 be incorrect, anyway, when Mule is enabled.) Instead, the limiting 3165 be incorrect, anyway, when Mule is enabled.) Instead, the limiting
3191 !NILP (visit) 3185 !NILP (visit)
3192 ? INSDEL_NO_LOCKING : 0); 3186 ? INSDEL_NO_LOCKING : 0);
3193 inserted += cc_inserted; 3187 inserted += cc_inserted;
3194 cur_point += cc_inserted; 3188 cur_point += cc_inserted;
3195 } 3189 }
3190 #ifdef MULE
3191 if (!NILP (used_codesys))
3192 {
3193 Fset (used_codesys,
3194 XCODING_SYSTEM_NAME (decoding_stream_coding_system (XLSTREAM (stream))));
3195 }
3196 #endif
3196 NUNGCPRO; 3197 NUNGCPRO;
3197 } 3198 }
3198 3199
3199 #ifdef DOS_NT 3200 #ifdef DOS_NT
3200 /* Determine file type from name and remove LFs from CR-LFs if the file 3201 /* Determine file type from name and remove LFs from CR-LFs if the file
3324 Fset_buffer (buf); 3325 Fset_buffer (buf);
3325 Fkill_buffer (tembuf); 3326 Fkill_buffer (tembuf);
3326 return Qnil; 3327 return Qnil;
3327 } 3328 }
3328 3329
3329 DEFUN ("write-region-internal", Fwrite_region_internal, 3, 6, 3330 DEFUN ("write-region-internal", Fwrite_region_internal, 3, 7,
3330 "r\nFWrite region to file: ", /* 3331 "r\nFWrite region to file: ", /*
3331 Write current region into specified file. 3332 Write current region into specified file; no coding-system frobbing.
3332 When called from a program, takes three arguments: 3333 This function is identical to `write-region' except for the handling
3333 START, END and FILENAME. START and END are buffer positions. 3334 of the CODESYS argument under XEmacs/Mule. (When Mule support is not
3334 Optional fourth argument APPEND if non-nil means 3335 present, both functions are identical and ignore the CODESYS argument.)
3335 append to existing file contents (if any). 3336 If support for Mule exists in this Emacs, the file is encoded according
3336 Optional fifth argument VISIT if t means 3337 to the value of CODESYS. If this is nil, no code conversion occurs.
3337 set the last-save-file-modtime of buffer to this file's modtime 3338 */
3338 and mark buffer not modified. 3339 (start, end, filename, append, visit, lockname, codesys))
3339 If VISIT is a string, it is a second file name; 3340 {
3340 the output goes to FILENAME, but the buffer is marked as visiting VISIT. 3341 /* This function can GC */
3341 VISIT is also the file name to lock and unlock for clash detection.
3342 If VISIT is neither t nor nil nor a string,
3343 that means do not print the \"Wrote file\" message.
3344 Kludgy feature: if START is a string, then that string is written
3345 to the file, instead of any buffer contents, and END is ignored.
3346 */
3347 (start, end, filename, append, visit, lockname))
3348 {
3349 /* This function can call lisp */
3350 int desc; 3342 int desc;
3351 int failure; 3343 int failure;
3352 int save_errno = 0; 3344 int save_errno = 0;
3353 struct stat st; 3345 struct stat st;
3354 Lisp_Object fn; 3346 Lisp_Object fn;
3362 Lisp_Object visit_file = Qnil; 3354 Lisp_Object visit_file = Qnil;
3363 Lisp_Object annotations = Qnil; 3355 Lisp_Object annotations = Qnil;
3364 struct buffer *given_buffer; 3356 struct buffer *given_buffer;
3365 Bufpos start1, end1; 3357 Bufpos start1, end1;
3366 3358
3367 /* #### dmoore - if Fexpand_file_name or handlers kill the buffer,
3368 we should signal an error rather than blissfully continuing
3369 along. ARGH, this function is going to lose lose lose. We need
3370 to protect the current_buffer from being destroyed, but the
3371 multiple return points make this a pain in the butt. */
3372
3373 #ifdef DOS_NT 3359 #ifdef DOS_NT
3374 int buffer_file_type 3360 int buffer_file_type
3375 = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY; 3361 = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY;
3376 #endif /* DOS_NT */ 3362 #endif /* DOS_NT */
3377 3363
3364 #ifdef MULE
3365 codesys = Fget_coding_system (codesys);
3366 #endif /* MULE */
3367
3378 if (current_buffer->base_buffer && ! NILP (visit)) 3368 if (current_buffer->base_buffer && ! NILP (visit))
3379 error ("Cannot do file visiting in an indirect buffer"); 3369 error ("Cannot do file visiting in an indirect buffer");
3380 3370
3381 if (!NILP (start) && !STRINGP (start)) 3371 if (!NILP (start) && !STRINGP (start))
3382 get_buffer_range_char (current_buffer, start, end, &start1, &end1, 0); 3372 get_buffer_range_char (current_buffer, start, end, &start1, &end1, 0);
3383 3373
3384 { 3374 {
3385 Lisp_Object handler; 3375 Lisp_Object handler;
3386 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 3376 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
3387
3388 GCPRO5 (start, filename, visit, visit_file, lockname); 3377 GCPRO5 (start, filename, visit, visit_file, lockname);
3389 3378
3390 if (visiting_other) 3379 if (visiting_other)
3391 visit_file = Fexpand_file_name (visit, Qnil); 3380 visit_file = Fexpand_file_name (visit, Qnil);
3392 else 3381 else
3405 if (NILP (handler) && STRINGP (visit)) 3394 if (NILP (handler) && STRINGP (visit))
3406 handler = Ffind_file_name_handler (visit, Qwrite_region); 3395 handler = Ffind_file_name_handler (visit, Qwrite_region);
3407 3396
3408 if (!NILP (handler)) 3397 if (!NILP (handler))
3409 { 3398 {
3410 Lisp_Object val = call6 (handler, Qwrite_region, start, end, 3399 Lisp_Object val = call7 (handler, Qwrite_region, start, end,
3411 filename, append, visit); 3400 filename, append, visit, codesys);
3412 if (visiting) 3401 if (visiting)
3413 { 3402 {
3414 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer); 3403 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer);
3415 current_buffer->save_length = 3404 current_buffer->save_length =
3416 make_int (BUF_SIZE (current_buffer)); 3405 make_int (BUF_SIZE (current_buffer));
3422 } 3411 }
3423 3412
3424 #ifdef CLASH_DETECTION 3413 #ifdef CLASH_DETECTION
3425 if (!auto_saving) 3414 if (!auto_saving)
3426 { 3415 {
3427 Lisp_Object curbuf; 3416 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
3428 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 3417 GCPRO4 (start, filename, visit_file, lockname);
3429
3430 XSETBUFFER (curbuf, current_buffer);
3431 GCPRO5 (start, filename, visit_file, lockname, curbuf);
3432 lock_file (lockname); 3418 lock_file (lockname);
3433 UNGCPRO; 3419 UNGCPRO;
3434 } 3420 }
3435 #endif /* CLASH_DETECTION */ 3421 #endif /* CLASH_DETECTION */
3436 3422
3481 /* if fn exists, truncate to zero length */ 3467 /* if fn exists, truncate to zero length */
3482 vms_truncate (fn_data); 3468 vms_truncate (fn_data);
3483 desc = open (fn_data, O_RDWR, 0); 3469 desc = open (fn_data, O_RDWR, 0);
3484 if (desc < 0) 3470 if (desc < 0)
3485 desc = creat_copy_attrs ((STRINGP (current_buffer->filename) 3471 desc = creat_copy_attrs ((STRINGP (current_buffer->filename)
3486 ? (char *) 3472 ? (char *) XSTRING_DATA (current_buffer->filename)
3487 XSTRING_DATA (current_buffer->filename)
3488 : 0), 3473 : 0),
3489 fn_data); 3474 fn_data);
3490 } 3475 }
3491 else /* Write to temporary name and rename if no errors */ 3476 else /* Write to temporary name and rename if no errors */
3492 { 3477 {
3609 for each request. So I've increased the buffer size 3594 for each request. So I've increased the buffer size
3610 to 64K.) */ 3595 to 64K.) */
3611 outstream = make_filedesc_output_stream (desc, 0, -1, 0); 3596 outstream = make_filedesc_output_stream (desc, 0, -1, 0);
3612 Lstream_set_buffering (XLSTREAM (outstream), 3597 Lstream_set_buffering (XLSTREAM (outstream),
3613 LSTREAM_BLOCKN_BUFFERED, 65536); 3598 LSTREAM_BLOCKN_BUFFERED, 65536);
3599 #ifdef MULE
3600 outstream =
3601 make_encoding_output_stream ( XLSTREAM (outstream), codesys);
3602 Lstream_set_buffering (XLSTREAM (outstream),
3603 LSTREAM_BLOCKN_BUFFERED, 65536);
3604 #endif
3614 if (STRINGP (start)) 3605 if (STRINGP (start))
3615 { 3606 {
3616 instream = make_lisp_string_input_stream (start, 0, -1); 3607 instream = make_lisp_string_input_stream (start, 0, -1);
3617 start1 = 0; 3608 start1 = 0;
3618 } 3609 }
3859 tem = Fcar_safe (Fcar (*annot)); 3850 tem = Fcar_safe (Fcar (*annot));
3860 if (INTP (tem)) 3851 if (INTP (tem))
3861 nextpos = XINT (tem); 3852 nextpos = XINT (tem);
3862 else 3853 else
3863 nextpos = INT_MAX; 3854 nextpos = INT_MAX;
3855 #ifdef MULE
3856 /* If there are annotations left and we have Mule, then we
3857 have to do the I/O one emchar at a time so we can
3858 determine when to insert the annotation. */
3859 if (!NILP (*annot))
3860 {
3861 Emchar ch;
3862 while (pos != nextpos && (ch = Lstream_get_emchar (instr)) != EOF)
3863 {
3864 if (Lstream_put_emchar (outstr, ch) < 0)
3865 return -1;
3866 pos++;
3867 }
3868 }
3869 else
3870 #endif
3864 { 3871 {
3865 while (pos != nextpos) 3872 while (pos != nextpos)
3866 { 3873 {
3867 /* Otherwise there is no point to that. Just go in batches. */ 3874 /* Otherwise there is no point to that. Just go in batches. */
3868 int chunk = min (nextpos - pos, A_WRITE_BATCH_SIZE); 3875 int chunk = min (nextpos - pos, A_WRITE_BATCH_SIZE);
3971 Return t if last mod time of BUF's visited file matches what BUF records. 3978 Return t if last mod time of BUF's visited file matches what BUF records.
3972 This means that the file has not been changed since it was visited or saved. 3979 This means that the file has not been changed since it was visited or saved.
3973 */ 3980 */
3974 (buf)) 3981 (buf))
3975 { 3982 {
3976 /* This function can call lisp */ 3983 /* This function can GC */
3977 struct buffer *b; 3984 struct buffer *b;
3978 struct stat st; 3985 struct stat st;
3979 Lisp_Object handler; 3986 Lisp_Object handler;
3980 3987
3981 CHECK_BUFFER (buf); 3988 CHECK_BUFFER (buf);
4037 (instead of that of the visited file), in the form of a list 4044 (instead of that of the visited file), in the form of a list
4038 (HIGH . LOW) or (HIGH LOW). 4045 (HIGH . LOW) or (HIGH LOW).
4039 */ 4046 */
4040 (time_list)) 4047 (time_list))
4041 { 4048 {
4042 /* This function can call lisp */ 4049 /* This function can GC */
4043 if (!NILP (time_list)) 4050 if (!NILP (time_list))
4044 { 4051 {
4045 time_t the_time; 4052 time_t the_time;
4046 lisp_to_time (time_list, &the_time); 4053 lisp_to_time (time_list, &the_time);
4047 current_buffer->modtime = (int) the_time; 4054 current_buffer->modtime = (int) the_time;
4049 else 4056 else
4050 { 4057 {
4051 Lisp_Object filename; 4058 Lisp_Object filename;
4052 struct stat st; 4059 struct stat st;
4053 Lisp_Object handler; 4060 Lisp_Object handler;
4054 struct gcpro gcpro1, gcpro2, gcpro3; 4061 struct gcpro gcpro1, gcpro2;
4055 4062
4056 GCPRO3 (filename, time_list, current_buffer->filename); 4063 GCPRO2 (filename, time_list);
4057 filename = Fexpand_file_name (current_buffer->filename, Qnil); 4064 filename = Fexpand_file_name (current_buffer->filename,
4065 Qnil);
4058 4066
4059 /* If the file name has special constructs in it, 4067 /* If the file name has special constructs in it,
4060 call the corresponding file handler. */ 4068 call the corresponding file handler. */
4061 handler = Ffind_file_name_handler (filename, Qset_visited_file_modtime); 4069 handler = Ffind_file_name_handler (filename, Qset_visited_file_modtime);
4062 UNGCPRO; 4070 UNGCPRO;
4076 current time. In either case, if the optional arg TIME is supplied, 4084 current time. In either case, if the optional arg TIME is supplied,
4077 it will be used if it is either an integer or a cons of two integers. 4085 it will be used if it is either an integer or a cons of two integers.
4078 */ 4086 */
4079 (buf, in_time)) 4087 (buf, in_time))
4080 { 4088 {
4081 /* This function can call lisp */ 4089 /* This function can GC */
4082 unsigned long time_to_use = 0; 4090 unsigned long time_to_use = 0;
4083 int set_time_to_use = 0; 4091 int set_time_to_use = 0;
4084 struct stat st; 4092 struct stat st;
4085 4093
4086 CHECK_BUFFER (buf); 4094 CHECK_BUFFER (buf);
4104 } 4112 }
4105 4113
4106 if (!set_time_to_use) 4114 if (!set_time_to_use)
4107 { 4115 {
4108 Lisp_Object filename = Qnil; 4116 Lisp_Object filename = Qnil;
4109 struct gcpro gcpro1; 4117 struct gcpro gcpro1, gcpro2;
4110 GCPRO1 (filename); 4118 GCPRO2 (buf, filename);
4111 /* #### dmoore - do we need to protect XBUFFER (buf)->filename?
4112 What if a ^(*&^&*^*& handler renames a buffer? I think I'm
4113 getting a headache now. */
4114 4119
4115 if (STRINGP (XBUFFER (buf)->filename)) 4120 if (STRINGP (XBUFFER (buf)->filename))
4116 filename = Fexpand_file_name (XBUFFER (buf)->filename, Qnil); 4121 filename = Fexpand_file_name (XBUFFER (buf)->filename,
4122 Qnil);
4117 else 4123 else
4118 filename = Qnil; 4124 filename = Qnil;
4125
4126 UNGCPRO;
4119 4127
4120 if (!NILP (filename) && !NILP (Ffile_exists_p (filename))) 4128 if (!NILP (filename) && !NILP (Ffile_exists_p (filename)))
4121 { 4129 {
4122 Lisp_Object handler; 4130 Lisp_Object handler;
4123 4131
4124 /* If the file name has special constructs in it, 4132 /* If the file name has special constructs in it,
4125 call the corresponding file handler. */ 4133 call the corresponding file handler. */
4134 GCPRO1 (filename);
4126 handler = Ffind_file_name_handler (filename, Qset_buffer_modtime); 4135 handler = Ffind_file_name_handler (filename, Qset_buffer_modtime);
4127 UNGCPRO; 4136 UNGCPRO;
4128 if (!NILP (handler)) 4137 if (!NILP (handler))
4129 /* The handler can find the file name the same way we did. */ 4138 /* The handler can find the file name the same way we did. */
4130 return (call2 (handler, Qset_buffer_modtime, Qnil)); 4139 return (call2 (handler, Qset_buffer_modtime, Qnil));
4135 else 4144 else
4136 time_to_use = time ((time_t *) 0); 4145 time_to_use = time ((time_t *) 0);
4137 } 4146 }
4138 } 4147 }
4139 else 4148 else
4140 { 4149 time_to_use = time ((time_t *) 0);
4141 UNGCPRO;
4142 time_to_use = time ((time_t *) 0);
4143 }
4144 } 4150 }
4145 4151
4146 XBUFFER (buf)->modtime = time_to_use; 4152 XBUFFER (buf)->modtime = time_to_use;
4147 4153
4148 return Qnil; 4154 return Qnil;
4149 } 4155 }
4150 4156
4151 4157
4152 static Lisp_Object 4158 static Lisp_Object
4153 auto_save_error (Lisp_Object condition_object, Lisp_Object ignored) 4159 auto_save_error (Lisp_Object condition_object, Lisp_Object ignored)
4154 { 4160 {
4155 /* This function can call lisp */ 4161 /* This function can GC */
4156 if (gc_in_progress) 4162 if (gc_in_progress)
4157 return Qnil;
4158 /* Don't try printing an error message after everything is gone! */
4159 if (preparing_for_armageddon)
4160 return Qnil; 4163 return Qnil;
4161 clear_echo_area (selected_frame (), Qauto_saving, 1); 4164 clear_echo_area (selected_frame (), Qauto_saving, 1);
4162 Fding (Qt, Qauto_save_error, Qnil); 4165 Fding (Qt, Qauto_save_error, Qnil);
4163 message ("Auto-saving...error for %s", XSTRING_DATA (current_buffer->name)); 4166 message ("Auto-saving...error for %s",
4167 XSTRING_DATA (current_buffer->name));
4164 Fsleep_for (make_int (1)); 4168 Fsleep_for (make_int (1));
4165 message ("Auto-saving...error!for %s", XSTRING_DATA (current_buffer->name)); 4169 message ("Auto-saving...error!for %s",
4170 XSTRING_DATA (current_buffer->name));
4166 Fsleep_for (make_int (1)); 4171 Fsleep_for (make_int (1));
4167 message ("Auto-saving...error for %s", XSTRING_DATA (current_buffer->name)); 4172 message ("Auto-saving...error for %s",
4173 XSTRING_DATA (current_buffer->name));
4168 Fsleep_for (make_int (1)); 4174 Fsleep_for (make_int (1));
4169 return Qnil; 4175 return Qnil;
4170 } 4176 }
4171 4177
4172 static Lisp_Object 4178 static Lisp_Object
4173 auto_save_1 (Lisp_Object ignored) 4179 auto_save_1 (Lisp_Object ignored)
4174 { 4180 {
4175 /* This function can call lisp */ 4181 /* This function can GC */
4176 /* #### I think caller is protecting current_buffer? */
4177 struct stat st; 4182 struct stat st;
4178 Lisp_Object fn = current_buffer->filename; 4183 Lisp_Object fn = current_buffer->filename;
4179 Lisp_Object a = current_buffer->auto_save_file_name; 4184 Lisp_Object a = current_buffer->auto_save_file_name;
4180 4185
4181 if (!STRINGP (a)) 4186 if (!STRINGP (a))
4191 readable by owner only. This may annoy some small number of 4196 readable by owner only. This may annoy some small number of
4192 people, but the alternative removes all privacy from email. */ 4197 people, but the alternative removes all privacy from email. */
4193 auto_save_mode_bits = 0600; 4198 auto_save_mode_bits = 0600;
4194 4199
4195 return 4200 return
4196 Fwrite_region_internal (Qnil, Qnil, a, Qnil, Qlambda, Qnil); 4201 /* !!#### need to deal with this 'escape-quoted everywhere */
4197 } 4202 Fwrite_region_internal (Qnil, Qnil, a, Qnil, Qlambda, Qnil,
4198 4203 #ifdef MULE
4199 static Lisp_Object 4204 Qescape_quoted
4200 auto_save_expand_name_error (Lisp_Object condition_object, Lisp_Object ignored) 4205 #else
4201 { 4206 Qnil
4202 /* #### this function should spew an error message about not being 4207 #endif
4203 able to open the .saves file. */ 4208 );
4204 return Qnil;
4205 }
4206
4207 static Lisp_Object
4208 auto_save_expand_name (Lisp_Object name)
4209 {
4210 struct gcpro gcpro1;
4211
4212 /* note that caller did NOT gc protect name, so we do it. */
4213 /* #### dmoore - this might not be neccessary, if condition_case_1
4214 protects it. but I don't think it does. */
4215 GCPRO1 (name);
4216 RETURN_UNGCPRO (Fexpand_file_name (name, Qnil));
4217 } 4209 }
4218 4210
4219 4211
4220 static Lisp_Object 4212 static Lisp_Object
4221 do_auto_save_unwind (Lisp_Object fd) 4213 do_auto_save_unwind (Lisp_Object fd)
4251 Non-nil first argument means do not print any message if successful. 4243 Non-nil first argument means do not print any message if successful.
4252 Non-nil second argument means save only current buffer. 4244 Non-nil second argument means save only current buffer.
4253 */ 4245 */
4254 (no_message, current_only)) 4246 (no_message, current_only))
4255 { 4247 {
4256 /* This function can call lisp */ 4248 /* This function can GC */
4257 struct buffer *b; 4249 struct buffer *old = current_buffer, *b;
4258 Lisp_Object tail, buf; 4250 Lisp_Object tail, buf;
4259 int auto_saved = 0; 4251 int auto_saved = 0;
4260 int do_handled_files; 4252 int do_handled_files;
4261 Lisp_Object oquit = Qnil; 4253 Lisp_Object oquit = Qnil;
4262 Lisp_Object listfile = Qnil; 4254 Lisp_Object listfile = Qnil;
4263 Lisp_Object old;
4264 int listdesc = -1; 4255 int listdesc = -1;
4265 int speccount = specpdl_depth (); 4256 int speccount = specpdl_depth ();
4266 struct gcpro gcpro1, gcpro2, gcpro3; 4257 struct gcpro gcpro1, gcpro2;
4267 4258
4268 XSETBUFFER (old, current_buffer); 4259 GCPRO2 (oquit, listfile);
4269 GCPRO3 (oquit, listfile, old);
4270 check_quit (); /* make Vquit_flag accurate */ 4260 check_quit (); /* make Vquit_flag accurate */
4271 /* Ordinarily don't quit within this function, 4261 /* Ordinarily don't quit within this function,
4272 but don't make it impossible to quit (in case we get hung in I/O). */ 4262 but don't make it impossible to quit (in case we get hung in I/O). */
4273 oquit = Vquit_flag; 4263 oquit = Vquit_flag;
4274 Vquit_flag = Qnil; 4264 Vquit_flag = Qnil;
4280 no_message = Qt; 4270 no_message = Qt;
4281 4271
4282 run_hook (Qauto_save_hook); 4272 run_hook (Qauto_save_hook);
4283 4273
4284 if (GC_STRINGP (Vauto_save_list_file_name)) 4274 if (GC_STRINGP (Vauto_save_list_file_name))
4285 listfile = condition_case_1 (Qt, 4275 listfile = Fexpand_file_name (Vauto_save_list_file_name, Qnil);
4286 auto_save_expand_name,
4287 Vauto_save_list_file_name,
4288 auto_save_expand_name_error, Qnil);
4289 4276
4290 /* Make sure auto_saving is reset. */ 4277 /* Make sure auto_saving is reset. */
4291 record_unwind_protect (do_auto_save_unwind_2, make_int (auto_saving)); 4278 record_unwind_protect (do_auto_save_unwind_2, make_int (auto_saving));
4292 4279
4293 auto_saving = 1; 4280 auto_saving = 1;
4376 We only do this now so that the file only exists 4363 We only do this now so that the file only exists
4377 if we actually auto-saved any files. */ 4364 if we actually auto-saved any files. */
4378 if (!auto_saved && GC_STRINGP (listfile) && listdesc < 0) 4365 if (!auto_saved && GC_STRINGP (listfile) && listdesc < 0)
4379 { 4366 {
4380 #ifdef DOS_NT 4367 #ifdef DOS_NT
4381 listdesc = open ((char *) XSTRING_DATA (listfile), 4368 listdesc = open ((char *) XSTRING_DATA (listfile),
4382 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT, 4369 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT,
4383 S_IREAD | S_IWRITE); 4370 S_IREAD | S_IWRITE);
4384 #else /* not DOS_NT */ 4371 #else /* not DOS_NT */
4385 listdesc = creat ((char *) XSTRING_DATA (listfile), 0666); 4372 listdesc = creat ((char *) XSTRING_DATA (listfile), 0666);
4386 #endif /* not DOS_NT */ 4373 #endif /* not DOS_NT */
4419 write (listdesc, auto_save_file_name_ext, 4406 write (listdesc, auto_save_file_name_ext,
4420 auto_save_file_name_ext_len); 4407 auto_save_file_name_ext_len);
4421 write (listdesc, "\n", 1); 4408 write (listdesc, "\n", 1);
4422 } 4409 }
4423 4410
4424 /* dmoore - In a bad scenario we've set b=XBUFFER(buf) 4411 condition_case_1 (Qt,
4425 based on values in Vbuffer_alist. auto_save_1 may 4412 auto_save_1, Qnil,
4426 cause lisp handlers to run. Those handlers may kill 4413 auto_save_error, Qnil);
4427 the buffer and then GC. Since the buffer is killed,
4428 it's no longer in Vbuffer_alist so it might get reaped
4429 by the GC. We also need to protect tail. */
4430 /* #### There is probably a lot of other code which has
4431 pointers into buffers which may get blown away by
4432 handlers. */
4433 {
4434 struct gcpro gcpro1, gcpro2;
4435 GCPRO2 (buf, tail);
4436 condition_case_1 (Qt,
4437 auto_save_1, Qnil,
4438 auto_save_error, Qnil);
4439 UNGCPRO;
4440 }
4441 /* Handler killed our saved current-buffer! Pick any. */
4442 if (!BUFFER_LIVE_P (XBUFFER (old)))
4443 XSETBUFFER (old, current_buffer);
4444
4445 set_buffer_internal (XBUFFER (old));
4446 auto_saved++; 4414 auto_saved++;
4447
4448 /* Handler killed their own buffer! */
4449 if (!BUFFER_LIVE_P(b))
4450 continue;
4451
4452 b->auto_save_modified = BUF_MODIFF (b); 4415 b->auto_save_modified = BUF_MODIFF (b);
4453 b->save_length = make_int (BUF_SIZE (b)); 4416 b->save_length = make_int (BUF_SIZE (b));
4417 set_buffer_internal (old);
4418
4454 EMACS_GET_TIME (after_time); 4419 EMACS_GET_TIME (after_time);
4455 /* If auto-save took more than 60 seconds, 4420 /* If auto-save took more than 60 seconds,
4456 assume it was an NFS failure that got a timeout. */ 4421 assume it was an NFS failure that got a timeout. */
4457 if (EMACS_SECS (after_time) - EMACS_SECS (before_time) > 60) 4422 if (EMACS_SECS (after_time) - EMACS_SECS (before_time) > 60)
4458 b->auto_save_failure_time = EMACS_SECS (after_time); 4423 b->auto_save_failure_time = EMACS_SECS (after_time);