X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.h;h=af589b6708c79d04f7b917538a1c408935be3711;hb=592fd144ae313855f48d0ca52a103013b41e5d59;hp=e405b02a8189760d4a9a773c160f330baba20bc7;hpb=b5de6d984296c9446ba0d2d32fd3248f453208aa;p=elogind.git diff --git a/src/shared/util.h b/src/shared/util.h index e405b02a8..af589b670 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;