gpt4 book ai didi

linux - 任何 errno 都是 read() 的有效 POSIX 返回值吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:57:54 24 4
gpt4 key购买 nike

是 POSIX,在设备驱动程序读取函数中返回 errno.h 中列出的任何可用 errno 值,还是我应该只使用 read linux 手册页中列出的值?

编辑:
我正在编写一个设备驱动程序,其中用户必须在调用读取函数之前使用 ioctl cmd 设置一些参数。因此,如果用户在设置这些参数之前尝试调用读取函数,我正在寻找要返回的正确 errno 值。 EPERM“不允许操作”似乎是正确的,但因为它没有在阅读的 linux 手册页中列出,我想知道这是否是一个正确的实现。

最佳答案

POSIX 要求使用列出的错误代码来报告相应的错误情况。但是,它还允许将其他错误代码用于未列出的错误。

text来自 POSIX.1-2008 第 2 卷:系统接口(interface),第 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.

The ERRORS section on each reference page specifies which error conditions shall be detected by all implementations ("shall fail") and which may be optionally detected by an implementation ("may fail"). If no error condition is detected, the action requested shall be successful.

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.

关于linux - 任何 errno 都是 read() 的有效 POSIX 返回值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13861969/

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