From 487ef48d2f727beb32081bab5f61372159f0533d Mon Sep 17 00:00:00 2001 From: vasilito Date: Mon, 3 Aug 2026 10:21:56 +0300 Subject: [PATCH] sys/un.h: define SUN_LEN SUN_LEN is not in the POSIX spec but is a long-standing BSD/glibc extension that portable AF_UNIX socket code depends on. KWin's src/helpers/wayland_wrapper/wl-socket.c calls it directly and fails with error: implicit declaration of function 'SUN_LEN' Definition matches glibc: offset of sun_path plus strlen of the pathname it holds, i.e. the byte count to pass to bind()/connect() for an AF_UNIX address. Pulls in for strlen. --- src/header/sys_un/cbindgen.toml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/header/sys_un/cbindgen.toml b/src/header/sys_un/cbindgen.toml index af00db5f3e..8a8fd7c711 100644 --- a/src/header/sys_un/cbindgen.toml +++ b/src/header/sys_un/cbindgen.toml @@ -4,6 +4,22 @@ # - "The header shall define the sa_family_t type as described in ." after_includes = """ #include // for sa_family_t from sys/socket.h +#include // for strlen() used by SUN_LEN + +/* + * SUN_LEN() is not in the POSIX spec, but it is a long-standing + * BSD/glibc extension that portable Wayland/X11 socket code relies on: + * KWin's src/helpers/wayland_wrapper/wl-socket.c calls it directly and + * otherwise fails with + * error: implicit declaration of function 'SUN_LEN' + * The definition matches glibc's: offset of sun_path plus the length of the + * pathname it holds, giving the number of bytes to pass to bind()/connect() + * for an AF_UNIX address. + */ +#ifndef SUN_LEN +#define SUN_LEN(ptr) \\ + ((size_t)(((struct sockaddr_un *)0)->sun_path) + strlen((ptr)->sun_path)) +#endif """ include_guard = "_RELIBC_SYS_UN_H" language = "C"