summaryrefslogtreecommitdiff
path: root/src/shared/macro.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-01-09 16:25:47 +0100
committerLennart Poettering <lennart@poettering.net>2015-01-09 18:35:36 +0100
commit8cb4ab0058e51f1fba93683d145ef95f97c2fa86 (patch)
tree022bbd937efd224d8de1e2c5db66331a6149ed74 /src/shared/macro.h
parent309a29dfd24f4175de334ca1593e3fe2436ab082 (diff)
logind: unify how we cast between uid_t and pointers for hashmap keys
Diffstat (limited to 'src/shared/macro.h')
-rw-r--r--src/shared/macro.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/shared/macro.h b/src/shared/macro.h
index 6a5742824..daa42c4c6 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -275,6 +275,14 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
#define PTR_TO_SIZE(p) ((size_t) ((uintptr_t) (p)))
#define SIZE_TO_PTR(u) ((void *) ((uintptr_t) (u)))
+/* The following macros add 1 when converting things, since UID 0 is a
+ * valid UID, while the pointer NULL is special */
+#define PTR_TO_UID(p) ((uid_t) (((uintptr_t) (p))-1))
+#define UID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1))
+
+#define PTR_TO_GID(p) ((gid_t) (((uintptr_t) (p))-1))
+#define GID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1))
+
#define memzero(x,l) (memset((x), 0, (l)))
#define zero(x) (memzero(&(x), sizeof(x)))