changeset 8597:cfd5153bc220

(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.
author Richard M. Stallman <rms@gnu.org>
date Tue, 23 Aug 1994 22:36:41 +0000
parents ccd3c3ca2aef
children d49cb56cce45
files src/fileio.c
diffstat 1 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/fileio.c	Tue Aug 23 22:28:49 1994 +0000
+++ b/src/fileio.c	Tue Aug 23 22:36:41 1994 +0000
@@ -101,6 +101,10 @@
 #define O_WRONLY 1
 #endif
 
+#ifndef O_RDONLY
+#define O_RDONLY 0
+#endif
+
 #define min(a, b) ((a) < (b) ? (a) : (b))
 #define max(a, b) ((a) > (b) ? (a) : (b))
 
@@ -1706,9 +1710,12 @@
      int interactive;
 {
   register Lisp_Object tem;
+  struct stat statbuf;
   struct gcpro gcpro1;
 
-  if (access (XSTRING (absname)->data, 4) >= 0)
+  /* stat is a good way to tell whether the file exists,
+     regardless of what access permissions it has.  */
+  if (stat (XSTRING (absname)->data, &statbuf) >= 0)
     {
       if (! interactive)
 	Fsignal (Qfile_already_exists,
@@ -1769,7 +1776,7 @@
     barf_or_query_if_file_exists (newname, "copy to it",
 				  XTYPE (ok_if_already_exists) == Lisp_Int);
 
-  ifd = open (XSTRING (filename)->data, 0);
+  ifd = open (XSTRING (filename)->data, O_RDONLY);
   if (ifd < 0)
     report_file_error ("Opening input file", Fcons (filename, Qnil));
 
@@ -2168,6 +2175,7 @@
 {
   Lisp_Object abspath;
   Lisp_Object handler;
+  struct stat statbuf;
 
   CHECK_STRING (filename, 0);
   abspath = Fexpand_file_name (filename, Qnil);
@@ -2178,7 +2186,7 @@
   if (!NILP (handler))
     return call2 (handler, Qfile_exists_p, abspath);
 
-  return (access (XSTRING (abspath)->data, 0) >= 0) ? Qt : Qnil;
+  return (stat (XSTRING (abspath)->data, &statbuf) >= 0) ? Qt : Qnil;
 }
 
 DEFUN ("file-executable-p", Ffile_executable_p, Sfile_executable_p, 1, 1, 0,
@@ -2211,6 +2219,7 @@
 {
   Lisp_Object abspath;
   Lisp_Object handler;
+  int desc;
 
   CHECK_STRING (filename, 0);
   abspath = Fexpand_file_name (filename, Qnil);
@@ -2221,7 +2230,11 @@
   if (!NILP (handler))
     return call2 (handler, Qfile_readable_p, abspath);
 
-  return (access (XSTRING (abspath)->data, 4) >= 0) ? Qt : Qnil;
+  desc = open (XSTRING (abspath)->data, O_RDONLY);
+  if (desc < 0)
+    return Qnil;
+  close (desc);
+  return Qt;
 }
 
 DEFUN ("file-symlink-p", Ffile_symlink_p, Sfile_symlink_p, 1, 1, 0,
@@ -2608,7 +2621,7 @@
 #ifndef APOLLO
   if (stat (XSTRING (filename)->data, &st) < 0)
 #else
-  if ((fd = open (XSTRING (filename)->data, 0)) < 0
+  if ((fd = open (XSTRING (filename)->data, O_RDONLY)) < 0
       || fstat (fd, &st) < 0)
 #endif /* not APOLLO */
     {
@@ -2632,7 +2645,7 @@
 #endif
 
   if (fd < 0)
-    if ((fd = open (XSTRING (filename)->data, 0)) < 0)
+    if ((fd = open (XSTRING (filename)->data, O_RDONLY)) < 0)
       goto badopen;
 
   /* Replacement should preserve point as it preserves markers.  */