daandemeyer / rpms / systemd

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