Robert Haas <robertmh...@gmail.com> writes: >> Should this also set/check errno ? >> And check if value != ivalue_endp ? >> See strtol(3)
> Even after reading the man page for strtol, it's not clear to me that > this is needed. That page represents checking *endptr != '\0' as > sufficient to tell whether an error occurred. I'm not sure whose man page you looked at, but the POSIX standard [1] has a pretty clear opinion about this: Since 0, {LONG_MIN} or {LLONG_MIN}, and {LONG_MAX} or {LLONG_MAX} are returned on error and are also valid returns on success, an application wishing to check for error situations should set errno to 0, then call strtol() or strtoll(), then check errno. Checking *endptr != '\0' is for detecting whether there is trailing garbage after the number; which may be an error case or not as you choose, but it's a different matter. regards, tom lane [1] https://pubs.opengroup.org/onlinepubs/9699919799/