From a253bab22d706a30c3742757cb4c370f0bf19003 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Tue, 11 May 1993 01:39:42 +0000 Subject: [PATCH] * fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the filesystem being ro, since Solaris 2.1 doesn't. (file-writable-p): Call ro_fsys. * s/sol2.h (SOLARIS_BROKEN_ACCESS): Define this. --- src/fileio.c | 31 +++++++++++++++++++++++++++++-- src/s/sol2.h | 7 +++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/fileio.c b/src/fileio.c index 7927a52d1b..5e6f048b9c 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -2065,6 +2065,30 @@ Otherwise returns NIL.") #endif /* not S_IFLNK */ } +#ifdef SOLARIS_BROKEN_ACCESS +/* In Solaris 2.1, the readonly-ness of the filesystem is not + considered by the access system call. This is Sun's bug, but we + still have to make Emacs work. */ + +#include + +static int +ro_fsys (path) + char *path; +{ + struct statvfs statvfsb; + + if (statvfs(path, &statvfsb)) + return 1; /* error from statvfs, be conservative and say not wrtable */ + else + /* Otherwise, fsys is ro if bit is set. */ + return statvfsb.f_flag & ST_RDONLY; +} +#else +/* But on every other os, access has already done the right thing. */ +#define ro_fsys(path) 0 +#endif + /* Having this before file-symlink-p mysteriously caused it to be forgotten on the RT/PC. */ DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0, @@ -2085,13 +2109,16 @@ DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0, return call2 (handler, Qfile_writable_p, abspath); if (access (XSTRING (abspath)->data, 0) >= 0) - return (access (XSTRING (abspath)->data, 2) >= 0) ? Qt : Qnil; + return ((access (XSTRING (abspath)->data, 2) >= 0 + && ! ro_fsys (XSTRING (abspath))) + ? Qt : Qnil); dir = Ffile_name_directory (abspath); #ifdef VMS if (!NILP (dir)) dir = Fdirectory_file_name (dir); #endif /* VMS */ - return (access (!NILP (dir) ? (char *) XSTRING (dir)->data : "", 2) >= 0 + return ((access (!NILP (dir) ? (char *) XSTRING (dir)->data : "", 2) >= 0 + && ! ro_fsys ((char *) XSTRING (dir))) ? Qt : Qnil); } diff --git a/src/s/sol2.h b/src/s/sol2.h index ac499294f2..18d6d74f1c 100644 --- a/src/s/sol2.h +++ b/src/s/sol2.h @@ -17,3 +17,10 @@ #else /* GCC */ #define C_SWITCH_SYSTEM -traditional #endif /* GCC */ + +/* Karl Berry writes: +If you have the misfortune to be running Solaris 2.1, you may have +noticed that the access system call does not check the readonlyness of +the filesystem the path refers to. This is a bug, according to +access(2), but in the meantime, some of us need the right behavior. */ +#define SOLARIS_BROKEN_ACCESS -- 2.20.1