gpt4 book ai didi

AT_SYMLINK_NOFOLLOW 会导致 fchmodat() 出现 EINVAL 吗?

转载 作者:行者123 更新时间:2023-12-02 08:44:29 25 4
gpt4 key购买 nike

我正在阅读 fchmodat() POSIX function spec我不确定以下是否正确:

#include <fcntl.h>
#include <sys/stat.h>

int chown_test(const char* path, mode_t mode, mode_t new_mode)
{
#ifdef HAVE_FCHMODAT
if (fchmodat(AT_FDCWD, path, new_mode,
AT_SYMLINK_NOFOLLOW) && errno != EOPNOTSUPP)
return 1;
#else
if (!S_ISLNK(mode) && chmod(path, new_mode))
return 1;
#endif

return 0;
}

modest_modelstat(path...) .

换句话说,如果系统支持的话,上面的函数应该尝试设置文件或符号链接(symbolic link)的模式。如果没有,它应该优雅地返回。

因此,我正在检查 EOPNOTSUPP POSIX 指定的错误:

[EOPNOTSUPP]

The AT_SYMLINK_NOFOLLOW bit is set in the flag argument, path names a symbolic link, and the system does not support changing the mode of a symbolic link.

但是,我有点担心EINVAL指定为:

[EINVAL]

The value of the flag argument is invalid.

理论上,如果特定文件系统不支持设置符号链接(symbolic link)的模式位,我认为它实际上可以处理 AT_SYMLINK_NOFOLLOW作为无效标志。

另一方面,EOPNOTSUPP错误描述和标志的描述方式:

Values for flag are constructed by a bitwise-inclusive OR of flags from the following list, defined in :

AT_SYMLINK_NOFOLLOW

If path names a symbolic link, then the mode of the symbolic link is changed.

让我认为这个标志应该始终被兼容的实现视为有效。

我是否正确,或者我应该回退到 chmod()如果是 EINVAL

<小时/>

编辑:作为注释,我刚刚发现 Linux 返回 ENOTSUP (与 EOPNOTSUPP 具有相同的值)每当 AT_SYMLINK_NOFOLLOW 时被使用,即使路径没有命名符号链接(symbolic link)。

最佳答案

相关文本是 XSH 2.3 错误号:

Implementations may support additional errors not included in this list, may generate errors included in this list under circumstances other than those described here, or may contain extensions or limitations that prevent some errors from occurring.

起初这似乎允许所描述的行为。不过我相信下面的文字:

Implementations may generate error numbers listed here under circumstances other than those described, if and only if all those error conditions can always be treated identically to the error conditions as described in this volume of POSIX.1-2008. Implementations shall not generate a different error number from one required by this volume of POSIX.1-2008 for an error condition described in this volume of POSIX.1-2008, but may generate additional errors unless explicitly disallowed for a particular function.

呈现一个给出 EINVAL 的实现,表示此条件不符合要求。 POSIX 指定 EOPNOTSUPP 作为此条件的错误代码,因此实现“不应”(这是规范要求)为其生成不同的错误代码。

来源:http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_03

关于AT_SYMLINK_NOFOLLOW 会导致 fchmodat() 出现 EINVAL 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12396615/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com