aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1994-08-23 22:36:41 +0000
committerRichard M. Stallman1994-08-23 22:36:41 +0000
commit4018b5ef31d23584adcd349a856f7248a84a32ba (patch)
tree836d7f0d312786bc035b59e1604036d678312e3b /src
parentf7d279f05dea5b655a35c93ff863af300b79cd58 (diff)
downloademacs-4018b5ef31d23584adcd349a856f7248a84a32ba.tar.gz
emacs-4018b5ef31d23584adcd349a856f7248a84a32ba.zip
(O_RDONLY): Defined.
(Finsert_file_contents, Fcopy_file): use it. (barf_or_query_if_file_exists, Ffile_exists_p): Use stat, not access. (Ffile_readable_p): Use open, not access.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 494694782af..e13bcc61f67 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -101,6 +101,10 @@ extern char *strerror ();
101#define O_WRONLY 1 101#define O_WRONLY 1
102#endif 102#endif
103 103
104#ifndef O_RDONLY
105#define O_RDONLY 0
106#endif
107
104#define min(a, b) ((a) < (b) ? (a) : (b)) 108#define min(a, b) ((a) < (b) ? (a) : (b))
105#define max(a, b) ((a) > (b) ? (a) : (b)) 109#define max(a, b) ((a) > (b) ? (a) : (b))
106 110
@@ -1706,9 +1710,12 @@ barf_or_query_if_file_exists (absname, querystring, interactive)
1706 int interactive; 1710 int interactive;
1707{ 1711{
1708 register Lisp_Object tem; 1712 register Lisp_Object tem;
1713 struct stat statbuf;
1709 struct gcpro gcpro1; 1714 struct gcpro gcpro1;
1710 1715
1711 if (access (XSTRING (absname)->data, 4) >= 0) 1716 /* stat is a good way to tell whether the file exists,
1717 regardless of what access permissions it has. */
1718 if (stat (XSTRING (absname)->data, &statbuf) >= 0)
1712 { 1719 {
1713 if (! interactive) 1720 if (! interactive)
1714 Fsignal (Qfile_already_exists, 1721 Fsignal (Qfile_already_exists,
@@ -1769,7 +1776,7 @@ A prefix arg makes KEEP-TIME non-nil.")
1769 barf_or_query_if_file_exists (newname, "copy to it", 1776 barf_or_query_if_file_exists (newname, "copy to it",
1770 XTYPE (ok_if_already_exists) == Lisp_Int); 1777 XTYPE (ok_if_already_exists) == Lisp_Int);
1771 1778
1772 ifd = open (XSTRING (filename)->data, 0); 1779 ifd = open (XSTRING (filename)->data, O_RDONLY);
1773 if (ifd < 0) 1780 if (ifd < 0)
1774 report_file_error ("Opening input file", Fcons (filename, Qnil)); 1781 report_file_error ("Opening input file", Fcons (filename, Qnil));
1775 1782
@@ -2168,6 +2175,7 @@ See also `file-readable-p' and `file-attributes'.")
2168{ 2175{
2169 Lisp_Object abspath; 2176 Lisp_Object abspath;
2170 Lisp_Object handler; 2177 Lisp_Object handler;
2178 struct stat statbuf;
2171 2179
2172 CHECK_STRING (filename, 0); 2180 CHECK_STRING (filename, 0);
2173 abspath = Fexpand_file_name (filename, Qnil); 2181 abspath = Fexpand_file_name (filename, Qnil);
@@ -2178,7 +2186,7 @@ See also `file-readable-p' and `file-attributes'.")
2178 if (!NILP (handler)) 2186 if (!NILP (handler))
2179 return call2 (handler, Qfile_exists_p, abspath); 2187 return call2 (handler, Qfile_exists_p, abspath);
2180 2188
2181 return (access (XSTRING (abspath)->data, 0) >= 0) ? Qt : Qnil; 2189 return (stat (XSTRING (abspath)->data, &statbuf) >= 0) ? Qt : Qnil;
2182} 2190}
2183 2191
2184DEFUN ("file-executable-p", Ffile_executable_p, Sfile_executable_p, 1, 1, 0, 2192DEFUN ("file-executable-p", Ffile_executable_p, Sfile_executable_p, 1, 1, 0,
@@ -2211,6 +2219,7 @@ See also `file-exists-p' and `file-attributes'.")
2211{ 2219{
2212 Lisp_Object abspath; 2220 Lisp_Object abspath;
2213 Lisp_Object handler; 2221 Lisp_Object handler;
2222 int desc;
2214 2223
2215 CHECK_STRING (filename, 0); 2224 CHECK_STRING (filename, 0);
2216 abspath = Fexpand_file_name (filename, Qnil); 2225 abspath = Fexpand_file_name (filename, Qnil);
@@ -2221,7 +2230,11 @@ See also `file-exists-p' and `file-attributes'.")
2221 if (!NILP (handler)) 2230 if (!NILP (handler))
2222 return call2 (handler, Qfile_readable_p, abspath); 2231 return call2 (handler, Qfile_readable_p, abspath);
2223 2232
2224 return (access (XSTRING (abspath)->data, 4) >= 0) ? Qt : Qnil; 2233 desc = open (XSTRING (abspath)->data, O_RDONLY);
2234 if (desc < 0)
2235 return Qnil;
2236 close (desc);
2237 return Qt;
2225} 2238}
2226 2239
2227DEFUN ("file-symlink-p", Ffile_symlink_p, Sfile_symlink_p, 1, 1, 0, 2240DEFUN ("file-symlink-p", Ffile_symlink_p, Sfile_symlink_p, 1, 1, 0,
@@ -2608,7 +2621,7 @@ and (2) it puts less data in the undo list.")
2608#ifndef APOLLO 2621#ifndef APOLLO
2609 if (stat (XSTRING (filename)->data, &st) < 0) 2622 if (stat (XSTRING (filename)->data, &st) < 0)
2610#else 2623#else
2611 if ((fd = open (XSTRING (filename)->data, 0)) < 0 2624 if ((fd = open (XSTRING (filename)->data, O_RDONLY)) < 0
2612 || fstat (fd, &st) < 0) 2625 || fstat (fd, &st) < 0)
2613#endif /* not APOLLO */ 2626#endif /* not APOLLO */
2614 { 2627 {
@@ -2632,7 +2645,7 @@ and (2) it puts less data in the undo list.")
2632#endif 2645#endif
2633 2646
2634 if (fd < 0) 2647 if (fd < 0)
2635 if ((fd = open (XSTRING (filename)->data, 0)) < 0) 2648 if ((fd = open (XSTRING (filename)->data, O_RDONLY)) < 0)
2636 goto badopen; 2649 goto badopen;
2637 2650
2638 /* Replacement should preserve point as it preserves markers. */ 2651 /* Replacement should preserve point as it preserves markers. */