summaryrefslogtreecommitdiff
path: root/src/basic/util.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-01-18 20:04:13 +0100
committerLennart Poettering <lennart@poettering.net>2019-02-08 10:34:47 +0100
commit840f606d88fef2f5d240b2d759ce7b951354d5bb (patch)
treefb9ab4e029e24b520ae33910f26fa5bb4e60f4e4 /src/basic/util.h
parent1cae151d8e38d4017ccd65ed12c459774e537bb2 (diff)
downloadsystemd-840f606d88fef2f5d240b2d759ce7b951354d5bb.tar.gz
util.h: add new UNPROTECT_ERRNO macro
THis is inspired by #11395, but much simpler.
Diffstat (limited to 'src/basic/util.h')
-rw-r--r--src/basic/util.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/basic/util.h b/src/basic/util.h
index f009d37d4c..dc33d66067 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -174,12 +174,21 @@ static inline void *mempset(void *s, int c, size_t n) {
}
static inline void _reset_errno_(int *saved_errno) {
+ if (*saved_errno < 0) /* Invalidated by UNPROTECT_ERRNO? */
+ return;
+
errno = *saved_errno;
}
#define PROTECT_ERRNO \
_cleanup_(_reset_errno_) _unused_ int _saved_errno_ = errno
+#define UNPROTECT_ERRNO \
+ do { \
+ errno = _saved_errno_; \
+ _saved_errno_ = -1; \
+ } while (false)
+
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();"