summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index e405b02a81..af589b6708 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -794,6 +794,15 @@ static inline void _reset_errno_(int *saved_errno) {
#define PROTECT_ERRNO _cleanup_(_reset_errno_) __attribute__((unused)) int _saved_errno_ = errno
+static inline int negative_errno(void) {
+ /* This helper should be used to shut up gcc if you know 'errno' is
+ * negative. Instead of "return -errno;", use "return negative_errno();"
+ * It will suppress bogus gcc warnings in case it assumes 'errno' might
+ * be 0 and thus the caller's error-handling might not be triggered. */
+ assert_return(errno > 0, -EINVAL);
+ return -errno;
+}
+
struct _umask_struct_ {
mode_t mask;
bool quit;