简体   繁体   English

ERANGE和EOVERFLOW之间的语义差异是什么?

[英]What's the semantic difference between ERANGE and EOVERFLOW?

The errno value ERANGE is documented by POSIX as POSIX将errnoERANGE记录为

Result too large. 结果太大了。

and EOVERFLOW is documented as EOVERFLOW记录为

Value too large to be stored in data type. 值太大而无法存储在数据类型中。

What's the semantic difference between these two? 这两者之间的语义差异是什么? Especially considering that ERANGE is used by ISO 9899 (eg in strtol ) with the semantic described for EOVERFLOW . 特别是考虑到ERANGE被ISO 9899(例如strtol )用于EOVERFLOW描述的语义。 Are these two errno values only distinct for historical reasons? 这两个errno值是否仅因历史原因而不同?

Please back up your arguments with appropriate sources if possible. 如果可能的话,请用适当的来源备份你的论点。

SingleUnix is quite verbose about EOVERFLOW : 关于EOVERFLOW SingleUnix非常详细:

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. 值太大而无法存储在数据类型中IPC或文件系统对象的用户ID或组ID太大,无法存储到调用者提供的结构的适当成员中。 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. 此错误仅发生在支持比声明的结构成员可支持的更大范围的用户ID或组ID值的实现上。 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. 这通常是因为IPC或文件系统对象驻留在具有比本地系统更大的类型uid_t,off_t或gid_t的远程计算机上。

EOVERFLOW seems to be intended to signal a subsystem incompatibility, ie some system returned a larger value than another subsystem can handle. EOVERFLOW似乎是为了表示子系统不兼容,即某些系统返回的值大于另一个子系统可以处理的值。

EOVERFLOW is explained in more detail in the rationale: EOVERFLOW在基本原理中有更详细的解释:

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. 通常,这些情况发生在支持具有不同大小的off_t的多个编程环境的系统上,但它们也可能与远程文件系统连接。

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. 另外,当不同的编程环境对于诸如int和uid_t的类型具有不同的宽度时,若干函数可能遇到特定环境中的值太宽而无法表示的条件。 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. 例如,假设当前正在运行的进程具有64位int,并且文件描述符9223372036854775807已打开且未设置close-on-exec标志。 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]. 如果进程然后使用execl()来执行在具有32位int的编程环境中编译的文件,则对execl()的调用可能会失败并且errno设置为[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. 如果要分配给新过程映像的任何用户标识或任何组标识超出执行文件编程环境的范围,则execl()可能会发生类似的故障。

Note, however, that this condition cannot occur for functions that are explicitly described as always being successful, such as getpid(). 但请注意,对于明确描述为始终成功的函数(例如getpid()),不会出现此情况。

Thanks to @rici for the pointer 感谢@rici指针

ERANGE is more like this won't ever fit . ERANGE更像是不适合的 strtol() is one example. strtol()就是一个例子。 Another, less clear one: Trying to increment a SYSV semaphore past its configured limit returns ERANGE . 另一个不那么清楚:尝试增加SYSV信号量超过其配置的限制返回ERANGE

With EOVERFLOW that data is there, it just does not fit into the local data structure(s). 有了数据存在的EOVERFLOW ,它就不适合本地数据结构。

For example, lseek() can return EOVERFLOW . 例如, lseek()可以返回EOVERFLOW This happens, eg when off_t is only 32bit but the file system can support larger files and you try to seek past the range the OS can handle. 发生这种情况,例如当off_t仅为32位但文件系统可以支持更大的文件时,您尝试超出操作系统可以处理的范围。 Why isn't this ERANGE ? 为什么不是这个ERANGE Because the system can handle the operation in principle, it just cannot return it to you in the data type available. 由于系统原则上可以处理操作,因此无法以可用的数据类型将其返回给您。

Trying to map more than 2G using mmap() on a 32bit system on Linux returns an EOVERFLOW (other systems return EINVAL ). 尝试在Linux上的32位系统上使用mmap()映射2G以上的数据会返回EOVERFLOW (其他系统返回EINVAL )。

Unfortunately, this is not totally consistent. 不幸的是,这并不完全一致。 For example, the bluetooth stack returns EOVERFLOW when it finds too many host controllers in the system. 例如,当蓝牙堆栈在系统中发现太多主机控制器时,它返回EOVERFLOW

There is a semantic difference: 存在语义差异:

EOVERFLOW is used for the case where a buffer size os too small and the data transfer requested would overflow the destination buffer, or similar error conditions: EOVERFLOW用于缓冲区大小os太小而请求的数据传输会溢出目标缓冲区或类似错误条件的情况:

http://man7.org/linux/man-pages/man2/open_by_handle_at.2.html http://man7.org/linux/man-pages/man2/open_by_handle_at.2.html

EOVERFLOW

  The handle->handle_bytes value passed into the call was too small. When this error occurs, handle->handle_bytes is updated to indicate the required size for the handle. 

http://man7.org/linux/man-pages/man2/open.2.html http://man7.org/linux/man-pages/man2/open.2.html

EOVERFLOW

  pathname refers to a regular file that is too large to be opened. The usual scenario here is that an application compiled on a 32-bit platform without -D_FILE_OFFSET_BITS=64 tried to open a file whose size exceeds (1<<31)-1 bytes; see also O_LARGEFILE above. This is the error specified by POSIX.1; in kernels before 2.6.24, Linux gave the error EFBIG for this case. 

ERANGE is used for values that do not fit in the destination type (C99) and for arguments outside the defined range for specific commands (POSIX) ERANGE用于不适合目标类型(C99)的值以及特定命令(POSIX)定义范围之外的参数

But it is also used in errors where EOVERFLOW would be more appropriate: 但它也用于EOVERFLOW更合适的错误:

http://man7.org/linux/man-pages/man3/pthread_setname_np.3.html http://man7.org/linux/man-pages/man3/pthread_setname_np.3.html

  The pthread_setname_np() function can fail with the following error: ERANGE The length of the string specified pointed to by name exceeds the allowed limit. The pthread_getname_np() function can fail with the following error: ERANGE The buffer specified by name and len is too small to hold the thread name. 

I guess EOVERFLOW is used for system calls and ERANGE is used in C library functions, standard and not. 我猜EOVERFLOW用于系统调用, ERANGE用于C库函数,标准与否。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM