fix: ext2 directory insertion; racing on inode create
[lunaix-os.git] / lunaix-os / includes / lunaix / types.h
index 52faac3d486d6f6ef2efa7d539225fc6401b4f52..6ce5fcf3b71873e3ea2b7ce4243c03bff658aac0 100644 (file)
@@ -2,6 +2,7 @@
 #define __LUNAIX_TYPES_H
 
 #include <lunaix/compiler.h>
+#include <lunaix/limits.h>
 #include <stdarg.h>
 #include <usr/lunaix/types.h>
 
@@ -43,9 +44,15 @@ typedef int bool;
 #define container_of(ptr, type, member)                                        \
     ({                                                                         \
         const typeof(((type*)0)->member)* __mptr = (ptr);                      \
-        (ptr) ? (type*)((char*)__mptr - offsetof(type, member)) : 0;           \
+        ((ptr_t)ptr != 0UL) ? (type*)((char*)__mptr - offsetof(type, member)) : 0;           \
     })
 
+#define offset(data, off)   \
+            ((typeof(data))(__ptr(data) + (off)))
+
+#define offset_t(data, type, off)   \
+            ((type*)(__ptr(data) + (off)))
+
 #define __ptr(val)      ((ptr_t)(val))
 
 typedef va_list* sc_va_list;