[libc-commits] [libc] [libc] Clean up sys/resource (PR #161749)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Thu Oct 2 16:08:25 PDT 2025


https://github.com/michaelrj-google created https://github.com/llvm/llvm-project/pull/161749

Needed to support sys/resource in bazel


>From 3af379d2b8519c2cce091c0c0a500f26b9034a30 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Thu, 2 Oct 2025 23:07:45 +0000
Subject: [PATCH] [libc] Clean up sys/resource

Needed to support sys/resource in bazel
---
 libc/hdr/types/CMakeLists.txt                 | 13 +++++++++--
 libc/hdr/types/struct_rlimit.h                | 22 +++++++++++++++++++
 libc/src/sys/resource/linux/CMakeLists.txt    |  2 ++
 libc/src/sys/resource/linux/getrlimit.cpp     |  5 ++---
 libc/src/sys/resource/linux/setrlimit.cpp     |  5 ++---
 libc/test/src/sys/resource/CMakeLists.txt     |  2 --
 .../sys/resource/getrlimit_setrlimit_test.cpp |  7 ++++--
 .../src/sys/resource/testdata/CMakeLists.txt  |  0
 8 files changed, 44 insertions(+), 12 deletions(-)
 create mode 100644 libc/hdr/types/struct_rlimit.h
 delete mode 100644 libc/test/src/sys/resource/testdata/CMakeLists.txt

diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 21971a4004760..225843924c243 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -1,5 +1,5 @@
 add_proxy_header_library(
-  char8_t 
+  char8_t
   HDRS
     char8_t.h
   DEPENDS
@@ -10,7 +10,7 @@ add_proxy_header_library(
 )
 
 add_proxy_header_library(
-  char32_t 
+  char32_t
   HDRS
     char32_t.h
   DEPENDS
@@ -470,3 +470,12 @@ add_proxy_header_library(
     libc.include.llvm-libc-types.dl_info
     libc.include.dlfcn
 )
+
+add_proxy_header_library(
+  struct_rlimit
+  HDRS
+    struct_rlimit.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.struct_rlimit
+    libc.include.sys_resource
+)
diff --git a/libc/hdr/types/struct_rlimit.h b/libc/hdr/types/struct_rlimit.h
new file mode 100644
index 0000000000000..a09dd53ef76e9
--- /dev/null
+++ b/libc/hdr/types/struct_rlimit.h
@@ -0,0 +1,22 @@
+//===-- Proxy for struct rlimit -------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_RLIMIT_H
+#define LLVM_LIBC_HDR_TYPES_STRUCT_RLIMIT_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/struct_rlimit.h"
+
+#else // Overlay mode
+
+#include <sys/resource.h>
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_STRUCT_RLIMIT_H
diff --git a/libc/src/sys/resource/linux/CMakeLists.txt b/libc/src/sys/resource/linux/CMakeLists.txt
index 19f3901c98a29..9f0fdad3b0fdf 100644
--- a/libc/src/sys/resource/linux/CMakeLists.txt
+++ b/libc/src/sys/resource/linux/CMakeLists.txt
@@ -5,6 +5,7 @@ add_entrypoint_object(
   HDRS
     ../getrlimit.h
   DEPENDS
+    libc.hdr.types.struct_rlimit
     libc.include.sys_resource
     libc.include.sys_syscall
     libc.src.__support.OSUtil.osutil
@@ -18,6 +19,7 @@ add_entrypoint_object(
   HDRS
     ../setrlimit.h
   DEPENDS
+    libc.hdr.types.struct_rlimit
     libc.include.sys_resource
     libc.include.sys_syscall
     libc.src.__support.OSUtil.osutil
diff --git a/libc/src/sys/resource/linux/getrlimit.cpp b/libc/src/sys/resource/linux/getrlimit.cpp
index d272134194949..a3234ebf4f90b 100644
--- a/libc/src/sys/resource/linux/getrlimit.cpp
+++ b/libc/src/sys/resource/linux/getrlimit.cpp
@@ -8,13 +8,12 @@
 
 #include "src/sys/resource/getrlimit.h"
 
+#include "hdr/types/struct_rlimit.h"
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
-
 #include "src/__support/libc_errno.h"
 #include "src/__support/macros/config.h"
-#include <sys/resource.h> // For struct rlimit
-#include <sys/syscall.h>  // For syscall numbers.
+#include <sys/syscall.h> // For syscall numbers.
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/src/sys/resource/linux/setrlimit.cpp b/libc/src/sys/resource/linux/setrlimit.cpp
index 300bad75baa63..e2c2b379e7087 100644
--- a/libc/src/sys/resource/linux/setrlimit.cpp
+++ b/libc/src/sys/resource/linux/setrlimit.cpp
@@ -8,13 +8,12 @@
 
 #include "src/sys/resource/setrlimit.h"
 
+#include "hdr/types/struct_rlimit.h"
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
-
 #include "src/__support/libc_errno.h"
 #include "src/__support/macros/config.h"
-#include <sys/resource.h> // For struct rlimit
-#include <sys/syscall.h>  // For syscall numbers.
+#include <sys/syscall.h> // For syscall numbers.
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/test/src/sys/resource/CMakeLists.txt b/libc/test/src/sys/resource/CMakeLists.txt
index 2870f2ca05b5c..2097a2c501fbd 100644
--- a/libc/test/src/sys/resource/CMakeLists.txt
+++ b/libc/test/src/sys/resource/CMakeLists.txt
@@ -1,7 +1,5 @@
 add_custom_target(libc_sys_resource_unittests)
 
-add_subdirectory(testdata)
-
 add_libc_unittest(
   getrlimit_setrlimit_test
   SUITE
diff --git a/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp b/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
index d6e1490e3a101..4e0a3c7d10b5f 100644
--- a/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
+++ b/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
@@ -27,8 +27,11 @@ TEST_F(LlvmLibcResourceLimitsTest, SetNoFileLimit) {
   // successfully. Next, close the files and set the file descriptor limit
   // to 4. This will allow us to open one of those file but not the other.
 
-  constexpr const char *TEST_FILE1 = "testdata/resource_limits1.test";
-  constexpr const char *TEST_FILE2 = "testdata/resource_limits2.test";
+  constexpr const char *TEST_FILE1_NAME = "resource_limits1.test";
+  constexpr const char *TEST_FILE2_NAME = "resource_limits2.test";
+
+  auto TEST_FILE1 = libc_make_test_file_path(TEST_FILE1_NAME);
+  auto TEST_FILE2 = libc_make_test_file_path(TEST_FILE2_NAME);
 
   int fd1 = LIBC_NAMESPACE::open(TEST_FILE1, O_CREAT | O_WRONLY, S_IRWXU);
   ASSERT_GT(fd1, 0);
diff --git a/libc/test/src/sys/resource/testdata/CMakeLists.txt b/libc/test/src/sys/resource/testdata/CMakeLists.txt
deleted file mode 100644
index e69de29bb2d1d..0000000000000



More information about the libc-commits mailing list