From: Richard M. Stallman Date: Tue, 23 Aug 1994 22:36:41 +0000 (+0000) Subject: (O_RDONLY): Defined. X-Git-Tag: emacs-19.34~7256 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4018b5ef31d23584adcd349a856f7248a84a32ba;p=emacs.git (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. --- 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 (); #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 @@ barf_or_query_if_file_exists (absname, querystring, interactive) 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 @@ A prefix arg makes KEEP-TIME non-nil.") 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 @@ See also `file-readable-p' and `file-attributes'.") { Lisp_Object abspath; Lisp_Object handler; + struct stat statbuf; CHECK_STRING (filename, 0); abspath = Fexpand_file_name (filename, Qnil); @@ -2178,7 +2186,7 @@ See also `file-readable-p' and `file-attributes'.") 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 @@ See also `file-exists-p' and `file-attributes'.") { Lisp_Object abspath; Lisp_Object handler; + int desc; CHECK_STRING (filename, 0); abspath = Fexpand_file_name (filename, Qnil); @@ -2221,7 +2230,11 @@ See also `file-exists-p' and `file-attributes'.") 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 @@ and (2) it puts less data in the undo list.") #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 @@ and (2) it puts less data in the undo list.") #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. */