[libc-commits] [libc] [libc] Add loff_t type (PR #204641)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Fri Jun 19 05:53:15 PDT 2026


https://github.com/kaladron updated https://github.com/llvm/llvm-project/pull/204641

>From 968e56ad6e6faa4afafcec965f2ca0a49b4c2c53 Mon Sep 17 00:00:00 2001
From: Jeff Bailey <jbailey at raspberryginger.com>
Date: Thu, 18 Jun 2026 17:57:50 +0100
Subject: [PATCH] [libc] Add loff_t type

Added loff_t type definition. This is a Linux extension required for
large file offsets.

* llvm-libc-types/linux/loff_t.h: Added Linux definition using __kernel_loff_t.
* llvm-libc-types/loff_t.h: Made fallback stub.
* llvm-libc-types/CMakeLists.txt: Conditionally use linux/loff_t.h on Linux.
* sys/types.yaml: Added loff_t to sys/types.
* libc/include/CMakeLists.txt: Added dependency to sys_types target.

Assisted-by: Automated tooling, human reviewed.
---
 libc/include/CMakeLists.txt                 |  1 +
 libc/include/llvm-libc-types/CMakeLists.txt |  5 +++++
 libc/include/llvm-libc-types/linux/loff_t.h | 21 +++++++++++++++++++++
 libc/include/llvm-libc-types/loff_t.h       | 19 +++++++++++++++++++
 libc/include/sys/types.yaml                 |  1 +
 5 files changed, 47 insertions(+)
 create mode 100644 libc/include/llvm-libc-types/linux/loff_t.h
 create mode 100644 libc/include/llvm-libc-types/loff_t.h

diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 549dbd9e4c3f8..8d980cfbd3d0b 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -877,6 +877,7 @@ add_header_macro(
     .llvm-libc-types.gid_t
     .llvm-libc-types.ino_t
     .llvm-libc-types.key_t
+    .llvm-libc-types.loff_t
     .llvm-libc-types.mode_t
     .llvm-libc-types.nlink_t
     .llvm-libc-types.off_t
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 46b0eb7d71183..1bd0b57fd9fc5 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -48,6 +48,11 @@ add_header(
 )
 add_header(ldiv_t HDR ldiv_t.h)
 add_header(lldiv_t HDR lldiv_t.h)
+if(LIBC_TARGET_OS STREQUAL "linux")
+  add_header(loff_t HDR linux/loff_t.h DEST_HDR loff_t.h)
+else()
+  add_header(loff_t HDR loff_t.h)
+endif()
 add_header(FILE HDR FILE.h)
 add_header(fd_set HDR fd_set.h DEPENDS libc.include.llvm-libc-macros.sys_select_macros)
 add_header(fenv_t HDR fenv_t.h)
diff --git a/libc/include/llvm-libc-types/linux/loff_t.h b/libc/include/llvm-libc-types/linux/loff_t.h
new file mode 100644
index 0000000000000..fc3ee674670a3
--- /dev/null
+++ b/libc/include/llvm-libc-types/linux/loff_t.h
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Definition of loff_t type for Linux.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_LOFF_T_H
+#define LLVM_LIBC_TYPES_LOFF_T_H
+
+#include <asm/posix_types.h>
+
+typedef __kernel_loff_t loff_t;
+
+#endif // LLVM_LIBC_TYPES_LOFF_T_H
diff --git a/libc/include/llvm-libc-types/loff_t.h b/libc/include/llvm-libc-types/loff_t.h
new file mode 100644
index 0000000000000..2324af0cdc4a4
--- /dev/null
+++ b/libc/include/llvm-libc-types/loff_t.h
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Fallback definition of loff_t type.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_LOFF_T_H
+#define LLVM_LIBC_TYPES_LOFF_T_H
+
+// loff_t is a Linux-specific type and is not defined on other platforms.
+
+#endif // LLVM_LIBC_TYPES_LOFF_T_H
diff --git a/libc/include/sys/types.yaml b/libc/include/sys/types.yaml
index 605b0c9258841..37c58e708af34 100644
--- a/libc/include/sys/types.yaml
+++ b/libc/include/sys/types.yaml
@@ -9,6 +9,7 @@ types:
   - type_name: gid_t
   - type_name: ino_t
   - type_name: key_t
+  - type_name: loff_t
   - type_name: mode_t
   - type_name: nlink_t
   - type_name: off_t



More information about the libc-commits mailing list