Re: refactoring basebackup.c (zstd workers) - Mailing list pgsql-hackers

From Tom Lane
Subject Re: refactoring basebackup.c (zstd workers)
Date
Msg-id 1565808.1647803514@sss.pgh.pa.us
Whole thread Raw
In response to Re: refactoring basebackup.c (zstd workers)  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: refactoring basebackup.c (zstd workers)  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
Robert Haas <robertmhaas@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/



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: refactoring basebackup.c (zstd workers)
Next
From: Justin Pryzby
Date:
Subject: Re: refactoring basebackup.c (zstd workers)