]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: introduce PTR_TO_MODE and MODE_TO_PTR macros
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 24 Apr 2019 23:19:07 +0000 (01:19 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 30 May 2019 12:08:51 +0000 (21:08 +0900)
src/basic/fs-util.h
src/basic/parse-util.h

index c153bc4448da61ccae1f5beabfaa7dd1d29e7b0f..c5527cc44fdf18a9d101f1e53de5c5002d76dbcf 100644 (file)
 #include "errno-util.h"
 #include "time-util.h"
 
+#define MODE_INVALID ((mode_t) -1)
+
+/* The following macros add 1 when converting things, since 0 is a valid mode, while the pointer
+ * NULL is special */
+#define PTR_TO_MODE(p) ((mode_t) ((uintptr_t) (p)-1))
+#define MODE_TO_PTR(u) ((void *) ((uintptr_t) (u)+1))
+
 int unlink_noerrno(const char *path);
 
 int rmdir_parents(const char *path, const char *stop);
index 7f5b0cf2b4894b0a93b1ee603dc3ebdb9796faf0..5a05dfeac550d3d317656c817dc67bf0ef3197d7 100644 (file)
@@ -9,8 +9,6 @@
 
 #include "macro.h"
 
-#define MODE_INVALID ((mode_t) -1)
-
 int parse_boolean(const char *v) _pure_;
 int parse_dev(const char *s, dev_t *ret);
 int parse_pid(const char *s, pid_t* ret_pid);