naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
be0c12
From c078d4d4bc3a61d186a98e03afc699b11134e09f Mon Sep 17 00:00:00 2001
be0c12
From: Lennart Poettering <lennart@poettering.net>
be0c12
Date: Wed, 20 Nov 2019 12:22:40 +0100
be0c12
Subject: [PATCH] errno-util: add ERRNO_IS_PRIVILEGE() helper
be0c12
be0c12
(cherry picked from commit e884e000714c2db006384058a63788ffcce8c8b8)
be0c12
be0c12
Related: #1977569
be0c12
---
be0c12
 src/basic/util.h | 7 +++++++
be0c12
 1 file changed, 7 insertions(+)
be0c12
be0c12
diff --git a/src/basic/util.h b/src/basic/util.h
be0c12
index c70467f98c..76b76d7e91 100644
be0c12
--- a/src/basic/util.h
be0c12
+++ b/src/basic/util.h
be0c12
@@ -170,6 +170,13 @@ static inline int negative_errno(void) {
be0c12
         return -errno;
be0c12
 }
be0c12
 
be0c12
+/* Two different errors for access problems */
be0c12
+static inline bool ERRNO_IS_PRIVILEGE(int r) {
be0c12
+        return IN_SET(abs(r),
be0c12
+                      EACCES,
be0c12
+                      EPERM);
be0c12
+}
be0c12
+
be0c12
 static inline unsigned u64log2(uint64_t n) {
be0c12
 #if __SIZEOF_LONG_LONG__ == 8
be0c12
         return (n > 1) ? (unsigned) __builtin_clzll(n) ^ 63U : 0;