Mercurial > hg > xemacs-beta
comparison src/fileio.c @ 16:0293115a14e9 r19-15b91
Import from CVS: tag r19-15b91
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:49:20 +0200 |
parents | ac2d302a0011 |
children | 859a2309aef8 |
comparison
equal
deleted
inserted
replaced
15:ad457d5f7d04 | 16:0293115a14e9 |
---|---|
419 } | 419 } |
420 | 420 |
421 #ifdef FILE_SYSTEM_CASE | 421 #ifdef FILE_SYSTEM_CASE |
422 file = FILE_SYSTEM_CASE (file); | 422 file = FILE_SYSTEM_CASE (file); |
423 #endif | 423 #endif |
424 beg = string_data (XSTRING (file)); | 424 beg = XSTRING_DATA (file); |
425 p = beg + string_length (XSTRING (file)); | 425 p = beg + XSTRING_LENGTH (file); |
426 | 426 |
427 while (p != beg && !IS_ANY_SEP (p[-1]) | 427 while (p != beg && !IS_ANY_SEP (p[-1]) |
428 #ifdef VMS | 428 #ifdef VMS |
429 && p[-1] != ':' && p[-1] != ']' && p[-1] != '>' | 429 && p[-1] != ':' && p[-1] != ']' && p[-1] != '>' |
430 #endif /* VMS */ | 430 #endif /* VMS */ |
486 handler = Ffind_file_name_handler (file, Qfile_name_nondirectory); | 486 handler = Ffind_file_name_handler (file, Qfile_name_nondirectory); |
487 if (!NILP (handler)) | 487 if (!NILP (handler)) |
488 return (call2_check_string (handler, Qfile_name_nondirectory, | 488 return (call2_check_string (handler, Qfile_name_nondirectory, |
489 file)); | 489 file)); |
490 | 490 |
491 beg = string_data (XSTRING (file)); | 491 beg = XSTRING_DATA (file); |
492 end = p = beg + string_length (XSTRING (file)); | 492 end = p = beg + XSTRING_LENGTH (file); |
493 | 493 |
494 while (p != beg && !IS_ANY_SEP (p[-1]) | 494 while (p != beg && !IS_ANY_SEP (p[-1]) |
495 #ifdef VMS | 495 #ifdef VMS |
496 && p[-1] != ':' && p[-1] != ']' && p[-1] != '>' | 496 && p[-1] != ':' && p[-1] != ']' && p[-1] != '>' |
497 #endif /* VMS */ | 497 #endif /* VMS */ |
626 handler = Ffind_file_name_handler (file, Qfile_name_as_directory); | 626 handler = Ffind_file_name_handler (file, Qfile_name_as_directory); |
627 if (!NILP (handler)) | 627 if (!NILP (handler)) |
628 return (call2_check_string (handler, Qfile_name_as_directory, | 628 return (call2_check_string (handler, Qfile_name_as_directory, |
629 file)); | 629 file)); |
630 | 630 |
631 buf = (char *) alloca (string_length (XSTRING (file)) + 10); | 631 buf = (char *) alloca (XSTRING_LENGTH (file) + 10); |
632 return build_string (file_name_as_directory | 632 return build_string (file_name_as_directory |
633 (buf, (char *) string_data (XSTRING (file)))); | 633 (buf, (char *) XSTRING_DATA (file))); |
634 } | 634 } |
635 | 635 |
636 /* | 636 /* |
637 * Convert from directory name to filename. | 637 * Convert from directory name to filename. |
638 * On VMS: | 638 * On VMS: |
822 directory)); | 822 directory)); |
823 #ifdef VMS | 823 #ifdef VMS |
824 /* 20 extra chars is insufficient for VMS, since we might perform a | 824 /* 20 extra chars is insufficient for VMS, since we might perform a |
825 logical name translation. an equivalence string can be up to 255 | 825 logical name translation. an equivalence string can be up to 255 |
826 chars long, so grab that much extra space... - sss */ | 826 chars long, so grab that much extra space... - sss */ |
827 buf = (char *) alloca (string_length (XSTRING (directory)) + 20 + 255); | 827 buf = (char *) alloca (XSTRING_LENGTH (directory) + 20 + 255); |
828 #else | 828 #else |
829 buf = (char *) alloca (string_length (XSTRING (directory)) + 20); | 829 buf = (char *) alloca (XSTRING_LENGTH (directory) + 20); |
830 #endif | 830 #endif |
831 directory_file_name ((char *) string_data (XSTRING (directory)), buf); | 831 directory_file_name ((char *) XSTRING_DATA (directory), buf); |
832 return build_string (buf); | 832 return build_string (buf); |
833 } | 833 } |
834 | 834 |
835 DEFUN ("make-temp-name", Fmake_temp_name, Smake_temp_name, 1, 1, 0 /* | 835 DEFUN ("make-temp-name", Fmake_temp_name, Smake_temp_name, 1, 1, 0 /* |
836 Generate temporary file name (string) starting with PREFIX (a string). | 836 Generate temporary file name (string) starting with PREFIX (a string). |
844 Bufbyte *data; | 844 Bufbyte *data; |
845 Bytecount len; | 845 Bytecount len; |
846 Lisp_Object val; | 846 Lisp_Object val; |
847 | 847 |
848 CHECK_STRING (prefix); | 848 CHECK_STRING (prefix); |
849 len = string_length (XSTRING (prefix)); | 849 len = XSTRING_LENGTH (prefix); |
850 val = make_uninit_string (len + countof (suffix) - 1); | 850 val = make_uninit_string (len + countof (suffix) - 1); |
851 data = string_data (XSTRING (val)); | 851 data = XSTRING_DATA (val); |
852 memcpy (data, string_data (XSTRING (prefix)), len); | 852 memcpy (data, XSTRING_DATA (prefix), len); |
853 memcpy (data + len, suffix, countof (suffix)); | 853 memcpy (data + len, suffix, countof (suffix)); |
854 /* !!#### does mktemp() Mule-encapsulate? */ | 854 /* !!#### does mktemp() Mule-encapsulate? */ |
855 mktemp ((char *) data); | 855 mktemp ((char *) data); |
856 | 856 |
857 return val; | 857 return val; |
938 Putting this call here avoids all that crud. | 938 Putting this call here avoids all that crud. |
939 | 939 |
940 The EQ test avoids infinite recursion. */ | 940 The EQ test avoids infinite recursion. */ |
941 if (! NILP (defalt) && !EQ (defalt, name) | 941 if (! NILP (defalt) && !EQ (defalt, name) |
942 /* This saves time in a common case. */ | 942 /* This saves time in a common case. */ |
943 && ! (string_length (XSTRING (defalt)) >= 3 | 943 && ! (XSTRING_LENGTH (defalt) >= 3 |
944 && IS_DIRECTORY_SEP (string_byte (XSTRING (defalt), 0)) | 944 && IS_DIRECTORY_SEP (XSTRING_BYTE (defalt, 0)) |
945 && IS_DEVICE_SEP (string_byte (XSTRING (defalt), 1)))) | 945 && IS_DEVICE_SEP (XSTRING_BYTE (defalt, 1)))) |
946 { | 946 { |
947 struct gcpro gcpro1; | 947 struct gcpro gcpro1; |
948 | 948 |
949 GCPRO1 (name); | 949 GCPRO1 (name); |
950 defalt = Fexpand_file_name (defalt, Qnil); | 950 defalt = Fexpand_file_name (defalt, Qnil); |
957 #endif | 957 #endif |
958 #ifdef FILE_SYSTEM_CASE | 958 #ifdef FILE_SYSTEM_CASE |
959 name = FILE_SYSTEM_CASE (name); | 959 name = FILE_SYSTEM_CASE (name); |
960 #endif | 960 #endif |
961 | 961 |
962 nm = string_data (XSTRING (name)); | 962 nm = XSTRING_DATA (name); |
963 | 963 |
964 #ifdef MSDOS | 964 #ifdef MSDOS |
965 /* First map all backslashes to slashes. */ | 965 /* First map all backslashes to slashes. */ |
966 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm)); | 966 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm)); |
967 #endif | 967 #endif |
1123 #ifdef VMS | 1123 #ifdef VMS |
1124 if (strchr (nm, '/')) | 1124 if (strchr (nm, '/')) |
1125 return build_string (sys_translate_unix (nm)); | 1125 return build_string (sys_translate_unix (nm)); |
1126 #endif /* VMS */ | 1126 #endif /* VMS */ |
1127 #ifndef DOS_NT | 1127 #ifndef DOS_NT |
1128 if (nm == string_data (XSTRING (name))) | 1128 if (nm == XSTRING_DATA (name)) |
1129 return name; | 1129 return name; |
1130 return build_string ((char *) nm); | 1130 return build_string ((char *) nm); |
1131 #endif /* not DOS_NT */ | 1131 #endif /* not DOS_NT */ |
1132 } | 1132 } |
1133 } | 1133 } |
1202 && drive == -1 | 1202 && drive == -1 |
1203 #endif /* DOS_NT */ | 1203 #endif /* DOS_NT */ |
1204 && !newdir | 1204 && !newdir |
1205 && STRINGP (defalt)) | 1205 && STRINGP (defalt)) |
1206 { | 1206 { |
1207 newdir = string_data (XSTRING (defalt)); | 1207 newdir = XSTRING_DATA (defalt); |
1208 } | 1208 } |
1209 | 1209 |
1210 #ifdef DOS_NT | 1210 #ifdef DOS_NT |
1211 if (newdir == 0 && relpath) | 1211 if (newdir == 0 && relpath) |
1212 newdir = defdir; | 1212 newdir = defdir; |
1424 #else | 1424 #else |
1425 { | 1425 { |
1426 char resolved_path[MAXPATHLEN]; | 1426 char resolved_path[MAXPATHLEN]; |
1427 char path[MAXPATHLEN]; | 1427 char path[MAXPATHLEN]; |
1428 char *p = path; | 1428 char *p = path; |
1429 int elen = string_length (XSTRING (expanded_name)); | 1429 int elen = XSTRING_LENGTH (expanded_name); |
1430 | 1430 |
1431 if (elen >= countof (path)) | 1431 if (elen >= countof (path)) |
1432 goto toolong; | 1432 goto toolong; |
1433 | 1433 |
1434 memcpy (path, string_data (XSTRING (expanded_name)), elen + 1); | 1434 memcpy (path, XSTRING_DATA (expanded_name), elen + 1); |
1435 /* memset (resolved_path, 0, sizeof (resolved_path)); */ | 1435 /* memset (resolved_path, 0, sizeof (resolved_path)); */ |
1436 | 1436 |
1437 /* Try doing it all at once. */ | 1437 /* Try doing it all at once. */ |
1438 /* !!#### Does realpath() Mule-encapsulate? */ | 1438 /* !!#### Does realpath() Mule-encapsulate? */ |
1439 if (!realpath (path, resolved_path)) | 1439 if (!realpath (path, resolved_path)) |
1488 } | 1488 } |
1489 } | 1489 } |
1490 | 1490 |
1491 { | 1491 { |
1492 int rlen = strlen (resolved_path); | 1492 int rlen = strlen (resolved_path); |
1493 if (elen > 0 && string_byte (XSTRING (expanded_name), elen - 1) == '/' | 1493 if (elen > 0 && XSTRING_BYTE (expanded_name, elen - 1) == '/' |
1494 && !(rlen > 0 && resolved_path[rlen - 1] == '/')) | 1494 && !(rlen > 0 && resolved_path[rlen - 1] == '/')) |
1495 { | 1495 { |
1496 if (rlen + 1 > countof (resolved_path)) | 1496 if (rlen + 1 > countof (resolved_path)) |
1497 goto toolong; | 1497 goto toolong; |
1498 resolved_path[rlen] = '/'; | 1498 resolved_path[rlen] = '/'; |
1550 if (!NILP (retval)) | 1550 if (!NILP (retval)) |
1551 CHECK_STRING (retval); | 1551 CHECK_STRING (retval); |
1552 return retval; | 1552 return retval; |
1553 } | 1553 } |
1554 | 1554 |
1555 nm = string_data (XSTRING (string)); | 1555 nm = XSTRING_DATA (string); |
1556 #ifdef MSDOS | 1556 #ifdef MSDOS |
1557 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm)); | 1557 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm)); |
1558 substituted = !strcmp (nm, string_data (XSTRING (string))); | 1558 substituted = !strcmp (nm, XSTRING_DATA (string)); |
1559 #endif | 1559 #endif |
1560 endp = nm + string_length (XSTRING (string)); | 1560 endp = nm + XSTRING_LENGTH (string); |
1561 | 1561 |
1562 /* If /~ or // appears, discard everything through first slash. */ | 1562 /* If /~ or // appears, discard everything through first slash. */ |
1563 | 1563 |
1564 for (p = nm; p != endp; p++) | 1564 for (p = nm; p != endp; p++) |
1565 { | 1565 { |
1649 if (!substituted) | 1649 if (!substituted) |
1650 return string; | 1650 return string; |
1651 | 1651 |
1652 /* If substitution required, recopy the string and do it */ | 1652 /* If substitution required, recopy the string and do it */ |
1653 /* Make space in stack frame for the new copy */ | 1653 /* Make space in stack frame for the new copy */ |
1654 xnm = (Bufbyte *) alloca (string_length (XSTRING (string)) + total + 1); | 1654 xnm = (Bufbyte *) alloca (XSTRING_LENGTH (string) + total + 1); |
1655 x = xnm; | 1655 x = xnm; |
1656 | 1656 |
1657 /* Copy the rest of the name through, replacing $ constructs with values */ | 1657 /* Copy the rest of the name through, replacing $ constructs with values */ |
1658 for (p = nm; *p;) | 1658 for (p = nm; *p;) |
1659 if (*p != '$') | 1659 if (*p != '$') |
1751 GCPRO1 (filename); | 1751 GCPRO1 (filename); |
1752 abspath = Fexpand_file_name (filename, defdir); | 1752 abspath = Fexpand_file_name (filename, defdir); |
1753 #ifdef VMS | 1753 #ifdef VMS |
1754 { | 1754 { |
1755 Bufbyte c = | 1755 Bufbyte c = |
1756 string_byte (XSTRING (abspath), string_length (XSTRING (abspath)) - 1); | 1756 XSTRING_BYTE (abspath, XSTRING_LENGTH (abspath) - 1); |
1757 if (c == ':' || c == ']' || c == '>') | 1757 if (c == ':' || c == ']' || c == '>') |
1758 abspath = Fdirectory_file_name (abspath); | 1758 abspath = Fdirectory_file_name (abspath); |
1759 } | 1759 } |
1760 #else | 1760 #else |
1761 /* Remove final slash, if any (unless path is root). | 1761 /* Remove final slash, if any (unless path is root). |
1762 stat behaves differently depending! */ | 1762 stat behaves differently depending! */ |
1763 if (string_length (XSTRING (abspath)) > 1 | 1763 if (XSTRING_LENGTH (abspath) > 1 |
1764 && IS_DIRECTORY_SEP (string_byte (XSTRING (abspath), | 1764 && IS_DIRECTORY_SEP (XSTRING_BYTE (abspath, XSTRING_LENGTH (abspath) - 1)) |
1765 string_length (XSTRING (abspath)) - 1)) | 1765 && !IS_DEVICE_SEP (XSTRING_BYTE (abspath, XSTRING_LENGTH (abspath) - 2))) |
1766 && !IS_DEVICE_SEP (string_byte (XSTRING (abspath), | |
1767 string_length (XSTRING (abspath)) - 2))) | |
1768 /* We cannot take shortcuts; they might be wrong for magic file names. */ | 1766 /* We cannot take shortcuts; they might be wrong for magic file names. */ |
1769 abspath = Fdirectory_file_name (abspath); | 1767 abspath = Fdirectory_file_name (abspath); |
1770 #endif | 1768 #endif |
1771 UNGCPRO; | 1769 UNGCPRO; |
1772 return abspath; | 1770 return abspath; |
1786 { | 1784 { |
1787 struct stat statbuf; | 1785 struct stat statbuf; |
1788 | 1786 |
1789 /* stat is a good way to tell whether the file exists, | 1787 /* stat is a good way to tell whether the file exists, |
1790 regardless of what access permissions it has. */ | 1788 regardless of what access permissions it has. */ |
1791 if (stat ((char *) string_data (XSTRING (absname)), &statbuf) >= 0) | 1789 if (stat ((char *) XSTRING_DATA (absname), &statbuf) >= 0) |
1792 { | 1790 { |
1793 Lisp_Object tem; | 1791 Lisp_Object tem; |
1794 struct gcpro gcpro1; | 1792 struct gcpro gcpro1; |
1795 | 1793 |
1796 GCPRO1 (absname); | 1794 GCPRO1 (absname); |
1797 if (interactive) | 1795 if (interactive) |
1798 tem = call1 | 1796 tem = call1 |
1799 (Qyes_or_no_p, | 1797 (Qyes_or_no_p, |
1800 (emacs_doprnt_string_c | 1798 (emacs_doprnt_string_c |
1801 ((CONST Bufbyte *) GETTEXT ("File %s already exists; %s anyway? "), | 1799 ((CONST Bufbyte *) GETTEXT ("File %s already exists; %s anyway? "), |
1802 Qnil, -1, string_data (XSTRING (absname)), | 1800 Qnil, -1, XSTRING_DATA (absname), |
1803 GETTEXT (querystring)))); | 1801 GETTEXT (querystring)))); |
1804 else | 1802 else |
1805 tem = Qnil; | 1803 tem = Qnil; |
1806 UNGCPRO; | 1804 UNGCPRO; |
1807 if (NILP (tem)) | 1805 if (NILP (tem)) |
1828 This is what happens in interactive use with M-x. | 1826 This is what happens in interactive use with M-x. |
1829 Fourth arg KEEP-TIME non-nil means give the new file the same | 1827 Fourth arg KEEP-TIME non-nil means give the new file the same |
1830 last-modified time as the old one. (This works on only some systems.) | 1828 last-modified time as the old one. (This works on only some systems.) |
1831 A prefix arg makes KEEP-TIME non-nil. | 1829 A prefix arg makes KEEP-TIME non-nil. |
1832 */ ) | 1830 */ ) |
1833 (filename, newname, ok_if_already_exists, keep_date) | 1831 (filename, newname, ok_if_already_exists, keep_time) |
1834 Lisp_Object filename, newname, ok_if_already_exists, keep_date; | 1832 Lisp_Object filename, newname, ok_if_already_exists, keep_time; |
1835 { | 1833 { |
1836 /* This function can GC */ | 1834 /* This function can GC */ |
1837 int ifd, ofd, n; | 1835 int ifd, ofd, n; |
1838 char buf[16 * 1024]; | 1836 char buf[16 * 1024]; |
1839 struct stat st, out_st; | 1837 struct stat st, out_st; |
1857 handler = Ffind_file_name_handler (newname, Qcopy_file); | 1855 handler = Ffind_file_name_handler (newname, Qcopy_file); |
1858 if (!NILP (handler)) | 1856 if (!NILP (handler)) |
1859 { | 1857 { |
1860 UNGCPRO; | 1858 UNGCPRO; |
1861 return call5 (handler, Qcopy_file, filename, newname, | 1859 return call5 (handler, Qcopy_file, filename, newname, |
1862 ok_if_already_exists, keep_date); | 1860 ok_if_already_exists, keep_time); |
1863 } | 1861 } |
1864 | 1862 |
1865 /* When second argument is a directory, copy the file into it. | 1863 /* When second argument is a directory, copy the file into it. |
1866 (copy-file "foo" "bar/") == (copy-file "foo" "bar/foo") | 1864 (copy-file "foo" "bar/") == (copy-file "foo" "bar/foo") |
1867 */ | 1865 */ |
1873 | 1871 |
1874 args[0] = newname; | 1872 args[0] = newname; |
1875 args[1] = Qnil; args[2] = Qnil; | 1873 args[1] = Qnil; args[2] = Qnil; |
1876 NGCPRO1 (*args); | 1874 NGCPRO1 (*args); |
1877 ngcpro1.nvars = 3; | 1875 ngcpro1.nvars = 3; |
1878 if (string_byte (XSTRING (newname), | 1876 if (XSTRING_BYTE (newname, XSTRING_LENGTH (newname) - 1) != '/') |
1879 string_length (XSTRING (newname)) - 1) != '/') | |
1880 args[i++] = build_string ("/"); | 1877 args[i++] = build_string ("/"); |
1881 args[i++] = Ffile_name_nondirectory (filename); | 1878 args[i++] = Ffile_name_nondirectory (filename); |
1882 newname = Fconcat (i, args); | 1879 newname = Fconcat (i, args); |
1883 NUNGCPRO; | 1880 NUNGCPRO; |
1884 } | 1881 } |
1885 | 1882 |
1886 if (NILP (ok_if_already_exists) | 1883 if (NILP (ok_if_already_exists) |
1887 || INTP (ok_if_already_exists)) | 1884 || INTP (ok_if_already_exists)) |
1888 barf_or_query_if_file_exists (newname, "copy to it", | 1885 barf_or_query_if_file_exists (newname, "copy to it", |
1889 INTP (ok_if_already_exists), &out_st); | 1886 INTP (ok_if_already_exists), &out_st); |
1890 else if (stat ((CONST char *) string_data (XSTRING (newname)), &out_st) < 0) | 1887 else if (stat ((CONST char *) XSTRING_DATA (newname), &out_st) < 0) |
1891 out_st.st_mode = 0; | 1888 out_st.st_mode = 0; |
1892 | 1889 |
1893 ifd = open ((char *) string_data (XSTRING (filename)), O_RDONLY, 0); | 1890 ifd = open ((char *) XSTRING_DATA (filename), O_RDONLY, 0); |
1894 if (ifd < 0) | 1891 if (ifd < 0) |
1895 report_file_error ("Opening input file", Fcons (filename, Qnil)); | 1892 report_file_error ("Opening input file", Fcons (filename, Qnil)); |
1896 | 1893 |
1897 record_unwind_protect (close_file_unwind, make_int (ifd)); | 1894 record_unwind_protect (close_file_unwind, make_int (ifd)); |
1898 | 1895 |
1929 } | 1926 } |
1930 #endif /* S_ISREG && S_ISLNK */ | 1927 #endif /* S_ISREG && S_ISLNK */ |
1931 | 1928 |
1932 #ifdef VMS | 1929 #ifdef VMS |
1933 /* Create the copy file with the same record format as the input file */ | 1930 /* Create the copy file with the same record format as the input file */ |
1934 ofd = sys_creat ((char *) string_data (XSTRING (newname)), 0666, ifd); | 1931 ofd = sys_creat ((char *) XSTRING_DATA (newname), 0666, ifd); |
1935 #else | 1932 #else |
1936 #ifdef MSDOS | 1933 #ifdef MSDOS |
1937 /* System's default file type was set to binary by _fmode in emacs.c. */ | 1934 /* System's default file type was set to binary by _fmode in emacs.c. */ |
1938 ofd = creat ((char *) string_data (XSTRING (newname)), S_IREAD | S_IWRITE); | 1935 ofd = creat ((char *) XSTRING_DATA (newname), S_IREAD | S_IWRITE); |
1939 #else /* not MSDOS */ | 1936 #else /* not MSDOS */ |
1940 ofd = creat ((char *) string_data (XSTRING (newname)), 0666); | 1937 ofd = creat ((char *) XSTRING_DATA (newname), 0666); |
1941 #endif /* not MSDOS */ | 1938 #endif /* not MSDOS */ |
1942 #endif /* VMS */ | 1939 #endif /* VMS */ |
1943 if (ofd < 0) | 1940 if (ofd < 0) |
1944 report_file_error ("Opening output file", list1 (newname)); | 1941 report_file_error ("Opening output file", list1 (newname)); |
1945 | 1942 |
1958 if (close (ofd) < 0) | 1955 if (close (ofd) < 0) |
1959 report_file_error ("I/O error", Fcons (newname, Qnil)); | 1956 report_file_error ("I/O error", Fcons (newname, Qnil)); |
1960 | 1957 |
1961 if (input_file_statable_p) | 1958 if (input_file_statable_p) |
1962 { | 1959 { |
1963 if (!NILP (keep_date)) | 1960 if (!NILP (keep_time)) |
1964 { | 1961 { |
1965 EMACS_TIME atime, mtime; | 1962 EMACS_TIME atime, mtime; |
1966 EMACS_SET_SECS_USECS (atime, st.st_atime, 0); | 1963 EMACS_SET_SECS_USECS (atime, st.st_atime, 0); |
1967 EMACS_SET_SECS_USECS (mtime, st.st_mtime, 0); | 1964 EMACS_SET_SECS_USECS (mtime, st.st_mtime, 0); |
1968 if (set_file_times ((char *) string_data (XSTRING (newname)), atime, | 1965 if (set_file_times ((char *) XSTRING_DATA (newname), atime, |
1969 mtime)) | 1966 mtime)) |
1970 report_file_error ("I/O error", Fcons (newname, Qnil)); | 1967 report_file_error ("I/O error", Fcons (newname, Qnil)); |
1971 } | 1968 } |
1972 #ifndef MSDOS | 1969 #ifndef MSDOS |
1973 chmod ((CONST char *) string_data (XSTRING (newname)), | 1970 chmod ((CONST char *) XSTRING_DATA (newname), |
1974 st.st_mode & 07777); | 1971 st.st_mode & 07777); |
1975 #else /* MSDOS */ | 1972 #else /* MSDOS */ |
1976 #if defined (__DJGPP__) && __DJGPP__ > 1 | 1973 #if defined (__DJGPP__) && __DJGPP__ > 1 |
1977 /* In DJGPP v2.0 and later, fstat usually returns true file mode bits, | 1974 /* In DJGPP v2.0 and later, fstat usually returns true file mode bits, |
1978 and if it can't, it tells so. Otherwise, under MSDOS we usually | 1975 and if it can't, it tells so. Otherwise, under MSDOS we usually |
1979 get only the READ bit, which will make the copied file read-only, | 1976 get only the READ bit, which will make the copied file read-only, |
1980 so it's better not to chmod at all. */ | 1977 so it's better not to chmod at all. */ |
1981 if ((_djstat_flags & _STFAIL_WRITEBIT) == 0) | 1978 if ((_djstat_flags & _STFAIL_WRITEBIT) == 0) |
1982 chmod ((char *) string_data (XSTRING (newname)), st.st_mode & 07777); | 1979 chmod ((char *) XSTRING_DATA (newname), st.st_mode & 07777); |
1983 #endif /* DJGPP version 2 or newer */ | 1980 #endif /* DJGPP version 2 or newer */ |
1984 #endif /* MSDOS */ | 1981 #endif /* MSDOS */ |
1985 } | 1982 } |
1986 | 1983 |
1987 /* We'll close it by hand */ | 1984 /* We'll close it by hand */ |
2016 UNGCPRO; | 2013 UNGCPRO; |
2017 if (!NILP (handler)) | 2014 if (!NILP (handler)) |
2018 return (call2 (handler, Qmake_directory_internal, | 2015 return (call2 (handler, Qmake_directory_internal, |
2019 dirname)); | 2016 dirname)); |
2020 | 2017 |
2021 if (string_length (XSTRING (dirname)) > (sizeof (dir) - 1)) | 2018 if (XSTRING_LENGTH (dirname) > (sizeof (dir) - 1)) |
2022 { | 2019 { |
2023 return Fsignal (Qfile_error, | 2020 return Fsignal (Qfile_error, |
2024 list3 (build_translated_string ("Creating directory"), | 2021 list3 (build_translated_string ("Creating directory"), |
2025 build_translated_string ("pathame too long"), | 2022 build_translated_string ("pathame too long"), |
2026 dirname)); | 2023 dirname)); |
2027 } | 2024 } |
2028 strncpy (dir, (char *) string_data (XSTRING (dirname)), | 2025 strncpy (dir, (char *) XSTRING_DATA (dirname), |
2029 string_length (XSTRING (dirname)) + 1); | 2026 XSTRING_LENGTH (dirname) + 1); |
2030 | 2027 |
2031 #ifndef VMS | 2028 #ifndef VMS |
2032 if (dir [string_length (XSTRING (dirname)) - 1] == '/') | 2029 if (dir [XSTRING_LENGTH (dirname) - 1] == '/') |
2033 dir [string_length (XSTRING (dirname)) - 1] = 0; | 2030 dir [XSTRING_LENGTH (dirname) - 1] = 0; |
2034 #endif | 2031 #endif |
2035 | 2032 |
2036 #ifdef WINDOWSNT | 2033 #ifdef WINDOWSNT |
2037 if (mkdir (dir) != 0) | 2034 if (mkdir (dir) != 0) |
2038 #else | 2035 #else |
2062 handler = Ffind_file_name_handler (dirname, Qdelete_directory); | 2059 handler = Ffind_file_name_handler (dirname, Qdelete_directory); |
2063 UNGCPRO; | 2060 UNGCPRO; |
2064 if (!NILP (handler)) | 2061 if (!NILP (handler)) |
2065 return (call2 (handler, Qdelete_directory, dirname)); | 2062 return (call2 (handler, Qdelete_directory, dirname)); |
2066 | 2063 |
2067 if (rmdir ((char *) string_data (XSTRING (dirname))) != 0) | 2064 if (rmdir ((char *) XSTRING_DATA (dirname)) != 0) |
2068 report_file_error ("Removing directory", list1 (dirname)); | 2065 report_file_error ("Removing directory", list1 (dirname)); |
2069 | 2066 |
2070 return Qnil; | 2067 return Qnil; |
2071 } | 2068 } |
2072 | 2069 |
2088 handler = Ffind_file_name_handler (filename, Qdelete_file); | 2085 handler = Ffind_file_name_handler (filename, Qdelete_file); |
2089 UNGCPRO; | 2086 UNGCPRO; |
2090 if (!NILP (handler)) | 2087 if (!NILP (handler)) |
2091 return call2 (handler, Qdelete_file, filename); | 2088 return call2 (handler, Qdelete_file, filename); |
2092 | 2089 |
2093 if (0 > unlink ((char *) string_data (XSTRING (filename)))) | 2090 if (0 > unlink ((char *) XSTRING_DATA (filename))) |
2094 report_file_error ("Removing old name", list1 (filename)); | 2091 report_file_error ("Removing old name", list1 (filename)); |
2095 return Qnil; | 2092 return Qnil; |
2096 } | 2093 } |
2097 | 2094 |
2098 static Lisp_Object | 2095 static Lisp_Object |
2155 | 2152 |
2156 args[0] = newname; | 2153 args[0] = newname; |
2157 args[1] = Qnil; args[2] = Qnil; | 2154 args[1] = Qnil; args[2] = Qnil; |
2158 NGCPRO1 (*args); | 2155 NGCPRO1 (*args); |
2159 ngcpro1.nvars = 3; | 2156 ngcpro1.nvars = 3; |
2160 if (string_byte (XSTRING (newname), | 2157 if (XSTRING_BYTE (newname, XSTRING_LENGTH (newname) - 1) != '/') |
2161 string_length (XSTRING (newname)) - 1) != '/') | |
2162 args[i++] = build_string ("/"); | 2158 args[i++] = build_string ("/"); |
2163 args[i++] = Ffile_name_nondirectory (filename); | 2159 args[i++] = Ffile_name_nondirectory (filename); |
2164 newname = Fconcat (i, args); | 2160 newname = Fconcat (i, args); |
2165 NUNGCPRO; | 2161 NUNGCPRO; |
2166 } | 2162 } |
2176 /* FSFmacs only calls rename() here under BSD 4.1, and calls | 2172 /* FSFmacs only calls rename() here under BSD 4.1, and calls |
2177 link() and unlink() otherwise, but that's bogus. Sometimes | 2173 link() and unlink() otherwise, but that's bogus. Sometimes |
2178 rename() succeeds where link()/unlink() fail, and we have | 2174 rename() succeeds where link()/unlink() fail, and we have |
2179 configure check for rename() and emulate using link()/unlink() | 2175 configure check for rename() and emulate using link()/unlink() |
2180 if necessary. */ | 2176 if necessary. */ |
2181 if (0 > rename ((char *) string_data (XSTRING (filename)), | 2177 if (0 > rename ((char *) XSTRING_DATA (filename), |
2182 (char *) string_data (XSTRING (newname)))) | 2178 (char *) XSTRING_DATA (newname))) |
2183 #endif /* not WINDOWSNT */ | 2179 #endif /* not WINDOWSNT */ |
2184 { | 2180 { |
2185 #ifdef WINDOWSNT | 2181 #ifdef WINDOWSNT |
2186 /* Why two? And why doesn't MS document what MoveFile will return? */ | 2182 /* Why two? And why doesn't MS document what MoveFile will return? */ |
2187 if (GetLastError () == ERROR_FILE_EXISTS | 2183 if (GetLastError () == ERROR_FILE_EXISTS |
2248 #ifdef WINDOWSNT | 2244 #ifdef WINDOWSNT |
2249 /* Windows does not support this operation. */ | 2245 /* Windows does not support this operation. */ |
2250 report_file_error ("Adding new name", Flist (2, &filename)); | 2246 report_file_error ("Adding new name", Flist (2, &filename)); |
2251 #else /* not WINDOWSNT */ | 2247 #else /* not WINDOWSNT */ |
2252 | 2248 |
2253 unlink ((char *) string_data (XSTRING (newname))); | 2249 unlink ((char *) XSTRING_DATA (newname)); |
2254 if (0 > link ((char *) string_data (XSTRING (filename)), | 2250 if (0 > link ((char *) XSTRING_DATA (filename), |
2255 (char *) string_data (XSTRING (newname)))) | 2251 (char *) XSTRING_DATA (newname))) |
2256 { | 2252 { |
2257 report_file_error ("Adding new name", | 2253 report_file_error ("Adding new name", |
2258 list2 (filename, newname)); | 2254 list2 (filename, newname)); |
2259 } | 2255 } |
2260 #endif /* not WINDOWSNT */ | 2256 #endif /* not WINDOWSNT */ |
2283 CHECK_STRING (filename); | 2279 CHECK_STRING (filename); |
2284 CHECK_STRING (linkname); | 2280 CHECK_STRING (linkname); |
2285 /* If the link target has a ~, we must expand it to get | 2281 /* If the link target has a ~, we must expand it to get |
2286 a truly valid file name. Otherwise, do not expand; | 2282 a truly valid file name. Otherwise, do not expand; |
2287 we want to permit links to relative file names. */ | 2283 we want to permit links to relative file names. */ |
2288 if (string_byte (XSTRING (filename), 0) == '~') /* #### Un*x-specific */ | 2284 if (XSTRING_BYTE (filename, 0) == '~') /* #### Un*x-specific */ |
2289 filename = Fexpand_file_name (filename, Qnil); | 2285 filename = Fexpand_file_name (filename, Qnil); |
2290 linkname = Fexpand_file_name (linkname, Qnil); | 2286 linkname = Fexpand_file_name (linkname, Qnil); |
2291 | 2287 |
2292 /* If the file name has special constructs in it, | 2288 /* If the file name has special constructs in it, |
2293 call the corresponding file handler. */ | 2289 call the corresponding file handler. */ |
2306 if (NILP (ok_if_already_exists) | 2302 if (NILP (ok_if_already_exists) |
2307 || INTP (ok_if_already_exists)) | 2303 || INTP (ok_if_already_exists)) |
2308 barf_or_query_if_file_exists (linkname, "make it a link", | 2304 barf_or_query_if_file_exists (linkname, "make it a link", |
2309 INTP (ok_if_already_exists), 0); | 2305 INTP (ok_if_already_exists), 0); |
2310 | 2306 |
2311 unlink ((char *) string_data (XSTRING (linkname))); | 2307 unlink ((char *) XSTRING_DATA (linkname)); |
2312 if (0 > symlink ((char *) string_data (XSTRING (filename)), | 2308 if (0 > symlink ((char *) XSTRING_DATA (filename), |
2313 (char *) string_data (XSTRING (linkname)))) | 2309 (char *) XSTRING_DATA (linkname))) |
2314 { | 2310 { |
2315 report_file_error ("Making symbolic link", | 2311 report_file_error ("Making symbolic link", |
2316 list2 (filename, linkname)); | 2312 list2 (filename, linkname)); |
2317 } | 2313 } |
2318 UNGCPRO; | 2314 UNGCPRO; |
2331 Lisp_Object varname; | 2327 Lisp_Object varname; |
2332 Lisp_Object string; | 2328 Lisp_Object string; |
2333 { | 2329 { |
2334 CHECK_STRING (varname); | 2330 CHECK_STRING (varname); |
2335 if (NILP (string)) | 2331 if (NILP (string)) |
2336 delete_logical_name ((char *) string_data (XSTRING (varname))); | 2332 delete_logical_name ((char *) XSTRING_DATA (varname)); |
2337 else | 2333 else |
2338 { | 2334 { |
2339 CHECK_STRING (string); | 2335 CHECK_STRING (string); |
2340 | 2336 |
2341 if (string_length (XSTRING (string)) == 0) | 2337 if (XSTRING_LENGTH (string) == 0) |
2342 delete_logical_name ((char *) string_data (XSTRING (varname))); | 2338 delete_logical_name ((char *) XSTRING_DATA (varname)); |
2343 else | 2339 else |
2344 define_logical_name ((char *) string_data (XSTRING (varname)), (char *) string_data (XSTRING (string))); | 2340 define_logical_name ((char *) XSTRING_DATA (varname), (char *) XSTRING_DATA (string)); |
2345 } | 2341 } |
2346 | 2342 |
2347 return string; | 2343 return string; |
2348 } | 2344 } |
2349 #endif /* VMS */ | 2345 #endif /* VMS */ |
2389 Lisp_Object filename; | 2385 Lisp_Object filename; |
2390 { | 2386 { |
2391 Bufbyte *ptr; | 2387 Bufbyte *ptr; |
2392 | 2388 |
2393 CHECK_STRING (filename); | 2389 CHECK_STRING (filename); |
2394 ptr = string_data (XSTRING (filename)); | 2390 ptr = XSTRING_DATA (filename); |
2395 if (IS_DIRECTORY_SEP (*ptr) || *ptr == '~' | 2391 if (IS_DIRECTORY_SEP (*ptr) || *ptr == '~' |
2396 #ifdef VMS | 2392 #ifdef VMS |
2397 /* ??? This criterion is probably wrong for '<'. */ | 2393 /* ??? This criterion is probably wrong for '<'. */ |
2398 || strchr (ptr, ':') || strchr (ptr, '<') | 2394 || strchr (ptr, ':') || strchr (ptr, '<') |
2399 || (*ptr == '[' && (ptr[1] != '-' || (ptr[2] != '.' && ptr[2] != ']')) | 2395 || (*ptr == '[' && (ptr[1] != '-' || (ptr[2] != '.' && ptr[2] != ']')) |
2485 handler = Ffind_file_name_handler (abspath, Qfile_exists_p); | 2481 handler = Ffind_file_name_handler (abspath, Qfile_exists_p); |
2486 UNGCPRO; | 2482 UNGCPRO; |
2487 if (!NILP (handler)) | 2483 if (!NILP (handler)) |
2488 return call2 (handler, Qfile_exists_p, abspath); | 2484 return call2 (handler, Qfile_exists_p, abspath); |
2489 | 2485 |
2490 if (stat ((char *) string_data (XSTRING (abspath)), &statbuf) >= 0) | 2486 if (stat ((char *) XSTRING_DATA (abspath), &statbuf) >= 0) |
2491 return (Qt); | 2487 return (Qt); |
2492 else | 2488 else |
2493 return (Qnil); | 2489 return (Qnil); |
2494 } | 2490 } |
2495 | 2491 |
2517 handler = Ffind_file_name_handler (abspath, Qfile_executable_p); | 2513 handler = Ffind_file_name_handler (abspath, Qfile_executable_p); |
2518 UNGCPRO; | 2514 UNGCPRO; |
2519 if (!NILP (handler)) | 2515 if (!NILP (handler)) |
2520 return call2 (handler, Qfile_executable_p, abspath); | 2516 return call2 (handler, Qfile_executable_p, abspath); |
2521 | 2517 |
2522 return (check_executable ((char *) string_data (XSTRING (abspath))) | 2518 return (check_executable ((char *) XSTRING_DATA (abspath)) |
2523 ? Qt : Qnil); | 2519 ? Qt : Qnil); |
2524 } | 2520 } |
2525 | 2521 |
2526 DEFUN ("file-readable-p", Ffile_readable_p, Sfile_readable_p, 1, 1, 0 /* | 2522 DEFUN ("file-readable-p", Ffile_readable_p, Sfile_readable_p, 1, 1, 0 /* |
2527 Return t if file FILENAME exists and you can read it. | 2523 Return t if file FILENAME exists and you can read it. |
2547 handler = Ffind_file_name_handler (abspath, Qfile_readable_p); | 2543 handler = Ffind_file_name_handler (abspath, Qfile_readable_p); |
2548 UNGCPRO; | 2544 UNGCPRO; |
2549 if (!NILP (handler)) | 2545 if (!NILP (handler)) |
2550 return call2 (handler, Qfile_readable_p, abspath); | 2546 return call2 (handler, Qfile_readable_p, abspath); |
2551 | 2547 |
2552 desc = open ((char *) string_data (XSTRING (abspath)), O_RDONLY, 0); | 2548 desc = open ((char *) XSTRING_DATA (abspath), O_RDONLY, 0); |
2553 if (desc < 0) | 2549 if (desc < 0) |
2554 return Qnil; | 2550 return Qnil; |
2555 close (desc); | 2551 close (desc); |
2556 return Qt; | 2552 return Qt; |
2557 } | 2553 } |
2581 handler = Ffind_file_name_handler (abspath, Qfile_writable_p); | 2577 handler = Ffind_file_name_handler (abspath, Qfile_writable_p); |
2582 UNGCPRO; | 2578 UNGCPRO; |
2583 if (!NILP (handler)) | 2579 if (!NILP (handler)) |
2584 return call2 (handler, Qfile_writable_p, abspath); | 2580 return call2 (handler, Qfile_writable_p, abspath); |
2585 | 2581 |
2586 if (stat ((char *) string_data (XSTRING (abspath)), &statbuf) >= 0) | 2582 if (stat ((char *) XSTRING_DATA (abspath), &statbuf) >= 0) |
2587 return (check_writable ((char *) string_data (XSTRING (abspath))) | 2583 return (check_writable ((char *) XSTRING_DATA (abspath)) |
2588 ? Qt : Qnil); | 2584 ? Qt : Qnil); |
2589 | 2585 |
2590 | 2586 |
2591 dir = Ffile_name_directory (abspath); | 2587 dir = Ffile_name_directory (abspath); |
2592 #if defined (VMS) || defined (MSDOS) | 2588 #if defined (VMS) || defined (MSDOS) |
2593 if (!NILP (dir)) | 2589 if (!NILP (dir)) |
2594 dir = Fdirectory_file_name (dir); | 2590 dir = Fdirectory_file_name (dir); |
2595 #endif /* VMS or MSDOS */ | 2591 #endif /* VMS or MSDOS */ |
2596 return (check_writable (!NILP (dir) ? (char *) string_data (XSTRING (dir)) | 2592 return (check_writable (!NILP (dir) ? (char *) XSTRING_DATA (dir) |
2597 : "") | 2593 : "") |
2598 ? Qt : Qnil); | 2594 ? Qt : Qnil); |
2599 } | 2595 } |
2600 | 2596 |
2601 DEFUN ("file-symlink-p", Ffile_symlink_p, Sfile_symlink_p, 1, 1, 0 /* | 2597 DEFUN ("file-symlink-p", Ffile_symlink_p, Sfile_symlink_p, 1, 1, 0 /* |
2629 bufsize = 100; | 2625 bufsize = 100; |
2630 while (1) | 2626 while (1) |
2631 { | 2627 { |
2632 buf = (char *) xmalloc (bufsize); | 2628 buf = (char *) xmalloc (bufsize); |
2633 memset (buf, 0, bufsize); | 2629 memset (buf, 0, bufsize); |
2634 valsize = readlink ((char *) string_data (XSTRING (filename)), | 2630 valsize = readlink ((char *) XSTRING_DATA (filename), |
2635 buf, bufsize); | 2631 buf, bufsize); |
2636 if (valsize < bufsize) break; | 2632 if (valsize < bufsize) break; |
2637 /* Buffer was not long enough */ | 2633 /* Buffer was not long enough */ |
2638 xfree (buf); | 2634 xfree (buf); |
2639 bufsize *= 2; | 2635 bufsize *= 2; |
2676 handler = Ffind_file_name_handler (abspath, Qfile_directory_p); | 2672 handler = Ffind_file_name_handler (abspath, Qfile_directory_p); |
2677 UNGCPRO; | 2673 UNGCPRO; |
2678 if (!NILP (handler)) | 2674 if (!NILP (handler)) |
2679 return call2 (handler, Qfile_directory_p, abspath); | 2675 return call2 (handler, Qfile_directory_p, abspath); |
2680 | 2676 |
2681 if (stat ((char *) string_data (XSTRING (abspath)), &st) < 0) | 2677 if (stat ((char *) XSTRING_DATA (abspath), &st) < 0) |
2682 return Qnil; | 2678 return Qnil; |
2683 return (st.st_mode & S_IFMT) == S_IFDIR ? Qt : Qnil; | 2679 return (st.st_mode & S_IFMT) == S_IFDIR ? Qt : Qnil; |
2684 } | 2680 } |
2685 | 2681 |
2686 DEFUN ("file-accessible-directory-p", | 2682 DEFUN ("file-accessible-directory-p", |
2734 call the corresponding file handler. */ | 2730 call the corresponding file handler. */ |
2735 handler = Ffind_file_name_handler (abspath, Qfile_regular_p); | 2731 handler = Ffind_file_name_handler (abspath, Qfile_regular_p); |
2736 if (!NILP (handler)) | 2732 if (!NILP (handler)) |
2737 return call2 (handler, Qfile_regular_p, abspath); | 2733 return call2 (handler, Qfile_regular_p, abspath); |
2738 | 2734 |
2739 if (stat ((char *) string_data (XSTRING (abspath)), &st) < 0) | 2735 if (stat ((char *) XSTRING_DATA (abspath), &st) < 0) |
2740 return Qnil; | 2736 return Qnil; |
2741 return (st.st_mode & S_IFMT) == S_IFREG ? Qt : Qnil; | 2737 return (st.st_mode & S_IFMT) == S_IFREG ? Qt : Qnil; |
2742 } | 2738 } |
2743 | 2739 |
2744 DEFUN ("file-modes", Ffile_modes, Sfile_modes, 1, 1, 0 /* | 2740 DEFUN ("file-modes", Ffile_modes, Sfile_modes, 1, 1, 0 /* |
2764 handler = Ffind_file_name_handler (abspath, Qfile_modes); | 2760 handler = Ffind_file_name_handler (abspath, Qfile_modes); |
2765 UNGCPRO; | 2761 UNGCPRO; |
2766 if (!NILP (handler)) | 2762 if (!NILP (handler)) |
2767 return call2 (handler, Qfile_modes, abspath); | 2763 return call2 (handler, Qfile_modes, abspath); |
2768 | 2764 |
2769 if (stat ((char *) string_data (XSTRING (abspath)), &st) < 0) | 2765 if (stat ((char *) XSTRING_DATA (abspath), &st) < 0) |
2770 return Qnil; | 2766 return Qnil; |
2771 #ifdef DOS_NT | 2767 #ifdef DOS_NT |
2772 if (check_executable (XSTRING (abspath)->data)) | 2768 if (check_executable (XSTRING (abspath)->data)) |
2773 st.st_mode |= S_IEXEC; | 2769 st.st_mode |= S_IEXEC; |
2774 #endif /* DOS_NT */ | 2770 #endif /* DOS_NT */ |
2799 handler = Ffind_file_name_handler (abspath, Qset_file_modes); | 2795 handler = Ffind_file_name_handler (abspath, Qset_file_modes); |
2800 UNGCPRO; | 2796 UNGCPRO; |
2801 if (!NILP (handler)) | 2797 if (!NILP (handler)) |
2802 return call3 (handler, Qset_file_modes, abspath, mode); | 2798 return call3 (handler, Qset_file_modes, abspath, mode); |
2803 | 2799 |
2804 if (chmod ((char *) string_data (XSTRING (abspath)), XINT (mode)) < 0) | 2800 if (chmod ((char *) XSTRING_DATA (abspath), XINT (mode)) < 0) |
2805 report_file_error ("Doing chmod", Fcons (abspath, Qnil)); | 2801 report_file_error ("Doing chmod", Fcons (abspath, Qnil)); |
2806 | 2802 |
2807 return Qnil; | 2803 return Qnil; |
2808 } | 2804 } |
2809 | 2805 |
2889 UNGCPRO; | 2885 UNGCPRO; |
2890 if (!NILP (handler)) | 2886 if (!NILP (handler)) |
2891 return call3 (handler, Qfile_newer_than_file_p, abspath1, | 2887 return call3 (handler, Qfile_newer_than_file_p, abspath1, |
2892 abspath2); | 2888 abspath2); |
2893 | 2889 |
2894 if (stat ((char *) string_data (XSTRING (abspath1)), &st) < 0) | 2890 if (stat ((char *) XSTRING_DATA (abspath1), &st) < 0) |
2895 return Qnil; | 2891 return Qnil; |
2896 | 2892 |
2897 mtime1 = st.st_mtime; | 2893 mtime1 = st.st_mtime; |
2898 | 2894 |
2899 if (stat ((char *) string_data (XSTRING (abspath2)), &st) < 0) | 2895 if (stat ((char *) XSTRING_DATA (abspath2), &st) < 0) |
2900 return Qt; | 2896 return Qt; |
2901 | 2897 |
2902 return (mtime1 > st.st_mtime) ? Qt : Qnil; | 2898 return (mtime1 > st.st_mtime) ? Qt : Qnil; |
2903 } | 2899 } |
2904 | 2900 |
2969 call the corresponding file handler. */ | 2965 call the corresponding file handler. */ |
2970 handler = Ffind_file_name_handler (filename, Qinsert_file_contents); | 2966 handler = Ffind_file_name_handler (filename, Qinsert_file_contents); |
2971 if (!NILP (handler)) | 2967 if (!NILP (handler)) |
2972 { | 2968 { |
2973 val = call6 (handler, Qinsert_file_contents, filename, | 2969 val = call6 (handler, Qinsert_file_contents, filename, |
2974 visit, beg, end, replace); | 2970 visit, beg, end, replace); |
2975 goto handled; | 2971 goto handled; |
2976 } | 2972 } |
2977 | 2973 |
2978 if ( (!NILP (beg) || !NILP (end)) && !NILP (visit) ) | 2974 if ( (!NILP (beg) || !NILP (end)) && !NILP (visit) ) |
2979 error ("Attempt to visit less than an entire file"); | 2975 error ("Attempt to visit less than an entire file"); |
2987 CHECK_INT (end); | 2983 CHECK_INT (end); |
2988 | 2984 |
2989 fd = -1; | 2985 fd = -1; |
2990 | 2986 |
2991 #ifndef APOLLO | 2987 #ifndef APOLLO |
2992 if (stat ((char *) string_data (XSTRING (filename)), &st) < 0) | 2988 if (stat ((char *) XSTRING_DATA (filename), &st) < 0) |
2993 #else /* APOLLO */ | 2989 #else /* APOLLO */ |
2994 if ((fd = open ((char *) string_data (XSTRING (filename)), O_RDONLY, 0)) < 0 | 2990 if ((fd = open ((char *) XSTRING_DATA (filename), O_RDONLY, 0)) < 0 |
2995 || fstat (fd, &st) < 0) | 2991 || fstat (fd, &st) < 0) |
2996 #endif /* APOLLO */ | 2992 #endif /* APOLLO */ |
2997 { | 2993 { |
2998 if (fd >= 0) close (fd); | 2994 if (fd >= 0) close (fd); |
2999 badopen: | 2995 badopen: |
3025 } | 3021 } |
3026 } | 3022 } |
3027 #endif | 3023 #endif |
3028 | 3024 |
3029 if (fd < 0) | 3025 if (fd < 0) |
3030 if ((fd = open ((char *) string_data (XSTRING (filename)), O_RDONLY, 0)) < 0) | 3026 if ((fd = open ((char *) XSTRING_DATA (filename), O_RDONLY, 0)) < 0) |
3031 goto badopen; | 3027 goto badopen; |
3032 | 3028 |
3033 /* Replacement should preserve point as it preserves markers. */ | 3029 /* Replacement should preserve point as it preserves markers. */ |
3034 if (!NILP (replace)) | 3030 if (!NILP (replace)) |
3035 record_unwind_protect (restore_point_unwind, Fpoint_marker (Qnil, Qnil)); | 3031 record_unwind_protect (restore_point_unwind, Fpoint_marker (Qnil, Qnil)); |
3049 | 3045 |
3050 /* If requested, replace the accessible part of the buffer | 3046 /* If requested, replace the accessible part of the buffer |
3051 with the file contents. Avoid replacing text at the | 3047 with the file contents. Avoid replacing text at the |
3052 beginning or end of the buffer that matches the file contents; | 3048 beginning or end of the buffer that matches the file contents; |
3053 that preserves markers pointing to the unchanged parts. */ | 3049 that preserves markers pointing to the unchanged parts. */ |
3054 #if !defined (DOS_NT) | 3050 #if !defined (DOS_NT) && !defined (MULE) |
3055 /* The replace-mode code currently only works when the assumption | 3051 /* The replace-mode code currently only works when the assumption |
3056 'one byte == one char' holds true. This fails under MSDOS and | 3052 'one byte == one char' holds true. This fails under MSDOS and |
3057 Windows NT (because newlines are represented as CR-LF in text | 3053 Windows NT (because newlines are represented as CR-LF in text |
3058 files). */ | 3054 files). and under Mule because files may contain multibyte characters. */ |
3059 # define FSFMACS_SPEEDY_INSERT | 3055 # define FSFMACS_SPEEDY_INSERT |
3060 #endif | 3056 #endif |
3061 #ifndef FSFMACS_SPEEDY_INSERT | 3057 #ifndef FSFMACS_SPEEDY_INSERT |
3062 if (!NILP (replace)) | 3058 if (!NILP (replace)) |
3063 { | 3059 { |
3080 Bufpos bufpos; | 3076 Bufpos bufpos; |
3081 | 3077 |
3082 nread = read_allowing_quit (fd, buffer, sizeof buffer); | 3078 nread = read_allowing_quit (fd, buffer, sizeof buffer); |
3083 if (nread < 0) | 3079 if (nread < 0) |
3084 error ("IO error reading %s: %s", | 3080 error ("IO error reading %s: %s", |
3085 string_data (XSTRING (filename)), strerror (errno)); | 3081 XSTRING_DATA (filename), strerror (errno)); |
3086 else if (nread == 0) | 3082 else if (nread == 0) |
3087 break; | 3083 break; |
3088 bufpos = 0; | 3084 bufpos = 0; |
3089 while (bufpos < nread && same_at_start < BUF_ZV (buf) | 3085 while (bufpos < nread && same_at_start < BUF_ZV (buf) |
3090 && BUF_FETCH_CHAR (buf, same_at_start) == buffer[bufpos]) | 3086 && BUF_FETCH_CHAR (buf, same_at_start) == buffer[bufpos]) |
3128 { | 3124 { |
3129 nread = read_allowing_quit (fd, buffer + total_read, | 3125 nread = read_allowing_quit (fd, buffer + total_read, |
3130 trial - total_read); | 3126 trial - total_read); |
3131 if (nread <= 0) | 3127 if (nread <= 0) |
3132 error ("IO error reading %s: %s", | 3128 error ("IO error reading %s: %s", |
3133 string_data (XSTRING (filename)), strerror (errno)); | 3129 XSTRING_DATA (filename), strerror (errno)); |
3134 total_read += nread; | 3130 total_read += nread; |
3135 } | 3131 } |
3136 /* Scan this bufferfull from the end, comparing with | 3132 /* Scan this bufferfull from the end, comparing with |
3137 the Emacs buffer. */ | 3133 the Emacs buffer. */ |
3138 bufpos = total_read; | 3134 bufpos = total_read; |
3195 NGCPRO1 (stream); | 3191 NGCPRO1 (stream); |
3196 Lstream_set_buffering (XLSTREAM (stream), LSTREAM_BLOCKN_BUFFERED, 65536); | 3192 Lstream_set_buffering (XLSTREAM (stream), LSTREAM_BLOCKN_BUFFERED, 65536); |
3197 | 3193 |
3198 record_unwind_protect (close_stream_unwind, stream); | 3194 record_unwind_protect (close_stream_unwind, stream); |
3199 | 3195 |
3200 /* No need to limit the amount of stuff we attempt to read. | 3196 /* No need to limit the amount of stuff we attempt to read. (It would |
3201 Instead, the limiting occurs inside of the filedesc stream. */ | 3197 be incorrect, anyway, when Mule is enabled.) Instead, the limiting |
3198 occurs inside of the filedesc stream. */ | |
3202 while (1) | 3199 while (1) |
3203 { | 3200 { |
3204 Bytecount this_len; | 3201 Bytecount this_len; |
3205 Charcount cc_inserted; | 3202 Charcount cc_inserted; |
3206 | 3203 |
3245 unbind_to (speccount, Qnil); | 3242 unbind_to (speccount, Qnil); |
3246 | 3243 |
3247 if (saverrno != 0) | 3244 if (saverrno != 0) |
3248 { | 3245 { |
3249 error ("IO error reading %s: %s", | 3246 error ("IO error reading %s: %s", |
3250 string_data (XSTRING (filename)), strerror (saverrno)); | 3247 XSTRING_DATA (filename), strerror (saverrno)); |
3251 } | 3248 } |
3252 | 3249 |
3253 notfound: | 3250 notfound: |
3254 handled: | 3251 handled: |
3255 | 3252 |
3258 if (!NILP (visit)) | 3255 if (!NILP (visit)) |
3259 { | 3256 { |
3260 if (!EQ (buf->undo_list, Qt)) | 3257 if (!EQ (buf->undo_list, Qt)) |
3261 buf->undo_list = Qnil; | 3258 buf->undo_list = Qnil; |
3262 #ifdef APOLLO | 3259 #ifdef APOLLO |
3263 stat ((char *) string_data (XSTRING (filename)), &st); | 3260 stat ((char *) XSTRING_DATA (filename), &st); |
3264 #endif | 3261 #endif |
3265 if (NILP (handler)) | 3262 if (NILP (handler)) |
3266 { | 3263 { |
3267 buf->modtime = st.st_mtime; | 3264 buf->modtime = st.st_mtime; |
3268 buf->filename = filename; | 3265 buf->filename = filename; |
3474 | 3471 |
3475 fn = filename; | 3472 fn = filename; |
3476 desc = -1; | 3473 desc = -1; |
3477 if (!NILP (append)) | 3474 if (!NILP (append)) |
3478 #ifdef DOS_NT | 3475 #ifdef DOS_NT |
3479 desc = open ((char *) string_data (XSTRING (fn)), | 3476 desc = open ((char *) XSTRING_DATA (fn), |
3480 (O_WRONLY | buffer_file_type), 0); | 3477 (O_WRONLY | buffer_file_type), 0); |
3481 #else /* not DOS_NT */ | 3478 #else /* not DOS_NT */ |
3482 desc = open ((char *) string_data (XSTRING (fn)), O_WRONLY, 0); | 3479 desc = open ((char *) XSTRING_DATA (fn), O_WRONLY, 0); |
3483 #endif /* not DOS_NT */ | 3480 #endif /* not DOS_NT */ |
3484 | 3481 |
3485 if (desc < 0) | 3482 if (desc < 0) |
3486 #ifndef VMS | 3483 #ifndef VMS |
3487 { | 3484 { |
3488 #ifdef DOS_NT | 3485 #ifdef DOS_NT |
3489 desc = open ((char *) string_data (XSTRING (fn)), | 3486 desc = open ((char *) XSTRING_DATA (fn), |
3490 (O_WRONLY | O_TRUNC | O_CREAT | buffer_file_type), | 3487 (O_WRONLY | O_TRUNC | O_CREAT | buffer_file_type), |
3491 (S_IREAD | S_IWRITE)); | 3488 (S_IREAD | S_IWRITE)); |
3492 #else /* not DOS_NT */ | 3489 #else /* not DOS_NT */ |
3493 desc = creat ((char *) string_data (XSTRING (fn)), | 3490 desc = creat ((char *) XSTRING_DATA (fn), |
3494 ((auto_saving) ? auto_save_mode_bits : 0666)); | 3491 ((auto_saving) ? auto_save_mode_bits : 0666)); |
3495 #endif /* DOS_NT */ | 3492 #endif /* DOS_NT */ |
3496 } | 3493 } |
3497 #else /* VMS */ | 3494 #else /* VMS */ |
3498 { | 3495 { |
3499 if (auto_saving) /* Overwrite any previous version of autosave file */ | 3496 if (auto_saving) /* Overwrite any previous version of autosave file */ |
3500 { | 3497 { |
3501 char *fn_data = string_data (XSTRING (fn)); | 3498 char *fn_data = XSTRING_DATA (fn); |
3502 /* if fn exists, truncate to zero length */ | 3499 /* if fn exists, truncate to zero length */ |
3503 vms_truncate (fn_data); | 3500 vms_truncate (fn_data); |
3504 desc = open (fn_data, O_RDWR, 0); | 3501 desc = open (fn_data, O_RDWR, 0); |
3505 if (desc < 0) | 3502 if (desc < 0) |
3506 desc = creat_copy_attrs ((STRINGP (current_buffer->filename) | 3503 desc = creat_copy_attrs ((STRINGP (current_buffer->filename) |
3507 ? (char *) string_data | 3504 ? (char *) |
3508 (XSTRING (current_buffer->filename)) | 3505 XSTRING_DATA (current_buffer->filename) |
3509 : 0), | 3506 : 0), |
3510 fn_data); | 3507 fn_data); |
3511 } | 3508 } |
3512 else /* Write to temporary name and rename if no errors */ | 3509 else /* Write to temporary name and rename if no errors */ |
3513 { | 3510 { |
3521 GCPRO3 (fn, fname, annotations); | 3518 GCPRO3 (fn, fname, annotations); |
3522 | 3519 |
3523 temp_name = Ffile_name_directory (filename); | 3520 temp_name = Ffile_name_directory (filename); |
3524 | 3521 |
3525 if (NILP (temp_name)) | 3522 if (NILP (temp_name)) |
3526 desc = creat ((char *) string_data (XSTRING (fn)), 0666); | 3523 desc = creat ((char *) XSTRING_DATA (fn), 0666); |
3527 else | 3524 else |
3528 { | 3525 { |
3529 temp_name = | 3526 temp_name = |
3530 Fmake_temp_name (concat2 (temp_name, | 3527 Fmake_temp_name (concat2 (temp_name, |
3531 build_string ("$$SAVE$$"))); | 3528 build_string ("$$SAVE$$"))); |
3532 fname = filename; | 3529 fname = filename; |
3533 fn = temp_name; | 3530 fn = temp_name; |
3534 desc = creat_copy_attrs (fname, | 3531 desc = creat_copy_attrs (fname, |
3535 (char *) string_data (XSTRING (fn))); | 3532 (char *) XSTRING_DATA (fn)); |
3536 if (desc < 0) | 3533 if (desc < 0) |
3537 { | 3534 { |
3538 char *fn_data; | 3535 char *fn_data; |
3539 /* If we can't open the temporary file, try creating a new | 3536 /* If we can't open the temporary file, try creating a new |
3540 version of the original file. VMS "creat" creates a | 3537 version of the original file. VMS "creat" creates a |
3541 new version rather than truncating an existing file. */ | 3538 new version rather than truncating an existing file. */ |
3542 fn = fname; | 3539 fn = fname; |
3543 fname = Qnil; | 3540 fname = Qnil; |
3544 fn_data = string_data (XSTRING (fn)); | 3541 fn_data = XSTRING_DATA (fn); |
3545 desc = creat (fn_data, 0666); | 3542 desc = creat (fn_data, 0666); |
3546 #if 0 /* This can clobber an existing file and fail | 3543 #if 0 /* This can clobber an existing file and fail |
3547 to replace it, if the user runs out of | 3544 to replace it, if the user runs out of |
3548 space. */ | 3545 space. */ |
3549 if (desc < 0) | 3546 if (desc < 0) |
3700 /* If we wrote to a temporary name and had no errors, rename to real name. */ | 3697 /* If we wrote to a temporary name and had no errors, rename to real name. */ |
3701 if (!NILP (fname)) | 3698 if (!NILP (fname)) |
3702 { | 3699 { |
3703 if (!failure) | 3700 if (!failure) |
3704 { | 3701 { |
3705 failure = (rename ((char *) string_data (XSTRING (fn)), | 3702 failure = (rename ((char *) XSTRING_DATA (fn), |
3706 (char *) string_data (XSTRING (fname))) | 3703 (char *) XSTRING_DATA (fname)) |
3707 != 0); | 3704 != 0); |
3708 save_errno = errno; | 3705 save_errno = errno; |
3709 } | 3706 } |
3710 fn = fname; | 3707 fn = fname; |
3711 } | 3708 } |
3712 #endif /* VMS */ | 3709 #endif /* VMS */ |
3713 | 3710 |
3714 #if 1 /* defined (VMS) || defined (APOLLO) */ | 3711 #if 1 /* defined (VMS) || defined (APOLLO) */ |
3715 stat ((char *) string_data (XSTRING (fn)), &st); | 3712 stat ((char *) XSTRING_DATA (fn), &st); |
3716 #endif | 3713 #endif |
3717 | 3714 |
3718 #ifdef CLASH_DETECTION | 3715 #ifdef CLASH_DETECTION |
3719 if (!auto_saving) | 3716 if (!auto_saving) |
3720 unlock_file (lockname); | 3717 unlock_file (lockname); |
3726 if (visiting) | 3723 if (visiting) |
3727 current_buffer->modtime = st.st_mtime; | 3724 current_buffer->modtime = st.st_mtime; |
3728 | 3725 |
3729 if (failure) | 3726 if (failure) |
3730 error ("IO error writing %s: %s", | 3727 error ("IO error writing %s: %s", |
3731 string_data (XSTRING (fn)), | 3728 XSTRING_DATA (fn), |
3732 strerror (save_errno)); | 3729 strerror (save_errno)); |
3733 | 3730 |
3734 if (visiting) | 3731 if (visiting) |
3735 { | 3732 { |
3736 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer); | 3733 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer); |
3744 } | 3741 } |
3745 | 3742 |
3746 if (!auto_saving) | 3743 if (!auto_saving) |
3747 { | 3744 { |
3748 if (visiting_other) | 3745 if (visiting_other) |
3749 message ("Wrote %s", string_data (XSTRING (visit_file))); | 3746 message ("Wrote %s", XSTRING_DATA (visit_file)); |
3750 else | 3747 else |
3751 { | 3748 { |
3752 struct gcpro gcpro1; | 3749 struct gcpro gcpro1; |
3753 Lisp_Object fsp; | 3750 Lisp_Object fsp; |
3754 GCPRO1 (fn); | 3751 GCPRO1 (fn); |
3755 | 3752 |
3756 fsp = Ffile_symlink_p (fn); | 3753 fsp = Ffile_symlink_p (fn); |
3757 if (NILP (fsp)) | 3754 if (NILP (fsp)) |
3758 message ("Wrote %s", string_data (XSTRING (fn))); | 3755 message ("Wrote %s", XSTRING_DATA (fn)); |
3759 else | 3756 else |
3760 message ("Wrote %s (symlink to %s)", | 3757 message ("Wrote %s (symlink to %s)", |
3761 string_data (XSTRING (fn)), string_data (XSTRING (fsp))); | 3758 XSTRING_DATA (fn), XSTRING_DATA (fsp)); |
3762 UNGCPRO; | 3759 UNGCPRO; |
3763 } | 3760 } |
3764 } | 3761 } |
3765 return Qnil; | 3762 return Qnil; |
3766 } | 3763 } |
3903 if (pos == nextpos) | 3900 if (pos == nextpos) |
3904 { | 3901 { |
3905 tem = Fcdr (Fcar (*annot)); | 3902 tem = Fcdr (Fcar (*annot)); |
3906 if (STRINGP (tem)) | 3903 if (STRINGP (tem)) |
3907 { | 3904 { |
3908 if (Lstream_write (outstr, string_data (XSTRING (tem)), | 3905 if (Lstream_write (outstr, XSTRING_DATA (tem), |
3909 string_length (XSTRING (tem))) < 0) | 3906 XSTRING_LENGTH (tem)) < 0) |
3910 return -1; | 3907 return -1; |
3911 } | 3908 } |
3912 *annot = Fcdr (*annot); | 3909 *annot = Fcdr (*annot); |
3913 } | 3910 } |
3914 else | 3911 else |
3936 | 3933 |
3937 /* !!#### May produce bogus data under Mule. */ | 3934 /* !!#### May produce bogus data under Mule. */ |
3938 CHECK_STRING (string); | 3935 CHECK_STRING (string); |
3939 CHECK_STRING (key); | 3936 CHECK_STRING (key); |
3940 | 3937 |
3941 extra = string_length (XSTRING (string)) % CRYPT_BLOCK_SIZE; | 3938 extra = XSTRING_LENGTH (string) % CRYPT_BLOCK_SIZE; |
3942 rounded_size = string_length (XSTRING (string)) + extra; | 3939 rounded_size = XSTRING_LENGTH (string) + extra; |
3943 encrypted_string = alloca (rounded_size + 1); | 3940 encrypted_string = alloca (rounded_size + 1); |
3944 memcpy (encrypted_string, string_data (XSTRING (string)), string_length (XSTRING (string))); | 3941 memcpy (encrypted_string, XSTRING_DATA (string), XSTRING_LENGTH (string)); |
3945 memset (encrypted_string + rounded_size - extra, 0, extra + 1); | 3942 memset (encrypted_string + rounded_size - extra, 0, extra + 1); |
3946 | 3943 |
3947 if (string_length (XSTRING (key)) > CRYPT_KEY_SIZE) | 3944 if (XSTRING_LENGTH (key) > CRYPT_KEY_SIZE) |
3948 key_size = CRYPT_KEY_SIZE; | 3945 key_size = CRYPT_KEY_SIZE; |
3949 else | 3946 else |
3950 key_size = string_length (XSTRING (key)); | 3947 key_size = XSTRING_LENGTH (key); |
3951 | 3948 |
3952 raw_key = alloca (CRYPT_KEY_SIZE + 1); | 3949 raw_key = alloca (CRYPT_KEY_SIZE + 1); |
3953 memcpy (raw_key, string_data (XSTRING (key)), key_size); | 3950 memcpy (raw_key, XSTRING_DATA (key), key_size); |
3954 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size); | 3951 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size); |
3955 | 3952 |
3956 (void) ecb_crypt (raw_key, encrypted_string, rounded_size, | 3953 (void) ecb_crypt (raw_key, encrypted_string, rounded_size, |
3957 DES_ENCRYPT | DES_SW); | 3954 DES_ENCRYPT | DES_SW); |
3958 return make_string (encrypted_string, rounded_size); | 3955 return make_string (encrypted_string, rounded_size); |
3968 int string_size, key_size; | 3965 int string_size, key_size; |
3969 | 3966 |
3970 CHECK_STRING (string); | 3967 CHECK_STRING (string); |
3971 CHECK_STRING (key); | 3968 CHECK_STRING (key); |
3972 | 3969 |
3973 string_size = string_length (XSTRING (string)) + 1; | 3970 string_size = XSTRING_LENGTH (string) + 1; |
3974 decrypted_string = alloca (string_size); | 3971 decrypted_string = alloca (string_size); |
3975 memcpy (decrypted_string, string_data (XSTRING (string)), string_size); | 3972 memcpy (decrypted_string, XSTRING_DATA (string), string_size); |
3976 decrypted_string[string_size - 1] = '\0'; | 3973 decrypted_string[string_size - 1] = '\0'; |
3977 | 3974 |
3978 if (string_length (XSTRING (key)) > CRYPT_KEY_SIZE) | 3975 if (XSTRING_LENGTH (key) > CRYPT_KEY_SIZE) |
3979 key_size = CRYPT_KEY_SIZE; | 3976 key_size = CRYPT_KEY_SIZE; |
3980 else | 3977 else |
3981 key_size = string_length (XSTRING (key)); | 3978 key_size = XSTRING_LENGTH (key); |
3982 | 3979 |
3983 raw_key = alloca (CRYPT_KEY_SIZE + 1); | 3980 raw_key = alloca (CRYPT_KEY_SIZE + 1); |
3984 memcpy (raw_key, string_data (XSTRING (key)), key_size); | 3981 memcpy (raw_key, XSTRING_DATA (key), key_size); |
3985 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size); | 3982 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size); |
3986 | 3983 |
3987 | 3984 |
3988 (void) ecb_crypt (raw_key, decrypted_string, string_size, | 3985 (void) ecb_crypt (raw_key, decrypted_string, string_size, |
3989 DES_DECRYPT | DES_SW); | 3986 DES_DECRYPT | DES_SW); |
4016 handler = Ffind_file_name_handler (b->filename, | 4013 handler = Ffind_file_name_handler (b->filename, |
4017 Qverify_visited_file_modtime); | 4014 Qverify_visited_file_modtime); |
4018 if (!NILP (handler)) | 4015 if (!NILP (handler)) |
4019 return call2 (handler, Qverify_visited_file_modtime, buf); | 4016 return call2 (handler, Qverify_visited_file_modtime, buf); |
4020 | 4017 |
4021 if (stat ((char *) string_data (XSTRING (b->filename)), &st) < 0) | 4018 if (stat ((char *) XSTRING_DATA (b->filename), &st) < 0) |
4022 { | 4019 { |
4023 /* If the file doesn't exist now and didn't exist before, | 4020 /* If the file doesn't exist now and didn't exist before, |
4024 we say that it isn't modified, provided the error is a tame one. */ | 4021 we say that it isn't modified, provided the error is a tame one. */ |
4025 if (errno == ENOENT || errno == EACCES || errno == ENOTDIR) | 4022 if (errno == ENOENT || errno == EACCES || errno == ENOTDIR) |
4026 st.st_mtime = -1; | 4023 st.st_mtime = -1; |
4093 handler = Ffind_file_name_handler (filename, Qset_visited_file_modtime); | 4090 handler = Ffind_file_name_handler (filename, Qset_visited_file_modtime); |
4094 UNGCPRO; | 4091 UNGCPRO; |
4095 if (!NILP (handler)) | 4092 if (!NILP (handler)) |
4096 /* The handler can find the file name the same way we did. */ | 4093 /* The handler can find the file name the same way we did. */ |
4097 return call2 (handler, Qset_visited_file_modtime, Qnil); | 4094 return call2 (handler, Qset_visited_file_modtime, Qnil); |
4098 else if (stat ((char *) string_data (XSTRING (filename)), &st) >= 0) | 4095 else if (stat ((char *) XSTRING_DATA (filename), &st) >= 0) |
4099 current_buffer->modtime = st.st_mtime; | 4096 current_buffer->modtime = st.st_mtime; |
4100 } | 4097 } |
4101 | 4098 |
4102 return Qnil; | 4099 return Qnil; |
4103 } | 4100 } |
4163 if (!NILP (handler)) | 4160 if (!NILP (handler)) |
4164 /* The handler can find the file name the same way we did. */ | 4161 /* The handler can find the file name the same way we did. */ |
4165 return (call2 (handler, Qset_buffer_modtime, Qnil)); | 4162 return (call2 (handler, Qset_buffer_modtime, Qnil)); |
4166 else | 4163 else |
4167 { | 4164 { |
4168 if (stat ((char *) string_data (XSTRING (filename)), &st) >= 0) | 4165 if (stat ((char *) XSTRING_DATA (filename), &st) >= 0) |
4169 time_to_use = st.st_mtime; | 4166 time_to_use = st.st_mtime; |
4170 else | 4167 else |
4171 time_to_use = time ((time_t *) 0); | 4168 time_to_use = time ((time_t *) 0); |
4172 } | 4169 } |
4173 } | 4170 } |
4187 /* This function can GC */ | 4184 /* This function can GC */ |
4188 if (gc_in_progress) | 4185 if (gc_in_progress) |
4189 return Qnil; | 4186 return Qnil; |
4190 clear_echo_area (selected_frame (), Qauto_saving, 1); | 4187 clear_echo_area (selected_frame (), Qauto_saving, 1); |
4191 Fding (Qt, Qauto_save_error, Qnil); | 4188 Fding (Qt, Qauto_save_error, Qnil); |
4192 message ("Auto-saving...error for %s", | 4189 message ("Auto-saving...error for %s", XSTRING_DATA (current_buffer->name)); |
4193 string_data (XSTRING (current_buffer->name))); | |
4194 Fsleep_for (make_int (1)); | 4190 Fsleep_for (make_int (1)); |
4195 message ("Auto-saving...error!for %s", | 4191 message ("Auto-saving...error!for %s", XSTRING_DATA (current_buffer->name)); |
4196 string_data (XSTRING (current_buffer->name))); | |
4197 Fsleep_for (make_int (1)); | 4192 Fsleep_for (make_int (1)); |
4198 message ("Auto-saving...error for %s", | 4193 message ("Auto-saving...error for %s", XSTRING_DATA (current_buffer->name)); |
4199 string_data (XSTRING (current_buffer->name))); | |
4200 Fsleep_for (make_int (1)); | 4194 Fsleep_for (make_int (1)); |
4201 return Qnil; | 4195 return Qnil; |
4202 } | 4196 } |
4203 | 4197 |
4204 static Lisp_Object | 4198 static Lisp_Object |
4212 if (!STRINGP (a)) | 4206 if (!STRINGP (a)) |
4213 return (Qnil); | 4207 return (Qnil); |
4214 | 4208 |
4215 /* Get visited file's mode to become the auto save file's mode. */ | 4209 /* Get visited file's mode to become the auto save file's mode. */ |
4216 if (STRINGP (fn) && | 4210 if (STRINGP (fn) && |
4217 stat ((char *) string_data (XSTRING (fn)), &st) >= 0) | 4211 stat ((char *) XSTRING_DATA (fn), &st) >= 0) |
4218 /* But make sure we can overwrite it later! */ | 4212 /* But make sure we can overwrite it later! */ |
4219 auto_save_mode_bits = st.st_mode | 0600; | 4213 auto_save_mode_bits = st.st_mode | 0600; |
4220 else | 4214 else |
4221 /* default mode for auto-save files of buffers with no file is | 4215 /* default mode for auto-save files of buffers with no file is |
4222 readable by owner only. This may annoy some small number of | 4216 readable by owner only. This may annoy some small number of |
4359 Unless we're about to crash, in which case auto-save it | 4353 Unless we're about to crash, in which case auto-save it |
4360 anyway. | 4354 anyway. |
4361 */ | 4355 */ |
4362 message | 4356 message |
4363 ("Buffer %s has shrunk a lot; auto save turned off there", | 4357 ("Buffer %s has shrunk a lot; auto save turned off there", |
4364 string_data (XSTRING (b->name))); | 4358 XSTRING_DATA (b->name)); |
4365 /* Turn off auto-saving until there's a real save, | 4359 /* Turn off auto-saving until there's a real save, |
4366 and prevent any more warnings. */ | 4360 and prevent any more warnings. */ |
4367 b->save_length = make_int (-1); | 4361 b->save_length = make_int (-1); |
4368 if (!gc_in_progress) | 4362 if (!gc_in_progress) |
4369 Fsleep_for (make_int (1)); | 4363 Fsleep_for (make_int (1)); |
4383 We only do this now so that the file only exists | 4377 We only do this now so that the file only exists |
4384 if we actually auto-saved any files. */ | 4378 if we actually auto-saved any files. */ |
4385 if (!auto_saved && GC_STRINGP (listfile) && listdesc < 0) | 4379 if (!auto_saved && GC_STRINGP (listfile) && listdesc < 0) |
4386 { | 4380 { |
4387 #ifdef DOS_NT | 4381 #ifdef DOS_NT |
4388 listdesc = open ((char *) | 4382 listdesc = open ((char *) XSTRING_DATA (listfile), |
4389 string_data (XSTRING (listfile)), | |
4390 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT, | 4383 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT, |
4391 S_IREAD | S_IWRITE); | 4384 S_IREAD | S_IWRITE); |
4392 #else /* not DOS_NT */ | 4385 #else /* not DOS_NT */ |
4393 listdesc = creat ((char *) | 4386 listdesc = creat ((char *) XSTRING_DATA (listfile), 0666); |
4394 string_data (XSTRING (listfile)), | |
4395 0666); | |
4396 #endif /* not DOS_NT */ | 4387 #endif /* not DOS_NT */ |
4397 | 4388 |
4398 /* Arrange to close that file whether or not we get | 4389 /* Arrange to close that file whether or not we get |
4399 an error. */ | 4390 an error. */ |
4400 if (listdesc >= 0) | 4391 if (listdesc >= 0) |
4455 /* If we didn't save anything into the listfile, remove the old | 4446 /* If we didn't save anything into the listfile, remove the old |
4456 one because nothing needed to be auto-saved. Do this afterwards | 4447 one because nothing needed to be auto-saved. Do this afterwards |
4457 rather than before in case we get a crash attempting to autosave | 4448 rather than before in case we get a crash attempting to autosave |
4458 (in that case we'd still want the old one around). */ | 4449 (in that case we'd still want the old one around). */ |
4459 if (listdesc < 0 && !auto_saved && GC_STRINGP (listfile)) | 4450 if (listdesc < 0 && !auto_saved && GC_STRINGP (listfile)) |
4460 unlink ((char *) string_data (XSTRING (listfile))); | 4451 unlink ((char *) XSTRING_DATA (listfile)); |
4461 | 4452 |
4462 /* Show "...done" only if the echo area would otherwise be empty. */ | 4453 /* Show "...done" only if the echo area would otherwise be empty. */ |
4463 if (auto_saved && NILP (no_message) | 4454 if (auto_saved && NILP (no_message) |
4464 && NILP (clear_echo_area (selected_frame (), Qauto_saving, 0))) | 4455 && NILP (clear_echo_area (selected_frame (), Qauto_saving, 0))) |
4465 { | 4456 { |