ryantimwilson / rpms / systemd

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