From aaf7355c5ededfcdc877c7f2989fb1ba02dfb848 Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Mon, 27 May 2024 13:53:52 -0500 Subject: libk: create a subset libc for kernel use Create a subset of the C library for use inside the kernel. Signed-off-by: Danny Holman --- include/libk/container_of.h | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 include/libk/container_of.h (limited to 'include/libk/container_of.h') diff --git a/include/libk/container_of.h b/include/libk/container_of.h new file mode 100644 index 0000000..fdc400c --- /dev/null +++ b/include/libk/container_of.h @@ -0,0 +1,10 @@ +#ifndef LIBK_CONTAINER_OF_H +#define LIBK_CONTAINER_OF_H + +#ifndef container_of +#define container_of(ptr, type, member) ({ \ + const typeof(((type*)0)->member)*__mptr = (ptr); \ + (type*)((char*)__mptr - offsetof(type, member)); }) +#endif + +#endif -- cgit v1.2.3