static int fchmodat_nofollow(int dirfd, const char *name, mode_t mode)

{

    int fd, ret;



    /* FIXME: this should be handled with fchmodat(AT_SYMLINK_NOFOLLOW).

     * Unfortunately, the linux kernel doesn't implement it yet. As an

     * alternative, let's open the file and use fchmod() instead. This

     * may fail depending on the permissions of the file, but it is the

     * best we can do to avoid TOCTTOU. We first try to open read-only

     * in case name points to a directory. If that fails, we try write-only

     * in case name doesn't point to a directory.

     */

    fd = openat_file(dirfd, name, O_RDONLY, 0);

    if (fd == -1) {

        /* In case the file is writable-only and isn't a directory. */

        if (errno == EACCES) {

            fd = openat_file(dirfd, name, O_WRONLY, 0);

        }

        if (fd == -1 && errno == EISDIR) {

            errno = EACCES;

        }

    }

    if (fd == -1) {

        return -1;

    }

    ret = fchmod(fd, mode);

    close_preserve_errno(fd);

    return ret;

}

static int fchmodat_nofollow(int dirfd, const char *name, mode_t mode)

{

    int fd, ret;



    















    fd = openat_file(dirfd, name, O_RDONLY, 0);

    if (fd == -1) {

        

        if (errno == EACCES) {

            fd = openat_file(dirfd, name, O_WRONLY, 0);

        }

        if (fd == -1 && errno == EISDIR) {

            errno = EACCES;

        }

    }

    if (fd == -1) {

        return -1;

    }

    ret = fchmod(fd, mode);

    close_preserve_errno(fd);

    return ret;

}

    fd = openat_file(dirfd, name, O_RDONLY, 0);
static int FUNC_0(int VAR_0, const char *VAR_1, mode_t VAR_2)

{

    int VAR_3, VAR_4;



    















    VAR_3 = openat_file(VAR_0, VAR_1, O_RDONLY, 0);

    if (VAR_3 == -1) {

        

        if (errno == EACCES) {

            VAR_3 = openat_file(VAR_0, VAR_1, O_WRONLY, 0);

        }

        if (VAR_3 == -1 && errno == EISDIR) {

            errno = EACCES;

        }

    }

    if (VAR_3 == -1) {

        return -1;

    }

    VAR_4 = fchmod(VAR_3, VAR_2);

    close_preserve_errno(VAR_3);

    return VAR_4;

}

static int FUNC_0(int VAR_0, const char *VAR_1, mode_t VAR_2)
{ int VAR_3, VAR_4; VAR_3 = openat_file(VAR_0, VAR_1, O_RDONLY, 0); if (VAR_3 == -1) { if (errno == EACCES) { VAR_3 = openat_file(VAR_0, VAR_1, O_WRONLY, 0); } if (VAR_3 == -1 && errno == EISDIR) { errno = EACCES; } } if (VAR_3 == -1) { return -1; } VAR_4 = fchmod(VAR_3, VAR_2); close_preserve_errno(VAR_3); return VAR_4; }