[libc-commits] [libc] [libc] Add struct cmsghdr and associated macros (PR #193756)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Thu Apr 23 07:40:03 PDT 2026


================
@@ -50,4 +50,23 @@
 #define SHUT_WR 1
 #define SHUT_RDWR 2
 
+#define SCM_RIGHTS 1
+
+#define CMSG_ALIGN(len) (((len) + sizeof(size_t) - 1) & ~(sizeof(size_t) - 1))
+#define CMSG_LEN(len) (sizeof(struct cmsghdr) + (len))
+#define CMSG_SPACE(len) (sizeof(struct cmsghdr) + CMSG_ALIGN(len))
+
+#define CMSG_FIRSTHDR(msg)                                                     \
----------------
labath wrote:

We'd have to make sure the function compiles both as C and C++, but yes, that should be doable. I haven't seen anybody do it for FIRSTHDR, but there are libcs (glibc included) which do it for NXTHDR.

I don't think it helps much with type safety, as both macros contain direct member access (so the only way this would compile is if a user passes a type with a c which has a `msg_control` member), but I guess the error message could be better.

Would you like me to do that?

https://github.com/llvm/llvm-project/pull/193756


More information about the libc-commits mailing list