[libc-commits] [libc] [libc] Add `utimes` function (PR #97530)

Izaak Schroeder via libc-commits libc-commits at lists.llvm.org
Wed Jul 3 00:04:34 PDT 2024


https://github.com/izaakschroeder created https://github.com/llvm/llvm-project/pull/97530

Implementation needed, definition provided.

>From 9c4af3032093c8bb27eab31a16fd956e96181a32 Mon Sep 17 00:00:00 2001
From: Izaak Schroeder <izaak.schroeder at gmail.com>
Date: Mon, 1 Jul 2024 12:07:37 -0700
Subject: [PATCH] [libc] Add `utimes` function

---
 libc/config/linux/aarch64/entrypoints.txt |  3 +++
 libc/config/linux/x86_64/entrypoints.txt  |  3 +++
 libc/spec/linux.td                        | 11 ++++++++++-
 libc/spec/spec.td                         |  1 +
 libc/src/sys/CMakeLists.txt               |  1 +
 libc/src/sys/time/CMakeLists.txt          | 10 ++++++++++
 libc/src/sys/time/linux/CMakeLists.txt    | 12 ++++++++++++
 libc/src/sys/time/linux/utimes.cpp        | 12 ++++++++++++
 libc/src/sys/time/utimes.h                | 18 ++++++++++++++++++
 9 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 libc/src/sys/time/CMakeLists.txt
 create mode 100644 libc/src/sys/time/linux/CMakeLists.txt
 create mode 100644 libc/src/sys/time/linux/utimes.cpp
 create mode 100644 libc/src/sys/time/utimes.h

diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 940df63e3912b..0e158ff9c1c05 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -242,6 +242,9 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.sys.stat.mkdirat
     libc.src.sys.stat.stat
 
+    # sys/time.h entrypoints
+    libc.src.sys.time.utimes
+
     # sys/utsname.h entrypoints
     libc.src.sys.utsname.uname
 
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 09f04fb31dfd8..1c5bec7626654 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -266,6 +266,9 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.sys.statvfs.fstatvfs
     libc.src.sys.statvfs.statvfs
 
+    # sys/time.h entrypoints
+    libc.src.sys.time.utimes
+
     # sys/utsname.h entrypoints
     libc.src.sys.utsname.uname
 
diff --git a/libc/spec/linux.td b/libc/spec/linux.td
index 82630ff413c73..191fd73adec60 100644
--- a/libc/spec/linux.td
+++ b/libc/spec/linux.td
@@ -148,7 +148,16 @@ def Linux : StandardSpec<"Linux"> {
       ],
       [StructTimevalType], // Types
       [], // Enumerations
-      []  // Functions
+      [
+        FunctionSpec<
+          "utimes",
+          RetValSpec<IntType>,
+          [
+            ArgSpec<ConstCharPtr>,
+            ArgSpec<ConstStructTimevalPtr>,
+          ]
+        >,
+      ]  // Functions
   >;
 
 
diff --git a/libc/spec/spec.td b/libc/spec/spec.td
index a3a5db7465b39..17c0589ab1d55 100644
--- a/libc/spec/spec.td
+++ b/libc/spec/spec.td
@@ -148,6 +148,7 @@ def StructRUsagePtr : PtrType<StructRUsage>;
 
 def StructTimevalType : NamedType<"struct timeval">;
 def StructTimevalPtr : PtrType<StructTimevalType>;
+def ConstStructTimevalPtr : ConstType<StructTimevalPtr>;
 def RestrictedStructTimevalPtr : RestrictedPtrType<StructTimevalType>;
 
 def SuSecondsT : NamedType<"suseconds_t">;
diff --git a/libc/src/sys/CMakeLists.txt b/libc/src/sys/CMakeLists.txt
index adc666b94202f..fba5f86d0b08c 100644
--- a/libc/src/sys/CMakeLists.txt
+++ b/libc/src/sys/CMakeLists.txt
@@ -11,3 +11,4 @@ add_subdirectory(statvfs)
 add_subdirectory(utsname)
 add_subdirectory(wait)
 add_subdirectory(prctl)
+add_subdirectory(time)
diff --git a/libc/src/sys/time/CMakeLists.txt b/libc/src/sys/time/CMakeLists.txt
new file mode 100644
index 0000000000000..f599cddaaeeb3
--- /dev/null
+++ b/libc/src/sys/time/CMakeLists.txt
@@ -0,0 +1,10 @@
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
+endif()
+
+add_entrypoint_object(
+  utimes
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.utimes
+)
diff --git a/libc/src/sys/time/linux/CMakeLists.txt b/libc/src/sys/time/linux/CMakeLists.txt
new file mode 100644
index 0000000000000..da5f698e3515c
--- /dev/null
+++ b/libc/src/sys/time/linux/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_entrypoint_object(
+  utimes
+  SRCS
+    utimes.cpp
+  HDRS
+    ../utimes.h
+  DEPENDS
+    libc.include.sys_time
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
+    libc.src.errno.errno
+)
diff --git a/libc/src/sys/time/linux/utimes.cpp b/libc/src/sys/time/linux/utimes.cpp
new file mode 100644
index 0000000000000..acf318bec7d91
--- /dev/null
+++ b/libc/src/sys/time/linux/utimes.cpp
@@ -0,0 +1,12 @@
+#include "src/sys/time/utimes.h"
+
+#include "src/__support/common.h"
+#include "src/errno/libc_errno.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(int, utimes, (const char *, const struct timeval[2])) {
+  return EINVAL;
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/sys/time/utimes.h b/libc/src/sys/time/utimes.h
new file mode 100644
index 0000000000000..93d5d4d1e9aef
--- /dev/null
+++ b/libc/src/sys/time/utimes.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for socket ------------------------*- C++ -*-===//
+//
+// 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_SRC_SYS_TIME_UTIMES_H
+#define LLVM_LIBC_SRC_SYS_TIME_UTIMES_H
+
+namespace LIBC_NAMESPACE {
+
+int utimes(const char *pathname, const struct timeval times[2]);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_SYS_TIME_UTIMES_H



More information about the libc-commits mailing list