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"