[libc-commits] [libc] [libc] Add the htons function family to netinet/in.h (PR #203028)

via libc-commits libc-commits at lists.llvm.org
Thu Jun 11 03:08:07 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Pavel Labath (labath)

<details>
<summary>Changes</summary>

As required by POSIX.

I've used the merge_yaml_files functionality to avoid duplication.

Assisted by Gemini.

---
Full diff: https://github.com/llvm/llvm-project/pull/203028.diff


4 Files Affected:

- (modified) libc/include/arpa/inet.yaml (+2-24) 
- (added) libc/include/htons-family.yaml (+25) 
- (modified) libc/include/netinet/in.yaml (+2) 
- (modified) libc/utils/docgen/netinet/in.yaml (+9) 


``````````diff
diff --git a/libc/include/arpa/inet.yaml b/libc/include/arpa/inet.yaml
index ab7b2e52dd127..38e975c3dfbfd 100644
--- a/libc/include/arpa/inet.yaml
+++ b/libc/include/arpa/inet.yaml
@@ -1,6 +1,8 @@
 header: arpa/inet.h
 standards:
   - posix
+merge_yaml_files:
+  - ../htons-family.yaml
 macros:
   - macro_name: INET_ADDRSTRLEN
     macro_header: inet-address-macros.h
@@ -12,18 +14,6 @@ types:
 enums: []
 objects: []
 functions:
-  - name: htonl
-    standards:
-      - posix
-    return_type: uint32_t
-    arguments:
-      - type: uint32_t
-  - name: htons
-    standards:
-      - posix
-    return_type: uint16_t
-    arguments:
-      - type: uint16_t
   - name: inet_addr
     standards:
       - posix
@@ -37,15 +27,3 @@ functions:
     arguments:
       - type: const char *
       - type: struct in_addr *
-  - name: ntohl
-    standards:
-      - posix
-    return_type: uint32_t
-    arguments:
-      - type: uint32_t
-  - name: ntohs
-    standards:
-      - posix
-    return_type: uint16_t
-    arguments:
-      - type: uint16_t
diff --git a/libc/include/htons-family.yaml b/libc/include/htons-family.yaml
new file mode 100644
index 0000000000000..f6b2ecccf3646
--- /dev/null
+++ b/libc/include/htons-family.yaml
@@ -0,0 +1,25 @@
+functions:
+  - name: htonl
+    standards:
+      - posix
+    return_type: uint32_t
+    arguments:
+      - type: uint32_t
+  - name: htons
+    standards:
+      - posix
+    return_type: uint16_t
+    arguments:
+      - type: uint16_t
+  - name: ntohl
+    standards:
+      - posix
+    return_type: uint32_t
+    arguments:
+      - type: uint32_t
+  - name: ntohs
+    standards:
+      - posix
+    return_type: uint16_t
+    arguments:
+      - type: uint16_t
diff --git a/libc/include/netinet/in.yaml b/libc/include/netinet/in.yaml
index 26e3a7c037c60..c5f24200b72ac 100644
--- a/libc/include/netinet/in.yaml
+++ b/libc/include/netinet/in.yaml
@@ -1,6 +1,8 @@
 header: netinet/in.h
 standards:
   - posix
+merge_yaml_files:
+  - ../htons-family.yaml
 macros:
   - macro_name: IPPROTO_IP
     macro_header: netinet-in-macros.h
diff --git a/libc/utils/docgen/netinet/in.yaml b/libc/utils/docgen/netinet/in.yaml
index 215451858dc15..dd575dcb0f181 100644
--- a/libc/utils/docgen/netinet/in.yaml
+++ b/libc/utils/docgen/netinet/in.yaml
@@ -59,3 +59,12 @@ macros:
     in-latest-posix: ''
   IN6_IS_ADDR_MC_GLOBAL:
     in-latest-posix: ''
+functions:
+  htonl:
+    in-latest-posix: ''
+  htons:
+    in-latest-posix: ''
+  ntohl:
+    in-latest-posix: ''
+  ntohs:
+    in-latest-posix: ''

``````````

</details>


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


More information about the libc-commits mailing list