4 ms·
#define ERANGE 34 /* Math result not representable */ > Hold on. Math result? But we don't do any math in the call that triggers that. Do we? If you "man errn
by segfaultbuserr 7y ago
#define ERANGE 34 /* Math result not representable */
> Hold on. Math result? But we don't do any math in the call that triggers that. Do we?
If you "man errno", you'll open a man page from Linux Programmer's Manual which tells you that "ERANGE" means "result too large" and it was defined in POSIX.1 and C99 standard, using it for either math overflow or size in general is appropriate. Particularly, in C99 (page 214, page 311) [0] , ERANGE is often returned by math functions (but it was also used by strtol, strtoll, strtoul, and strtoull for indicating buffer overflow), and simply defines it as "ERANGE: Result too large" [1].
So the conclusion is, although abusing the errno in an ad-hoc basis is not uncommon, but clearly this is not the case here, it's perfectly in compliance and it's even documented. It was simply the case which the comment itself in <asm-generic/errno-base.h> was outdated and misleading.
I suspect "ERANGE" was originally introduced to <asm-generic/errno-base.h> for some math or softfloat code and/or it was a copy-and-paste of the C manual, but later it was picked up by other system calls, and the original comment was never updated. The fact that
#define EDOM 33 /* Math argument out of domain of func */
was just above ERANGE is possibly my circumstantial evidence.
However, I just looked through "git log" but I couldn't confirm my hypothesis, since the code has been there since 2005 [3] in the first git release. The comment must be ancient, a real historical artifact.
[0] http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf
[1] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/er...
[3] https://github.com/torvalds/linux/blob/0d7614f09c1ebdbaa1599a5aba7593f147bf96ee/include/asm-generic/errno-base.h https://github.com/torvalds/linux/blob/0d7614f09c1ebdbaa1599...
- fao_ 7y agoIndeed! I was indeed aware of this specific use of ERANGE (although imo there's almost always a better error code that can be chosen to better communicate what has happened).