If strtol(3) returns 0 and sets errno to something different than EINVAL, the call succeeded, or so we interpret from the standards. POSIX allows libc functions to set errno in success, and it only specifies two errors for strtol(3) for which it can return 0: - Unsupported base. (errno must be set to EINVAL.) - No conversion performed. (errno might be set to EINVAL.) If errno is anything else, POSIX doesn't specify, so it can only be a successful call strtol(3) that read "0" and set errno for spurious reasons that are allowed. Cc: Florian Weimer Cc: Iker Pedrosa Signed-off-by: Alejandro Colomar --- man3/strtol.3 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/man3/strtol.3 b/man3/strtol.3 index a5082a761..be8cc81d9 100644 --- a/man3/strtol.3 +++ b/man3/strtol.3 @@ -264,7 +264,8 @@ .SS Program source /* Check for various possible errors */ \& if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) - || (errno != 0 && val == 0)) { + || (errno == EINVAL && val == 0)) + { perror("strtol"); exit(EXIT_FAILURE); } -- 2.42.0