Mercurial > hg > xemacs-beta
comparison src/fileio.c @ 563:183866b06e0b
[xemacs-hg @ 2001-05-24 07:50:48 by ben]
Makefile.in.in, abbrev.c, alloc.c, buffer.c, bytecode.c, callint.c, callproc.c, casetab.c, chartab.c, cmdloop.c, cmds.c, console-msw.c, console-msw.h, console-stream.c, console-tty.c, console-x.c, console.c, data.c, database.c, debug.c, device-gtk.c, device-msw.c, device-tty.c, device-x.c, device.c, dialog-gtk.c, dialog-msw.c, dialog-x.c, dialog.c, dired-msw.c, dired.c, doc.c, doprnt.c, dragdrop.c, editfns.c, eldap.c, eldap.h, elhash.c, emacs-widget-accessors.c, emacs.c, emodules.c, esd.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, extents.c, faces.c, file-coding.c, fileio.c, filelock.c, floatfns.c, fns.c, font-lock.c, frame-gtk.c, frame-x.c, frame.c, general-slots.h, glade.c, glyphs-gtk.c, glyphs-msw.c, glyphs-widget.c, glyphs-x.c, glyphs.c, glyphs.h, gpmevent.c, gui-gtk.c, gui-x.c, gui.c, gutter.c, hpplay.c, indent.c, input-method-xlib.c, insdel.c, intl.c, keymap.c, libsst.c, libsst.h, linuxplay.c, lisp.h, lread.c, lstream.c, lstream.h, macros.c, marker.c, md5.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, miscplay.c, miscplay.h, mule-ccl.c, mule-charset.c, mule-wnnfns.c, mule.c, nas.c, ntplay.c, ntproc.c, objects-gtk.c, objects-msw.c, objects-x.c, objects.c, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, ralloc.c, rangetab.c, redisplay.c, scrollbar.c, search.c, select-gtk.c, select-x.c, select.c, sgiplay.c, sheap.c, sound.c, specifier.c, sunplay.c, symbols.c, symeval.h, symsinit.h, syntax.c, sysdep.c, toolbar-msw.c, toolbar.c, tooltalk.c, ui-byhand.c, ui-gtk.c, undo.c, unexaix.c, unexapollo.c, unexconvex.c, unexec.c, widget.c, win32.c, window.c:
-- defsymbol -> DEFSYMBOL.
-- add an error type to all errors.
-- eliminate the error functions in eval.c that let you just
use Qerror as the type.
-- redo the error API to be more consistent, sensibly named,
and easier to use.
-- redo the error hierarchy somewhat. create new errors:
structure-formation-error, gui-error, invalid-constant,
stack-overflow, out-of-memory, process-error, network-error,
sound-error, printing-unreadable-object, base64-conversion-
error; coding-system-error renamed to text-conversion error;
some others.
-- fix Mule problems in error strings in emodules.c, tooltalk.c.
-- fix error handling in mswin open-network-stream.
-- Mule-ize all sound files and clean up the headers.
-- nativesound.h -> sound.h and used for all sound files.
-- move some shared stuff into glyphs-shared.c: first attempt
at eliminating some of the massive GTK code duplication.
xemacs.mak: add glyphs-shared.c.
xemacs-faq.texi: document how to debug X errors
subr.el: fix doc string to reflect reality
author | ben |
---|---|
date | Thu, 24 May 2001 07:51:33 +0000 |
parents | ed498ef2108b |
children | 4f6ba8f1fb3d |
comparison
equal
deleted
inserted
replaced
562:c775bd016b32 | 563:183866b06e0b |
---|---|
1 /* File IO for XEmacs. | 1 /* File IO for XEmacs. |
2 Copyright (C) 1985-1988, 1992-1995 Free Software Foundation, Inc. | 2 Copyright (C) 1985-1988, 1992-1995 Free Software Foundation, Inc. |
3 Copyright (C) 1996 Ben Wing. | 3 Copyright (C) 1996, 2001 Ben Wing. |
4 | 4 |
5 This file is part of XEmacs. | 5 This file is part of XEmacs. |
6 | 6 |
7 XEmacs is free software; you can redistribute it and/or modify it | 7 XEmacs is free software; you can redistribute it and/or modify it |
8 under the terms of the GNU General Public License as published by the | 8 under the terms of the GNU General Public License as published by the |
112 If we try to handle that operation, we ignore those handlers. */ | 112 If we try to handle that operation, we ignore those handlers. */ |
113 | 113 |
114 static Lisp_Object Vinhibit_file_name_handlers; | 114 static Lisp_Object Vinhibit_file_name_handlers; |
115 static Lisp_Object Vinhibit_file_name_operation; | 115 static Lisp_Object Vinhibit_file_name_operation; |
116 | 116 |
117 Lisp_Object Qfile_error, Qfile_already_exists; | 117 Lisp_Object Qfile_already_exists; |
118 | 118 |
119 Lisp_Object Qauto_save_hook; | 119 Lisp_Object Qauto_save_hook; |
120 Lisp_Object Qauto_save_error; | 120 Lisp_Object Qauto_save_error; |
121 Lisp_Object Qauto_saving; | 121 Lisp_Object Qauto_saving; |
122 | 122 |
124 | 124 |
125 Lisp_Object Qcompute_buffer_file_truename; | 125 Lisp_Object Qcompute_buffer_file_truename; |
126 | 126 |
127 EXFUN (Frunning_temacs_p, 0); | 127 EXFUN (Frunning_temacs_p, 0); |
128 | 128 |
129 /* DATA can be anything acceptable to signal_error (). | |
130 */ | |
131 | |
132 DOESNT_RETURN | |
133 report_file_type_error (Lisp_Object errtype, Lisp_Object oserrmess, | |
134 const char *string, Lisp_Object data) | |
135 { | |
136 struct gcpro gcpro1; | |
137 Lisp_Object errdata = build_error_data (NULL, data); | |
138 | |
139 GCPRO1 (errdata); | |
140 errdata = Fcons (build_translated_string (string), | |
141 Fcons (oserrmess, errdata)); | |
142 signal_error_1 (errtype, errdata); | |
143 UNGCPRO; /* not reached */ | |
144 } | |
145 | |
146 DOESNT_RETURN | |
147 report_error_with_errno (Lisp_Object errtype, | |
148 const char *string, Lisp_Object data) | |
149 { | |
150 report_file_type_error (errtype, lisp_strerror (errno), string, data); | |
151 } | |
152 | |
129 /* signal a file error when errno contains a meaningful value. */ | 153 /* signal a file error when errno contains a meaningful value. */ |
130 | 154 |
131 DOESNT_RETURN | 155 DOESNT_RETURN |
132 report_file_error (const char *string, Lisp_Object data) | 156 report_file_error (const char *string, Lisp_Object data) |
133 { | 157 { |
134 /* #### dmoore - This uses current_buffer, better make sure no one | 158 report_error_with_errno (Qfile_error, string, data); |
135 has GC'd the current buffer. File handlers are giving me a headache | |
136 maybe I'll just always protect current_buffer around all of those | |
137 calls. */ | |
138 | |
139 signal_error (Qfile_error, | |
140 Fcons (build_translated_string (string), | |
141 Fcons (lisp_strerror (errno), data))); | |
142 } | |
143 | |
144 void | |
145 maybe_report_file_error (const char *string, Lisp_Object data, | |
146 Lisp_Object class, Error_behavior errb) | |
147 { | |
148 /* Optimization: */ | |
149 if (ERRB_EQ (errb, ERROR_ME_NOT)) | |
150 return; | |
151 | |
152 maybe_signal_error (Qfile_error, | |
153 Fcons (build_translated_string (string), | |
154 Fcons (lisp_strerror (errno), data)), | |
155 class, errb); | |
156 } | |
157 | |
158 /* signal a file error when errno does not contain a meaningful value. */ | |
159 | |
160 DOESNT_RETURN | |
161 signal_file_error (const char *string, Lisp_Object data) | |
162 { | |
163 signal_error (Qfile_error, | |
164 list2 (build_translated_string (string), data)); | |
165 } | |
166 | |
167 void | |
168 maybe_signal_file_error (const char *string, Lisp_Object data, | |
169 Lisp_Object class, Error_behavior errb) | |
170 { | |
171 /* Optimization: */ | |
172 if (ERRB_EQ (errb, ERROR_ME_NOT)) | |
173 return; | |
174 maybe_signal_error (Qfile_error, | |
175 list2 (build_translated_string (string), data), | |
176 class, errb); | |
177 } | |
178 | |
179 DOESNT_RETURN | |
180 signal_double_file_error (const char *string1, const char *string2, | |
181 Lisp_Object data) | |
182 { | |
183 signal_error (Qfile_error, | |
184 list3 (build_translated_string (string1), | |
185 build_translated_string (string2), | |
186 data)); | |
187 } | |
188 | |
189 void | |
190 maybe_signal_double_file_error (const char *string1, const char *string2, | |
191 Lisp_Object data, Lisp_Object class, | |
192 Error_behavior errb) | |
193 { | |
194 /* Optimization: */ | |
195 if (ERRB_EQ (errb, ERROR_ME_NOT)) | |
196 return; | |
197 maybe_signal_error (Qfile_error, | |
198 list3 (build_translated_string (string1), | |
199 build_translated_string (string2), | |
200 data), | |
201 class, errb); | |
202 } | |
203 | |
204 DOESNT_RETURN | |
205 signal_double_file_error_2 (const char *string1, const char *string2, | |
206 Lisp_Object data1, Lisp_Object data2) | |
207 { | |
208 signal_error (Qfile_error, | |
209 list4 (build_translated_string (string1), | |
210 build_translated_string (string2), | |
211 data1, data2)); | |
212 } | |
213 | |
214 void | |
215 maybe_signal_double_file_error_2 (const char *string1, const char *string2, | |
216 Lisp_Object data1, Lisp_Object data2, | |
217 Lisp_Object class, Error_behavior errb) | |
218 { | |
219 /* Optimization: */ | |
220 if (ERRB_EQ (errb, ERROR_ME_NOT)) | |
221 return; | |
222 maybe_signal_error (Qfile_error, | |
223 list4 (build_translated_string (string1), | |
224 build_translated_string (string2), | |
225 data1, data2), | |
226 class, errb); | |
227 } | 159 } |
228 | 160 |
229 | 161 |
230 /* Just like strerror(3), except return a lisp string instead of char *. | 162 /* Just like strerror(3), except return a lisp string instead of char *. |
231 The string needs to be converted since it may be localized. | 163 The string needs to be converted since it may be localized. |
724 can do. The alternatives are to return nil, which is | 656 can do. The alternatives are to return nil, which is |
725 as bad as (and in many cases worse than) throwing the | 657 as bad as (and in many cases worse than) throwing the |
726 error, or to ignore the error, which will likely result | 658 error, or to ignore the error, which will likely result |
727 in inflooping. */ | 659 in inflooping. */ |
728 report_file_error ("Cannot create temporary name for prefix", | 660 report_file_error ("Cannot create temporary name for prefix", |
729 list1 (prefix)); | 661 prefix); |
730 return Qnil; /* not reached */ | 662 return Qnil; /* not reached */ |
731 } | 663 } |
732 } | 664 } |
733 } | 665 } |
734 | 666 |
1382 | 1314 |
1383 toolong: | 1315 toolong: |
1384 errno = ENAMETOOLONG; | 1316 errno = ENAMETOOLONG; |
1385 goto lose; | 1317 goto lose; |
1386 lose: | 1318 lose: |
1387 report_file_error ("Finding truename", list1 (expanded_name)); | 1319 report_file_error ("Finding truename", expanded_name); |
1388 } | 1320 } |
1389 RETURN_UNGCPRO (Qnil); | 1321 RETURN_UNGCPRO (Qnil); |
1390 } | 1322 } |
1391 | 1323 |
1392 | 1324 |
1745 else if (xemacs_stat ((const char *) XSTRING_DATA (newname), &out_st) < 0) | 1677 else if (xemacs_stat ((const char *) XSTRING_DATA (newname), &out_st) < 0) |
1746 out_st.st_mode = 0; | 1678 out_st.st_mode = 0; |
1747 | 1679 |
1748 ifd = interruptible_open ((char *) XSTRING_DATA (filename), O_RDONLY | OPEN_BINARY, 0); | 1680 ifd = interruptible_open ((char *) XSTRING_DATA (filename), O_RDONLY | OPEN_BINARY, 0); |
1749 if (ifd < 0) | 1681 if (ifd < 0) |
1750 report_file_error ("Opening input file", list1 (filename)); | 1682 report_file_error ("Opening input file", filename); |
1751 | 1683 |
1752 record_unwind_protect (close_file_unwind, make_int (ifd)); | 1684 record_unwind_protect (close_file_unwind, make_int (ifd)); |
1753 | 1685 |
1754 /* We can only copy regular files and symbolic links. Other files are not | 1686 /* We can only copy regular files and symbolic links. Other files are not |
1755 copyable by us. */ | 1687 copyable by us. */ |
1759 if (out_st.st_mode != 0 | 1691 if (out_st.st_mode != 0 |
1760 && st.st_dev == out_st.st_dev && st.st_ino == out_st.st_ino) | 1692 && st.st_dev == out_st.st_dev && st.st_ino == out_st.st_ino) |
1761 { | 1693 { |
1762 errno = 0; | 1694 errno = 0; |
1763 report_file_error ("Input and output files are the same", | 1695 report_file_error ("Input and output files are the same", |
1764 list2 (filename, newname)); | 1696 list3 (Qunbound, filename, newname)); |
1765 } | 1697 } |
1766 #endif | 1698 #endif |
1767 | 1699 |
1768 #if defined (S_ISREG) && defined (S_ISLNK) | 1700 #if defined (S_ISREG) && defined (S_ISLNK) |
1769 if (input_file_statable_p) | 1701 if (input_file_statable_p) |
1777 { | 1709 { |
1778 #if defined (EISDIR) | 1710 #if defined (EISDIR) |
1779 /* Get a better looking error message. */ | 1711 /* Get a better looking error message. */ |
1780 errno = EISDIR; | 1712 errno = EISDIR; |
1781 #endif /* EISDIR */ | 1713 #endif /* EISDIR */ |
1782 report_file_error ("Non-regular file", list1 (filename)); | 1714 report_file_error ("Non-regular file", filename); |
1783 } | 1715 } |
1784 } | 1716 } |
1785 #endif /* S_ISREG && S_ISLNK */ | 1717 #endif /* S_ISREG && S_ISLNK */ |
1786 | 1718 |
1787 ofd = open( (char *) XSTRING_DATA (newname), | 1719 ofd = open( (char *) XSTRING_DATA (newname), |
1788 O_WRONLY | O_CREAT | O_TRUNC | OPEN_BINARY, CREAT_MODE); | 1720 O_WRONLY | O_CREAT | O_TRUNC | OPEN_BINARY, CREAT_MODE); |
1789 if (ofd < 0) | 1721 if (ofd < 0) |
1790 report_file_error ("Opening output file", list1 (newname)); | 1722 report_file_error ("Opening output file", newname); |
1791 | 1723 |
1792 { | 1724 { |
1793 Lisp_Object ofd_locative = noseeum_cons (make_int (ofd), Qnil); | 1725 Lisp_Object ofd_locative = noseeum_cons (make_int (ofd), Qnil); |
1794 | 1726 |
1795 record_unwind_protect (close_file_unwind, ofd_locative); | 1727 record_unwind_protect (close_file_unwind, ofd_locative); |
1796 | 1728 |
1797 while ((n = read_allowing_quit (ifd, buf, sizeof (buf))) > 0) | 1729 while ((n = read_allowing_quit (ifd, buf, sizeof (buf))) > 0) |
1798 { | 1730 { |
1799 if (write_allowing_quit (ofd, buf, n) != n) | 1731 if (write_allowing_quit (ofd, buf, n) != n) |
1800 report_file_error ("I/O error", list1 (newname)); | 1732 report_file_error ("I/O error", newname); |
1801 } | 1733 } |
1802 | 1734 |
1803 /* Closing the output clobbers the file times on some systems. */ | 1735 /* Closing the output clobbers the file times on some systems. */ |
1804 if (close (ofd) < 0) | 1736 if (close (ofd) < 0) |
1805 report_file_error ("I/O error", list1 (newname)); | 1737 report_file_error ("I/O error", newname); |
1806 | 1738 |
1807 if (input_file_statable_p) | 1739 if (input_file_statable_p) |
1808 { | 1740 { |
1809 if (!NILP (keep_time)) | 1741 if (!NILP (keep_time)) |
1810 { | 1742 { |
1811 EMACS_TIME atime, mtime; | 1743 EMACS_TIME atime, mtime; |
1812 EMACS_SET_SECS_USECS (atime, st.st_atime, 0); | 1744 EMACS_SET_SECS_USECS (atime, st.st_atime, 0); |
1813 EMACS_SET_SECS_USECS (mtime, st.st_mtime, 0); | 1745 EMACS_SET_SECS_USECS (mtime, st.st_mtime, 0); |
1814 if (lisp_string_set_file_times (newname, atime, mtime)) | 1746 if (lisp_string_set_file_times (newname, atime, mtime)) |
1815 report_file_error ("I/O error", list1 (newname)); | 1747 report_file_error ("I/O error", newname); |
1816 } | 1748 } |
1817 chmod ((const char *) XSTRING_DATA (newname), | 1749 chmod ((const char *) XSTRING_DATA (newname), |
1818 st.st_mode & 07777); | 1750 st.st_mode & 07777); |
1819 } | 1751 } |
1820 | 1752 |
1860 | 1792 |
1861 if (dir [XSTRING_LENGTH (dirname_) - 1] == '/') | 1793 if (dir [XSTRING_LENGTH (dirname_) - 1] == '/') |
1862 dir [XSTRING_LENGTH (dirname_) - 1] = 0; | 1794 dir [XSTRING_LENGTH (dirname_) - 1] = 0; |
1863 | 1795 |
1864 if (mkdir (dir, 0777) != 0) | 1796 if (mkdir (dir, 0777) != 0) |
1865 report_file_error ("Creating directory", list1 (dirname_)); | 1797 report_file_error ("Creating directory", dirname_); |
1866 | 1798 |
1867 return Qnil; | 1799 return Qnil; |
1868 } | 1800 } |
1869 | 1801 |
1870 DEFUN ("delete-directory", Fdelete_directory, 1, 1, "FDelete directory: ", /* | 1802 DEFUN ("delete-directory", Fdelete_directory, 1, 1, "FDelete directory: ", /* |
1886 UNGCPRO; | 1818 UNGCPRO; |
1887 if (!NILP (handler)) | 1819 if (!NILP (handler)) |
1888 return (call2 (handler, Qdelete_directory, dirname_)); | 1820 return (call2 (handler, Qdelete_directory, dirname_)); |
1889 | 1821 |
1890 if (rmdir ((char *) XSTRING_DATA (dirname_)) != 0) | 1822 if (rmdir ((char *) XSTRING_DATA (dirname_)) != 0) |
1891 report_file_error ("Removing directory", list1 (dirname_)); | 1823 report_file_error ("Removing directory", dirname_); |
1892 | 1824 |
1893 return Qnil; | 1825 return Qnil; |
1894 } | 1826 } |
1895 | 1827 |
1896 DEFUN ("delete-file", Fdelete_file, 1, 1, "fDelete file: ", /* | 1828 DEFUN ("delete-file", Fdelete_file, 1, 1, "fDelete file: ", /* |
1911 UNGCPRO; | 1843 UNGCPRO; |
1912 if (!NILP (handler)) | 1844 if (!NILP (handler)) |
1913 return call2 (handler, Qdelete_file, filename); | 1845 return call2 (handler, Qdelete_file, filename); |
1914 | 1846 |
1915 if (0 > unlink ((char *) XSTRING_DATA (filename))) | 1847 if (0 > unlink ((char *) XSTRING_DATA (filename))) |
1916 report_file_error ("Removing old name", list1 (filename)); | 1848 report_file_error ("Removing old name", filename); |
1917 return Qnil; | 1849 return Qnil; |
1918 } | 1850 } |
1919 | 1851 |
1920 static Lisp_Object | 1852 static Lisp_Object |
1921 internal_delete_file_1 (Lisp_Object ignore, Lisp_Object ignore2) | 1853 internal_delete_file_1 (Lisp_Object ignore, Lisp_Object ignore2) |
2008 Qt); | 1940 Qt); |
2009 Fdelete_file (filename); | 1941 Fdelete_file (filename); |
2010 } | 1942 } |
2011 else | 1943 else |
2012 { | 1944 { |
2013 report_file_error ("Renaming", list2 (filename, newname)); | 1945 report_file_error ("Renaming", list3 (Qunbound, filename, newname)); |
2014 } | 1946 } |
2015 } | 1947 } |
2016 UNGCPRO; | 1948 UNGCPRO; |
2017 return Qnil; | 1949 return Qnil; |
2018 } | 1950 } |
2060 /* But FSF #defines link as sys_link which is supplied in nt.c. We can't do | 1992 /* But FSF #defines link as sys_link which is supplied in nt.c. We can't do |
2061 that because sysfile.h defines sys_link depending on ENCAPSULATE_LINK. | 1993 that because sysfile.h defines sys_link depending on ENCAPSULATE_LINK. |
2062 Reverted to previous behavior pending a working fix. (jhar) */ | 1994 Reverted to previous behavior pending a working fix. (jhar) */ |
2063 #if defined(WIN32_NATIVE) | 1995 #if defined(WIN32_NATIVE) |
2064 /* Windows does not support this operation. */ | 1996 /* Windows does not support this operation. */ |
2065 report_file_error ("Adding new name", Flist (2, &filename)); | 1997 signal_error_2 (Qunimplemented, "Adding new name", filename, newname); |
2066 #else /* not defined(WIN32_NATIVE) */ | 1998 #else /* not defined(WIN32_NATIVE) */ |
2067 | 1999 |
2068 unlink ((char *) XSTRING_DATA (newname)); | 2000 unlink ((char *) XSTRING_DATA (newname)); |
2069 if (0 > link ((char *) XSTRING_DATA (filename), | 2001 if (0 > link ((char *) XSTRING_DATA (filename), |
2070 (char *) XSTRING_DATA (newname))) | 2002 (char *) XSTRING_DATA (newname))) |
2071 { | 2003 { |
2072 report_file_error ("Adding new name", | 2004 report_file_error ("Adding new name", |
2073 list2 (filename, newname)); | 2005 list3 (Qunbound, filename, newname)); |
2074 } | 2006 } |
2075 #endif /* defined(WIN32_NATIVE) */ | 2007 #endif /* defined(WIN32_NATIVE) */ |
2076 | 2008 |
2077 UNGCPRO; | 2009 UNGCPRO; |
2078 return Qnil; | 2010 return Qnil; |
2126 unlink ((char *) XSTRING_DATA (linkname)); | 2058 unlink ((char *) XSTRING_DATA (linkname)); |
2127 if (0 > symlink ((char *) XSTRING_DATA (filename), | 2059 if (0 > symlink ((char *) XSTRING_DATA (filename), |
2128 (char *) XSTRING_DATA (linkname))) | 2060 (char *) XSTRING_DATA (linkname))) |
2129 { | 2061 { |
2130 report_file_error ("Making symbolic link", | 2062 report_file_error ("Making symbolic link", |
2131 list2 (filename, linkname)); | 2063 list3 (Qunbound, filename, linkname)); |
2132 } | 2064 } |
2133 #endif /* S_IFLNK */ | 2065 #endif /* S_IFLNK */ |
2134 | 2066 |
2135 UNGCPRO; | 2067 UNGCPRO; |
2136 return Qnil; | 2068 return Qnil; |
2567 UNGCPRO; | 2499 UNGCPRO; |
2568 if (!NILP (handler)) | 2500 if (!NILP (handler)) |
2569 return call3 (handler, Qset_file_modes, abspath, mode); | 2501 return call3 (handler, Qset_file_modes, abspath, mode); |
2570 | 2502 |
2571 if (chmod ((char *) XSTRING_DATA (abspath), XINT (mode)) < 0) | 2503 if (chmod ((char *) XSTRING_DATA (abspath), XINT (mode)) < 0) |
2572 report_file_error ("Doing chmod", list1 (abspath)); | 2504 report_file_error ("Doing chmod", abspath); |
2573 | 2505 |
2574 return Qnil; | 2506 return Qnil; |
2575 } | 2507 } |
2576 | 2508 |
2577 DEFUN ("set-default-file-modes", Fset_default_file_modes, 1, 1, 0, /* | 2509 DEFUN ("set-default-file-modes", Fset_default_file_modes, 1, 1, 0, /* |
2701 struct buffer *buf = current_buffer; | 2633 struct buffer *buf = current_buffer; |
2702 Lisp_Object curbuf; | 2634 Lisp_Object curbuf; |
2703 int not_regular = 0; | 2635 int not_regular = 0; |
2704 | 2636 |
2705 if (buf->base_buffer && ! NILP (visit)) | 2637 if (buf->base_buffer && ! NILP (visit)) |
2706 error ("Cannot do file visiting in an indirect buffer"); | 2638 invalid_operation ("Cannot do file visiting in an indirect buffer", Qunbound); |
2707 | 2639 |
2708 /* No need to call Fbarf_if_buffer_read_only() here. | 2640 /* No need to call Fbarf_if_buffer_read_only() here. |
2709 That's called in begin_multiple_change() or wherever. */ | 2641 That's called in begin_multiple_change() or wherever. */ |
2710 | 2642 |
2711 val = Qnil; | 2643 val = Qnil; |
2740 if (!NILP (used_codesys)) | 2672 if (!NILP (used_codesys)) |
2741 CHECK_SYMBOL (used_codesys); | 2673 CHECK_SYMBOL (used_codesys); |
2742 #endif | 2674 #endif |
2743 | 2675 |
2744 if ( (!NILP (start) || !NILP (end)) && !NILP (visit) ) | 2676 if ( (!NILP (start) || !NILP (end)) && !NILP (visit) ) |
2745 error ("Attempt to visit less than an entire file"); | 2677 invalid_operation ("Attempt to visit less than an entire file", Qunbound); |
2746 | 2678 |
2747 fd = -1; | 2679 fd = -1; |
2748 | 2680 |
2749 if (xemacs_stat ((char *) XSTRING_DATA (filename), &st) < 0) | 2681 if (xemacs_stat ((char *) XSTRING_DATA (filename), &st) < 0) |
2750 { | 2682 { |
2751 if (fd >= 0) close (fd); | 2683 if (fd >= 0) close (fd); |
2752 badopen: | 2684 badopen: |
2753 if (NILP (visit)) | 2685 if (NILP (visit)) |
2754 report_file_error ("Opening input file", list1 (filename)); | 2686 report_file_error ("Opening input file", filename); |
2755 st.st_mtime = -1; | 2687 st.st_mtime = -1; |
2756 goto notfound; | 2688 goto notfound; |
2757 } | 2689 } |
2758 | 2690 |
2759 #ifdef S_IFREG | 2691 #ifdef S_IFREG |
2799 | 2731 |
2800 record_unwind_protect (close_file_unwind, make_int (fd)); | 2732 record_unwind_protect (close_file_unwind, make_int (fd)); |
2801 | 2733 |
2802 /* Supposedly happens on VMS. */ | 2734 /* Supposedly happens on VMS. */ |
2803 if (st.st_size < 0) | 2735 if (st.st_size < 0) |
2804 error ("File size is negative"); | 2736 signal_error (Qfile_error, "File size is negative", Qunbound); |
2805 | 2737 |
2806 if (NILP (end)) | 2738 if (NILP (end)) |
2807 { | 2739 { |
2808 if (!not_regular) | 2740 if (!not_regular) |
2809 { | 2741 { |
2810 end = make_int (st.st_size); | 2742 end = make_int (st.st_size); |
2811 if (XINT (end) != st.st_size) | 2743 if (XINT (end) != st.st_size) |
2812 error ("Maximum buffer size exceeded"); | 2744 out_of_memory ("Maximum buffer size exceeded", Qunbound); |
2813 } | 2745 } |
2814 } | 2746 } |
2815 | 2747 |
2816 /* If requested, replace the accessible part of the buffer | 2748 /* If requested, replace the accessible part of the buffer |
2817 with the file contents. Avoid replacing text at the | 2749 with the file contents. Avoid replacing text at the |
2845 { | 2777 { |
2846 int nread; | 2778 int nread; |
2847 Bufpos bufpos; | 2779 Bufpos bufpos; |
2848 nread = read_allowing_quit (fd, buffer, sizeof buffer); | 2780 nread = read_allowing_quit (fd, buffer, sizeof buffer); |
2849 if (nread < 0) | 2781 if (nread < 0) |
2850 error ("IO error reading %s: %s", | 2782 report_file_error ("Reading", filename); |
2851 XSTRING_DATA (filename), strerror (errno)); | |
2852 else if (nread == 0) | 2783 else if (nread == 0) |
2853 break; | 2784 break; |
2854 bufpos = 0; | 2785 bufpos = 0; |
2855 while (bufpos < nread && same_at_start < BUF_ZV (buf) | 2786 while (bufpos < nread && same_at_start < BUF_ZV (buf) |
2856 && BUF_FETCH_CHAR (buf, same_at_start) == buffer[bufpos]) | 2787 && BUF_FETCH_CHAR (buf, same_at_start) == buffer[bufpos]) |
2884 if (curpos == 0) | 2815 if (curpos == 0) |
2885 break; | 2816 break; |
2886 /* How much can we scan in the next step? */ | 2817 /* How much can we scan in the next step? */ |
2887 trial = min (curpos, (Bufpos) sizeof (buffer)); | 2818 trial = min (curpos, (Bufpos) sizeof (buffer)); |
2888 if (lseek (fd, curpos - trial, 0) < 0) | 2819 if (lseek (fd, curpos - trial, 0) < 0) |
2889 report_file_error ("Setting file position", list1 (filename)); | 2820 report_file_error ("Setting file position", filename); |
2890 | 2821 |
2891 total_read = 0; | 2822 total_read = 0; |
2892 while (total_read < trial) | 2823 while (total_read < trial) |
2893 { | 2824 { |
2894 nread = read_allowing_quit (fd, buffer + total_read, | 2825 nread = read_allowing_quit (fd, buffer + total_read, |
2895 trial - total_read); | 2826 trial - total_read); |
2896 if (nread <= 0) | 2827 if (nread <= 0) |
2897 report_file_error ("IO error reading file", list1 (filename)); | 2828 report_file_error ("IO error reading file", filename); |
2898 total_read += nread; | 2829 total_read += nread; |
2899 } | 2830 } |
2900 /* Scan this bufferful from the end, comparing with | 2831 /* Scan this bufferful from the end, comparing with |
2901 the Emacs buffer. */ | 2832 the Emacs buffer. */ |
2902 bufpos = total_read; | 2833 bufpos = total_read; |
2938 { | 2869 { |
2939 total = XINT (end) - XINT (start); | 2870 total = XINT (end) - XINT (start); |
2940 | 2871 |
2941 /* Make sure point-max won't overflow after this insertion. */ | 2872 /* Make sure point-max won't overflow after this insertion. */ |
2942 if (total != XINT (make_int (total))) | 2873 if (total != XINT (make_int (total))) |
2943 error ("Maximum buffer size exceeded"); | 2874 out_of_memory ("Maximum buffer size exceeded", Qunbound); |
2944 } | 2875 } |
2945 else | 2876 else |
2946 /* For a special file, all we can do is guess. The value of -1 | 2877 /* For a special file, all we can do is guess. The value of -1 |
2947 will make the stream functions read as much as possible. */ | 2878 will make the stream functions read as much as possible. */ |
2948 total = -1; | 2879 total = -1; |
2955 || !NILP (replace) | 2886 || !NILP (replace) |
2956 #endif /* !FSFMACS_SPEEDY_INSERT */ | 2887 #endif /* !FSFMACS_SPEEDY_INSERT */ |
2957 ) | 2888 ) |
2958 { | 2889 { |
2959 if (lseek (fd, XINT (start), 0) < 0) | 2890 if (lseek (fd, XINT (start), 0) < 0) |
2960 report_file_error ("Setting file position", list1 (filename)); | 2891 report_file_error ("Setting file position", filename); |
2961 } | 2892 } |
2962 | 2893 |
2963 { | 2894 { |
2964 Bufpos cur_point = BUF_PT (buf); | 2895 Bufpos cur_point = BUF_PT (buf); |
2965 struct gcpro ngcpro1; | 2896 struct gcpro ngcpro1; |
3016 /* Close the file/stream */ | 2947 /* Close the file/stream */ |
3017 unbind_to (speccount, Qnil); | 2948 unbind_to (speccount, Qnil); |
3018 | 2949 |
3019 if (saverrno != 0) | 2950 if (saverrno != 0) |
3020 { | 2951 { |
3021 error ("IO error reading %s: %s", | 2952 errno = saverrno; |
3022 XSTRING_DATA (filename), strerror (saverrno)); | 2953 report_file_error ("Reading", filename); |
3023 } | 2954 } |
3024 | 2955 |
3025 notfound: | 2956 notfound: |
3026 handled: | 2957 handled: |
3027 | 2958 |
3063 filename))); | 2994 filename))); |
3064 | 2995 |
3065 /* If visiting nonexistent file, return nil. */ | 2996 /* If visiting nonexistent file, return nil. */ |
3066 if (buf->modtime == -1) | 2997 if (buf->modtime == -1) |
3067 report_file_error ("Opening input file", | 2998 report_file_error ("Opening input file", |
3068 list1 (filename)); | 2999 filename); |
3069 } | 3000 } |
3070 | 3001 |
3071 /* Decode file format */ | 3002 /* Decode file format */ |
3072 if (inserted > 0) | 3003 if (inserted > 0) |
3073 { | 3004 { |
3258 #ifdef CLASH_DETECTION | 3189 #ifdef CLASH_DETECTION |
3259 save_errno = errno; | 3190 save_errno = errno; |
3260 if (!auto_saving) unlock_file (lockname); | 3191 if (!auto_saving) unlock_file (lockname); |
3261 errno = save_errno; | 3192 errno = save_errno; |
3262 #endif /* CLASH_DETECTION */ | 3193 #endif /* CLASH_DETECTION */ |
3263 report_file_error ("Opening output file", list1 (filename)); | 3194 report_file_error ("Opening output file", filename); |
3264 } | 3195 } |
3265 | 3196 |
3266 { | 3197 { |
3267 Lisp_Object desc_locative = Fcons (make_int (desc), Qnil); | 3198 Lisp_Object desc_locative = Fcons (make_int (desc), Qnil); |
3268 Lisp_Object instream = Qnil, outstream = Qnil; | 3199 Lisp_Object instream = Qnil, outstream = Qnil; |
3278 { | 3209 { |
3279 #ifdef CLASH_DETECTION | 3210 #ifdef CLASH_DETECTION |
3280 if (!auto_saving) unlock_file (lockname); | 3211 if (!auto_saving) unlock_file (lockname); |
3281 #endif /* CLASH_DETECTION */ | 3212 #endif /* CLASH_DETECTION */ |
3282 report_file_error ("Lseek error", | 3213 report_file_error ("Lseek error", |
3283 list1 (filename)); | 3214 filename); |
3284 } | 3215 } |
3285 } | 3216 } |
3286 | 3217 |
3287 failure = 0; | 3218 failure = 0; |
3288 | 3219 |
3377 current_buffer->modtime = st.st_mtime; | 3308 current_buffer->modtime = st.st_mtime; |
3378 | 3309 |
3379 if (failure) | 3310 if (failure) |
3380 { | 3311 { |
3381 errno = save_errno; | 3312 errno = save_errno; |
3382 report_file_error ("Writing file", list1 (fn)); | 3313 report_file_error ("Writing file", fn); |
3383 } | 3314 } |
3384 | 3315 |
3385 if (visiting) | 3316 if (visiting) |
3386 { | 3317 { |
3387 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer); | 3318 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer); |
4144 /************************************************************************/ | 4075 /************************************************************************/ |
4145 | 4076 |
4146 void | 4077 void |
4147 syms_of_fileio (void) | 4078 syms_of_fileio (void) |
4148 { | 4079 { |
4149 defsymbol (&Qexpand_file_name, "expand-file-name"); | 4080 DEFSYMBOL (Qexpand_file_name); |
4150 defsymbol (&Qfile_truename, "file-truename"); | 4081 DEFSYMBOL (Qfile_truename); |
4151 defsymbol (&Qsubstitute_in_file_name, "substitute-in-file-name"); | 4082 DEFSYMBOL (Qsubstitute_in_file_name); |
4152 defsymbol (&Qdirectory_file_name, "directory-file-name"); | 4083 DEFSYMBOL (Qdirectory_file_name); |
4153 defsymbol (&Qfile_name_directory, "file-name-directory"); | 4084 DEFSYMBOL (Qfile_name_directory); |
4154 defsymbol (&Qfile_name_nondirectory, "file-name-nondirectory"); | 4085 DEFSYMBOL (Qfile_name_nondirectory); |
4155 defsymbol (&Qunhandled_file_name_directory, "unhandled-file-name-directory"); | 4086 DEFSYMBOL (Qunhandled_file_name_directory); |
4156 defsymbol (&Qfile_name_as_directory, "file-name-as-directory"); | 4087 DEFSYMBOL (Qfile_name_as_directory); |
4157 defsymbol (&Qcopy_file, "copy-file"); | 4088 DEFSYMBOL (Qcopy_file); |
4158 defsymbol (&Qmake_directory_internal, "make-directory-internal"); | 4089 DEFSYMBOL (Qmake_directory_internal); |
4159 defsymbol (&Qdelete_directory, "delete-directory"); | 4090 DEFSYMBOL (Qdelete_directory); |
4160 defsymbol (&Qdelete_file, "delete-file"); | 4091 DEFSYMBOL (Qdelete_file); |
4161 defsymbol (&Qrename_file, "rename-file"); | 4092 DEFSYMBOL (Qrename_file); |
4162 defsymbol (&Qadd_name_to_file, "add-name-to-file"); | 4093 DEFSYMBOL (Qadd_name_to_file); |
4163 defsymbol (&Qmake_symbolic_link, "make-symbolic-link"); | 4094 DEFSYMBOL (Qmake_symbolic_link); |
4164 defsymbol (&Qfile_exists_p, "file-exists-p"); | 4095 DEFSYMBOL (Qfile_exists_p); |
4165 defsymbol (&Qfile_executable_p, "file-executable-p"); | 4096 DEFSYMBOL (Qfile_executable_p); |
4166 defsymbol (&Qfile_readable_p, "file-readable-p"); | 4097 DEFSYMBOL (Qfile_readable_p); |
4167 defsymbol (&Qfile_symlink_p, "file-symlink-p"); | 4098 DEFSYMBOL (Qfile_symlink_p); |
4168 defsymbol (&Qfile_writable_p, "file-writable-p"); | 4099 DEFSYMBOL (Qfile_writable_p); |
4169 defsymbol (&Qfile_directory_p, "file-directory-p"); | 4100 DEFSYMBOL (Qfile_directory_p); |
4170 defsymbol (&Qfile_regular_p, "file-regular-p"); | 4101 DEFSYMBOL (Qfile_regular_p); |
4171 defsymbol (&Qfile_accessible_directory_p, "file-accessible-directory-p"); | 4102 DEFSYMBOL (Qfile_accessible_directory_p); |
4172 defsymbol (&Qfile_modes, "file-modes"); | 4103 DEFSYMBOL (Qfile_modes); |
4173 defsymbol (&Qset_file_modes, "set-file-modes"); | 4104 DEFSYMBOL (Qset_file_modes); |
4174 defsymbol (&Qfile_newer_than_file_p, "file-newer-than-file-p"); | 4105 DEFSYMBOL (Qfile_newer_than_file_p); |
4175 defsymbol (&Qinsert_file_contents, "insert-file-contents"); | 4106 DEFSYMBOL (Qinsert_file_contents); |
4176 defsymbol (&Qwrite_region, "write-region"); | 4107 DEFSYMBOL (Qwrite_region); |
4177 defsymbol (&Qverify_visited_file_modtime, "verify-visited-file-modtime"); | 4108 DEFSYMBOL (Qverify_visited_file_modtime); |
4178 defsymbol (&Qset_visited_file_modtime, "set-visited-file-modtime"); | 4109 DEFSYMBOL (Qset_visited_file_modtime); |
4179 defsymbol (&Qcar_less_than_car, "car-less-than-car"); /* Vomitous! */ | 4110 DEFSYMBOL (Qcar_less_than_car); /* Vomitous! */ |
4180 | 4111 |
4181 defsymbol (&Qauto_save_hook, "auto-save-hook"); | 4112 DEFSYMBOL (Qauto_save_hook); |
4182 defsymbol (&Qauto_save_error, "auto-save-error"); | 4113 DEFSYMBOL (Qauto_save_error); |
4183 defsymbol (&Qauto_saving, "auto-saving"); | 4114 DEFSYMBOL (Qauto_saving); |
4184 | 4115 |
4185 defsymbol (&Qformat_decode, "format-decode"); | 4116 DEFSYMBOL (Qformat_decode); |
4186 defsymbol (&Qformat_annotate_function, "format-annotate-function"); | 4117 DEFSYMBOL (Qformat_annotate_function); |
4187 | 4118 |
4188 defsymbol (&Qcompute_buffer_file_truename, "compute-buffer-file-truename"); | 4119 DEFSYMBOL (Qcompute_buffer_file_truename); |
4189 DEFERROR_STANDARD (Qfile_error, Qio_error); | 4120 |
4190 DEFERROR_STANDARD (Qfile_already_exists, Qfile_error); | 4121 DEFERROR_STANDARD (Qfile_already_exists, Qfile_error); |
4191 | 4122 |
4192 DEFSUBR (Ffind_file_name_handler); | 4123 DEFSUBR (Ffind_file_name_handler); |
4193 | 4124 |
4194 DEFSUBR (Ffile_name_directory); | 4125 DEFSUBR (Ffile_name_directory); |