[libc-commits] [libc] b4b9fbb - [libc] Add a proxy header for sa_family_t (#207736)

via libc-commits libc-commits at lists.llvm.org
Wed Jul 8 04:00:47 PDT 2026


Author: Pavel Labath
Date: 2026-07-08T13:00:39+02:00
New Revision: b4b9fbb56271236f6415403b562c46fcb64016d5

URL: https://github.com/llvm/llvm-project/commit/b4b9fbb56271236f6415403b562c46fcb64016d5
DIFF: https://github.com/llvm/llvm-project/commit/b4b9fbb56271236f6415403b562c46fcb64016d5.diff

LOG: [libc] Add a proxy header for sa_family_t (#207736)

This patch adds `hdr/types/sa_family_t.h` and updates socket tests and
helpers to use it instead of directly including `<sys/socket.h>` or
`include/llvm-libc-types/sa_family_t.h`.

The patch also adds a couple of includes of `hdr/types/socklen_t.h` for
files that are using the type, but not including it directly.

Assisted by Gemini.

Added: 
    libc/hdr/types/sa_family_t.h

Modified: 
    libc/hdr/types/CMakeLists.txt
    libc/test/src/sys/socket/linux/CMakeLists.txt
    libc/test/src/sys/socket/linux/bind_test.cpp
    libc/test/src/sys/socket/linux/connect_accept_test.cpp
    libc/test/src/sys/socket/linux/sockaddr_storage_helper.cpp
    libc/test/src/sys/socket/linux/sockaddr_storage_test.cpp
    libc/test/src/sys/socket/linux/sockname_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 6c645e1b1eb84..5a6b17ef67f2d 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -601,6 +601,14 @@ add_proxy_header_library(
     libc.include.netinet_udp
 )
 
+add_proxy_header_library(
+  sa_family_t
+  HDRS
+    sa_family_t.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.sa_family_t
+    libc.include.sys_socket
+)
 
 add_proxy_header_library(
   socklen_t

diff  --git a/libc/hdr/types/sa_family_t.h b/libc/hdr/types/sa_family_t.h
new file mode 100644
index 0000000000000..af26df226be81
--- /dev/null
+++ b/libc/hdr/types/sa_family_t.h
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Proxy for sa_family_t.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_HDR_TYPES_SA_FAMILY_T_H
+#define LLVM_LIBC_HDR_TYPES_SA_FAMILY_T_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/sa_family_t.h"
+
+#else
+
+#include <sys/socket.h>
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_SA_FAMILY_T_H

diff  --git a/libc/test/src/sys/socket/linux/CMakeLists.txt b/libc/test/src/sys/socket/linux/CMakeLists.txt
index 76585f6b9129d..44b9fea16a40d 100644
--- a/libc/test/src/sys/socket/linux/CMakeLists.txt
+++ b/libc/test/src/sys/socket/linux/CMakeLists.txt
@@ -41,6 +41,7 @@ add_libc_unittest(
     libc.include.sys_socket
     libc.hdr.netinet_in_macros
     libc.hdr.sys_socket_macros
+    libc.hdr.types.sa_family_t
     libc.hdr.types.struct_sockaddr_in
     libc.hdr.types.struct_sockaddr_in6
     libc.hdr.types.struct_sockaddr_un
@@ -67,7 +68,9 @@ add_libc_unittest(
     libc.include.sys_socket
     libc.hdr.fcntl_macros
     libc.hdr.sys_socket_macros
+    libc.hdr.types.sa_family_t
     libc.hdr.types.size_t
+    libc.hdr.types.socklen_t
     libc.hdr.types.struct_sockaddr_un
     libc.src.errno.errno
     libc.src.fcntl.fcntl
@@ -177,6 +180,8 @@ add_libc_unittest(
     .socket_test_support
     libc.include.sys_socket
     libc.hdr.sys_socket_macros
+    libc.hdr.types.sa_family_t
+    libc.hdr.types.socklen_t
     libc.hdr.types.struct_sockaddr_un
     libc.src.errno.errno
     libc.src.sys.socket.accept
@@ -303,6 +308,8 @@ add_libc_unittest(
     sockaddr_storage_test.cpp
     sockaddr_storage_helper.cpp
   DEPENDS
+    libc.hdr.sys_socket_macros
+    libc.hdr.types.sa_family_t
     libc.hdr.types.struct_sockaddr_storage
     libc.hdr.types.struct_sockaddr_un
 )

diff  --git a/libc/test/src/sys/socket/linux/bind_test.cpp b/libc/test/src/sys/socket/linux/bind_test.cpp
index af2b855c7e6c1..6236de08dc3a8 100644
--- a/libc/test/src/sys/socket/linux/bind_test.cpp
+++ b/libc/test/src/sys/socket/linux/bind_test.cpp
@@ -20,6 +20,7 @@
 
 #include "hdr/netinet_in_macros.h"
 #include "hdr/sys_socket_macros.h"
+#include "hdr/types/sa_family_t.h"
 #include "hdr/types/struct_sockaddr_in.h"
 #include "hdr/types/struct_sockaddr_in6.h"
 #include "hdr/types/struct_sockaddr_un.h"

diff  --git a/libc/test/src/sys/socket/linux/connect_accept_test.cpp b/libc/test/src/sys/socket/linux/connect_accept_test.cpp
index 97cf822936cc2..d0446590ffef6 100644
--- a/libc/test/src/sys/socket/linux/connect_accept_test.cpp
+++ b/libc/test/src/sys/socket/linux/connect_accept_test.cpp
@@ -8,7 +8,9 @@
 
 #include "hdr/fcntl_macros.h"
 #include "hdr/sys_socket_macros.h"
+#include "hdr/types/sa_family_t.h"
 #include "hdr/types/size_t.h"
+#include "hdr/types/socklen_t.h"
 #include "hdr/types/struct_sockaddr_un.h"
 #include "src/fcntl/fcntl.h"
 #include "src/stdio/remove.h"

diff  --git a/libc/test/src/sys/socket/linux/sockaddr_storage_helper.cpp b/libc/test/src/sys/socket/linux/sockaddr_storage_helper.cpp
index 0c6d7a128fea0..06f0f1954d60d 100644
--- a/libc/test/src/sys/socket/linux/sockaddr_storage_helper.cpp
+++ b/libc/test/src/sys/socket/linux/sockaddr_storage_helper.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "hdr/sys_socket_macros.h"
+#include "hdr/types/sa_family_t.h"
 #include "hdr/types/struct_sockaddr_storage.h"
 #include "hdr/types/struct_sockaddr_un.h"
-#include "include/llvm-libc-types/sa_family_t.h"
 
 // POSIX requires (and many applications make use of this) the ability to cast
 // one sockaddr pointer to another. This verifies that the compiler does not

diff  --git a/libc/test/src/sys/socket/linux/sockaddr_storage_test.cpp b/libc/test/src/sys/socket/linux/sockaddr_storage_test.cpp
index b95fd5074880b..2b7fbcb22aae8 100644
--- a/libc/test/src/sys/socket/linux/sockaddr_storage_test.cpp
+++ b/libc/test/src/sys/socket/linux/sockaddr_storage_test.cpp
@@ -6,13 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/sys_socket_macros.h"
+#include "hdr/types/sa_family_t.h"
 #include "hdr/types/struct_sockaddr_storage.h"
 #include "hdr/types/struct_sockaddr_un.h"
-
 #include "test/UnitTest/LibcTest.h"
 
-#include <sys/socket.h> // For AF_UNIX
-
 using LlvmLibcSockaddrStorageTest = LIBC_NAMESPACE::testing::Test;
 
 sa_family_t test_sockaddr_aliasing(struct sockaddr_storage *ss,

diff  --git a/libc/test/src/sys/socket/linux/sockname_test.cpp b/libc/test/src/sys/socket/linux/sockname_test.cpp
index 0ee7b5b75bbeb..a13c9233f4e4a 100644
--- a/libc/test/src/sys/socket/linux/sockname_test.cpp
+++ b/libc/test/src/sys/socket/linux/sockname_test.cpp
@@ -12,6 +12,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "hdr/sys_socket_macros.h"
+#include "hdr/types/sa_family_t.h"
+#include "hdr/types/socklen_t.h"
 #include "hdr/types/struct_sockaddr_un.h"
 #include "src/__support/CPP/scope.h"
 #include "src/stdio/remove.h"


        


More information about the libc-commits mailing list