tree-wide: define and use STRERROR_OR_EOF()

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2022-10-11 16:58:21 +02:00
parent a6e016af01
commit f69ae8585f
5 changed files with 18 additions and 7 deletions
+5
View File
@@ -16,6 +16,11 @@
* Note that we use the GNU variant of strerror_r() here. */
#define STRERROR(errnum) strerror_r(abs(errnum), (char[ERRNO_BUF_LEN]){}, ERRNO_BUF_LEN)
/* A helper to print an error message or message for functions that return 0 on EOF.
* Note that we can't use ({ … }) to define a temporary variable, so errnum is
* evaluated twice. */
#define STRERROR_OR_EOF(errnum) ((errnum) != 0 ? STRERROR(errnum) : "Unexpected EOF")
static inline void _reset_errno_(int *saved_errno) {
if (*saved_errno < 0) /* Invalidated by UNPROTECT_ERRNO? */
return;