groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [groff] [off-topic] Reliable use of errno


From: Ralph Corderoy
Subject: Re: [groff] [off-topic] Reliable use of errno
Date: Sun, 19 Aug 2018 15:27:03 +0100

Hi Ingo,

> even though close(2) is the most typical example of a system call
> where checking the return value / checking for failure is almost never
> useful, and simply ignoring both the return value and errno is what
> you should do in most cases.

There's ENOSPC indicating a previous write(2) didn't fare well?

>  * not all functions adhere to the 0/-1 scheme to report success
>    or failure, allways check the spec.

fgetpos() is one that deviates;  it returns non-zero on error, setting
errno.  So does raise().  So a `< 0' test may work a lot, but not all,
of the time.

fgetwc() another, returning WEOF, e.g. 0xffffffffu, and setting errno.
Some functions may set errno, but have no return value to indicate it,
e.g. strcoll().  mbrlen() returns (size_t)-1 on error, but (size_t)-2
for another exceptional state that should be handled differently!

I think `< 0' when not necessary for the spec. lures the writer, and
readers, into complacency.

> Behaviour of some is implementation-dependent in some respects, most
> notably in the printf(3) family.

Right, POSIX says printf() returns negative on error, not just -1,
setting errno.

-- 
Cheers, Ralph.
https://plus.google.com/+RalphCorderoy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]