Merge pull request #28359 from keszybz/ret-gather

Add RET_GATHER macro to make continue-but-remember-first-error functions easier
This commit is contained in:
Daan De Meyer
2023-07-28 14:28:35 +02:00
committed by GitHub
30 changed files with 247 additions and 415 deletions
+10
View File
@@ -73,6 +73,16 @@ static inline int RET_NERRNO(int ret) {
return ret;
}
/* Collect possible errors in <acc>, so that the first error can be returned.
* Returns (possibly updated) <acc>. */
#define RET_GATHER(acc, err) \
({ \
int *__a = &(acc), __e = (err); \
if (*__a >= 0 && __e < 0) \
*__a = __e; \
*__a; \
})
static inline int errno_or_else(int fallback) {
/* To be used when invoking library calls where errno handling is not defined clearly: we return
* errno if it is set, and the specified error otherwise. The idea is that the caller initializes