mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-06 06:20:55 -08:00
Update from Gnulib by running admin/merge-gnulib
* admin/merge-gnulib (GNULIB_MODULES): Add stringeq. With current Gnulib it is already present as in indirect dependency; listing it here because Emacs now depends on it directly. * lib-src/ebrowse.c, lib-src/etags.c: (streq): Remove, as Gnulib defines this now. * lib/fseterr.c, lib/fseterr.h, lib/issymlink.c, lib/issymlink.h: * lib/issymlinkat.c, lib/stdio-consolesafe.c, lib/string.c: * m4/fseterr.m4, m4/gettext_h.m4, m4/stringeq.m4: New files from Gnulib. * src/conf_post.h (tzfree) [__ANDROID_API__ >= 35]: Remove.
This commit is contained in:
parent
327c16ce14
commit
59fbaca6b9
115 changed files with 1733 additions and 1097 deletions
32
lib/lchmod.c
32
lib/lchmod.c
|
|
@ -29,6 +29,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include <intprops.h>
|
||||
#include "issymlink.h"
|
||||
|
||||
/* Work like chmod, except when FILE is a symbolic link.
|
||||
In that case, on systems where permissions on symbolic links are unsupported
|
||||
|
|
@ -37,29 +38,30 @@
|
|||
int
|
||||
lchmod (char const *file, mode_t mode)
|
||||
{
|
||||
char readlink_buf[1];
|
||||
|
||||
#ifdef O_PATH
|
||||
/* Open a file descriptor with O_NOFOLLOW, to make sure we don't
|
||||
follow symbolic links, if /proc is mounted. O_PATH is used to
|
||||
avoid a failure if the file is not readable.
|
||||
Cf. <https://sourceware.org/bugzilla/show_bug.cgi?id=14578> */
|
||||
Cf. <https://sourceware.org/PR14578> */
|
||||
int fd = open (file, O_PATH | O_NOFOLLOW | O_CLOEXEC);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
int err;
|
||||
if (0 <= readlinkat (fd, "", readlink_buf, sizeof readlink_buf))
|
||||
err = EOPNOTSUPP;
|
||||
else if (errno == EINVAL)
|
||||
{
|
||||
static char const fmt[] = "/proc/self/fd/%d";
|
||||
char buf[sizeof fmt - sizeof "%d" + INT_BUFSIZE_BOUND (int)];
|
||||
sprintf (buf, fmt, fd);
|
||||
err = chmod (buf, mode) == 0 ? 0 : errno == ENOENT ? -1 : errno;
|
||||
}
|
||||
else
|
||||
err = errno == ENOENT ? -1 : errno;
|
||||
{
|
||||
int ret = issymlinkat (fd, "");
|
||||
if (ret > 0)
|
||||
err = EOPNOTSUPP;
|
||||
else if (ret == 0)
|
||||
{
|
||||
static char const fmt[] = "/proc/self/fd/%d";
|
||||
char buf[sizeof fmt - sizeof "%d" + INT_BUFSIZE_BOUND (int)];
|
||||
sprintf (buf, fmt, fd);
|
||||
err = chmod (buf, mode) == 0 ? 0 : errno == ENOENT ? -1 : errno;
|
||||
}
|
||||
else
|
||||
err = errno == ENOENT ? -1 : errno;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
|
||||
|
|
@ -83,7 +85,7 @@ lchmod (char const *file, mode_t mode)
|
|||
|
||||
/* O_PATH + /proc is not supported. */
|
||||
|
||||
if (0 <= readlink (file, readlink_buf, sizeof readlink_buf))
|
||||
if (issymlink (file) > 0)
|
||||
{
|
||||
errno = EOPNOTSUPP;
|
||||
return -1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue