From: Ken Brown Date: Sat, 17 Dec 2011 17:00:49 +0000 (-0500) Subject: * src/fileio.c (check_writable) [CYGWIN]: Return non-zero if UID or X-Git-Tag: emacs-pretest-24.0.93~152 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e1b01a3a530809a1e84ecddff31faf85b94e79e7;p=emacs.git * src/fileio.c (check_writable) [CYGWIN]: Return non-zero if UID or GID is unknown (Bug#10257). --- diff --git a/src/ChangeLog b/src/ChangeLog index 98e87ef4306..e25f0c68ce0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2011-12-17 Ken Brown + + * fileio.c (check_writable) [CYGWIN]: Return non-zero if UID or + GID is unknown (Bug#10257). + 2011-12-17 Paul Eggert * s/gnu-linux.h: Fix mark_memory typo (Bug#10286). diff --git a/src/fileio.c b/src/fileio.c index fb021cee5a4..3306085491e 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -2416,15 +2416,27 @@ check_writable (const char *filename) return (st.st_mode & S_IWRITE || S_ISDIR (st.st_mode)); #else /* not MSDOS */ #ifdef HAVE_EUIDACCESS - return (euidaccess (filename, 2) >= 0); -#else + int res = (euidaccess (filename, 2) >= 0); +#ifdef CYGWIN + /* euidaccess may have returned failure because Cygwin couldn't + determine the file's UID or GID; if so, we return success. */ + if (!res) + { + struct stat st; + if (stat (filename, &st) < 0) + return 0; + res = (st.st_uid == -1 || st.st_gid == -1); + } +#endif /* CYGWIN */ + return res; +#else /* not HAVE_EUIDACCESS */ /* Access isn't quite right because it uses the real uid and we really want to test with the effective uid. But Unix doesn't give us a right way to do it. Opening with O_WRONLY could work for an ordinary file, but would lose for directories. */ return (access (filename, 2) >= 0); -#endif +#endif /* not HAVE_EUIDACCESS */ #endif /* not MSDOS */ }