[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] [off-topic] Reliable use of errno
From: |
Carsten Kunze |
Subject: |
[groff] [off-topic] Reliable use of errno |
Date: |
Sun, 19 Aug 2018 14:32:49 +0200 (CEST) |
Hello,
sorry for misusing the list for something completely off-topic (while it still
refers to the documentation of the UNIX system), but since there are many UNIX
experts on the list maybe someone has a definite answer.
Many system calls (e.g. close(2),
http://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html) return 0
on success and -1 on error and set errno.
My understanding is that errno is only reliably set when the system call
returns -1, not for < -1 nor for > 0, so I do only check the error condition
with "if (close(fd) == -1)" ignoring all other values. Some are testing for "<
0" but would it not be consequent for them to check for "!= 0"? So when can I
rely on errno to be set, for -1, for "< 0" or for "!= 0"?
In case of library functions (e.g. fclose(3),
http://pubs.opengroup.org/onlinepubs/9699919799/functions/fclose.html) we have
a similar situation with the return values 0 and EOF.
I did test for errors with "if (fclose(fh) == EOF)", others are testing for "!=
0". When can I rely here for errno to be set, only in case of EOF or als for
"!= 0"?
Thank you and sorry for the noice.
--Carsten
- [groff] [off-topic] Reliable use of errno,
Carsten Kunze <=