c - ERANGE 和 EOVERFLOW 之间的语义区别是什么?

标签 c posix semantics errno

errnoERANGE 被 POSIX 记录为

Result too large.

EOVERFLOW被记录为

Value too large to be stored in data type.

这两者之间的语义区别是什么?特别是考虑到 ERANGE 被 ISO 9899 使用(例如在 strtol 中),其语义描述为 EOVERFLOW。这两个 errno 值是否只是由于历史原因而不同?

如果可能,请使用适当的来源支持您的论点。

最佳答案

SingleUnix 对 EOVERFLOW 相当冗长:

Value too large to be stored in data type The user ID or group ID of an IPC or file system object was too large to be stored into appropriate member of the caller-provided structure. This error will only occur on implementations that support a larger range of user ID or group ID values than the declared structure member can support. This usually occurs because the IPC or file system object resides on a remote machine with a larger value of the type uid_t, off_t or gid_t than the local system.

EOVERFLOW 似乎旨在表示子系统不兼容,即某些系统返回的值大于另一个子系统可以处理的值。

EOVERFLOWexplained in more detail理由:

Most of the uses of this error code are related to large file support. Typically, these cases occur on systems which support multiple programming environments with different sizes for off_t, but they may also occur in connection with remote file systems.

In addition, when different programming environments have different widths for types such as int and uid_t, several functions may encounter a condition where a value in a particular environment is too wide to be represented. In that case, this error should be raised. For example, suppose the currently running process has 64-bit int, and file descriptor 9223372036854775807 is open and does not have the close-on- exec flag set. If the process then uses execl() to exec a file compiled in a programming environment with 32-bit int, the call to execl() can fail with errno set to [EOVERFLOW]. A similar failure can occur with execl() if any of the user IDs or any of the group IDs to be assigned to the new process image are out of range for the executed file's programming environment.

Note, however, that this condition cannot occur for functions that are explicitly described as always being successful, such as getpid().

感谢@rici 指点

ERANGE 更像是永远不适合strtol() 就是一个例子。另一个不太清楚的问题:尝试将 SYSV 信号量增加到超过其配置的限制返回 ERANGE

有了 EOVERFLOW,数据就在那里,只是不适合本地数据结构。

例如,lseek() 可以返回EOVERFLOW。这种情况发生,例如当 off_t 仅为 32 位但文件系统可以支持更大的文件时,您尝试寻找超过操作系统可以处理的范围。为什么这不是 ERANGE?因为系统原则上可以处理操作,只是不能以可用的数据类型返回给你。

尝试在 Linux 的 32 位系统上使用 mmap() 映射超过 2G 返回 EOVERFLOW(其他系统返回 EINVAL)。

不幸的是,这并不完全一致。例如,蓝牙堆栈在发现系统中有太多主机 Controller 时返回 EOVERFLOW

关于c - ERANGE 和 EOVERFLOW 之间的语义区别是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34981085/

相关文章:

c - Eclipse CDT 自定义生成文件

c - 在 C 中通过引用传递

c - C 代码中 if 和 switch 语句中的意外输出

c++ - 将单例实例限制为线程

用于一组缩略图的 HTML5 标签

html - 没有<ol>或<ul>的<li>的语义意义?

c - 如何为二维数组动态分配连续的内存块

c - 使用read函数使用C读取大文件(大于4GB),导致问题

正则表达式在 C 中不起作用

javascript - RDF 可以在 MarkLogic 中与 JSON 一起使用吗?