-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc] Implemented utimes (Issue #133953) #134167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
61ea09a
Adding utimes, tests left
hoarfrost32 b19363d
added tests
hoarfrost32 da4cee3
added tests
hoarfrost32 0a12455
[libc] Implement utimes (https://github.com/llvm/llvm-project/issues/…
hoarfrost32 c645ddf
[libc] Code cleaning, formatting and refactoring
hoarfrost32 f59b93c
[libc] clang-format
hoarfrost32 39d9932
[libc] Ensured proper formatting of files
hoarfrost32 14d44e6
[libc] matched int types in utimes_test, cleaned up time.yaml
hoarfrost32 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # This is the CMakeCache file. | ||
| # For build in directory: /home/hoarfrost/Projects/llvm/llvm-project/__cmake_systeminformation | ||
| # It was generated by CMake: /nix/store/ciiwq1ymzac9m5azhf4higkynmy3f8f7-cmake-3.31.5/bin/cmake | ||
| # You can edit this file to change values found and used by cmake. | ||
| # If you do not want to change any of the values, simply exit the editor. | ||
| # If you do want to change a value, simply edit, save, and exit the editor. | ||
| # The syntax for the file is as follows: | ||
| # KEY:TYPE=VALUE | ||
| # KEY is the name of a variable in the cache. | ||
| # TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. | ||
| # VALUE is the current value for the KEY. | ||
|
|
||
| ######################## | ||
| # EXTERNAL cache entries | ||
| ######################## | ||
|
|
||
| //Value Computed by CMake. | ||
| CMAKE_FIND_PACKAGE_REDIRECTS_DIR:STATIC=/home/hoarfrost/Projects/llvm/llvm-project/__cmake_systeminformation/CMakeFiles/pkgRedirects | ||
|
|
||
| //Path to a program. | ||
| CMAKE_MAKE_PROGRAM:FILEPATH=CMAKE_MAKE_PROGRAM-NOTFOUND | ||
|
|
||
| //Value Computed by CMake | ||
| CMAKE_PROJECT_DESCRIPTION:STATIC= | ||
|
|
||
| //Value Computed by CMake | ||
| CMAKE_PROJECT_HOMEPAGE_URL:STATIC= | ||
|
|
||
| //Value Computed by CMake | ||
| CMAKE_PROJECT_NAME:STATIC=DumpInformation | ||
|
|
||
| //Value Computed by CMake | ||
| DumpInformation_BINARY_DIR:STATIC=/home/hoarfrost/Projects/llvm/llvm-project/__cmake_systeminformation | ||
|
|
||
| //Value Computed by CMake | ||
| DumpInformation_IS_TOP_LEVEL:STATIC=ON | ||
|
|
||
| //Value Computed by CMake | ||
| DumpInformation_SOURCE_DIR:STATIC=/home/hoarfrost/Projects/llvm/llvm-project/__cmake_systeminformation | ||
|
|
||
| //No help, variable specified on the command line. | ||
| RESULT_FILE:UNINITIALIZED=/home/hoarfrost/Projects/llvm/llvm-project/__cmake_systeminformation/results.txt | ||
|
|
||
|
|
||
| ######################## | ||
| # INTERNAL cache entries | ||
| ######################## | ||
|
|
||
| //This is the directory where this CMakeCache.txt was created | ||
| CMAKE_CACHEFILE_DIR:INTERNAL=/home/hoarfrost/Projects/llvm/llvm-project/__cmake_systeminformation | ||
| //Major version of cmake used to create the current loaded cache | ||
| CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 | ||
| //Minor version of cmake used to create the current loaded cache | ||
| CMAKE_CACHE_MINOR_VERSION:INTERNAL=31 | ||
| //Patch version of cmake used to create the current loaded cache | ||
| CMAKE_CACHE_PATCH_VERSION:INTERNAL=5 | ||
| //Path to CMake executable. | ||
| CMAKE_COMMAND:INTERNAL=/nix/store/ciiwq1ymzac9m5azhf4higkynmy3f8f7-cmake-3.31.5/bin/cmake | ||
| //Path to cpack program executable. | ||
| CMAKE_CPACK_COMMAND:INTERNAL=/nix/store/ciiwq1ymzac9m5azhf4higkynmy3f8f7-cmake-3.31.5/bin/cpack | ||
| //Path to ctest program executable. | ||
| CMAKE_CTEST_COMMAND:INTERNAL=/nix/store/ciiwq1ymzac9m5azhf4higkynmy3f8f7-cmake-3.31.5/bin/ctest | ||
| //Name of external makefile project generator. | ||
| CMAKE_EXTRA_GENERATOR:INTERNAL= | ||
| //Name of generator. | ||
| CMAKE_GENERATOR:INTERNAL=Unix Makefiles | ||
| //Generator instance identifier. | ||
| CMAKE_GENERATOR_INSTANCE:INTERNAL= | ||
| //Name of generator platform. | ||
| CMAKE_GENERATOR_PLATFORM:INTERNAL= | ||
| //Name of generator toolset. | ||
| CMAKE_GENERATOR_TOOLSET:INTERNAL= | ||
| //Source directory with the top level CMakeLists.txt file for this | ||
| // project | ||
| CMAKE_HOME_DIRECTORY:INTERNAL=/home/hoarfrost/Projects/llvm/llvm-project/__cmake_systeminformation | ||
| //ADVANCED property for variable: CMAKE_MAKE_PROGRAM | ||
| CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1 | ||
| //number of local generators | ||
| CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=1 | ||
| //Platform information initialized | ||
| CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1 | ||
| //Path to CMake installation. | ||
| CMAKE_ROOT:INTERNAL=/nix/store/ciiwq1ymzac9m5azhf4higkynmy3f8f7-cmake-3.31.5/share/cmake-3.31 | ||
| //uname command | ||
| CMAKE_UNAME:INTERNAL=/usr/bin/uname | ||
|
|
||
15 changes: 15 additions & 0 deletions
15
__cmake_systeminformation/CMakeFiles/3.31.5/CMakeSystem.cmake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| set(CMAKE_HOST_SYSTEM "Linux-6.12.20") | ||
| set(CMAKE_HOST_SYSTEM_NAME "Linux") | ||
| set(CMAKE_HOST_SYSTEM_VERSION "6.12.20") | ||
| set(CMAKE_HOST_SYSTEM_PROCESSOR "x86_64") | ||
|
|
||
|
|
||
|
|
||
| set(CMAKE_SYSTEM "Linux-6.12.20") | ||
| set(CMAKE_SYSTEM_NAME "Linux") | ||
| set(CMAKE_SYSTEM_VERSION "6.12.20") | ||
| set(CMAKE_SYSTEM_PROCESSOR "x86_64") | ||
|
|
||
| set(CMAKE_CROSSCOMPILING "FALSE") | ||
|
|
||
| set(CMAKE_SYSTEM_LOADED 1) |
11 changes: 11 additions & 0 deletions
11
__cmake_systeminformation/CMakeFiles/CMakeConfigureLog.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
|
|
||
| --- | ||
| events: | ||
| - | ||
| kind: "message-v1" | ||
| backtrace: | ||
| - "/nix/store/ciiwq1ymzac9m5azhf4higkynmy3f8f7-cmake-3.31.5/share/cmake-3.31/Modules/CMakeDetermineSystem.cmake:205 (message)" | ||
| - "CMakeLists.txt:6 (project)" | ||
| message: | | ||
| The system is: Linux - 6.12.20 - x86_64 | ||
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # This file is generated by cmake for dependency checking of the CMakeCache.txt file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # Distributed under the OSI-approved BSD 3-Clause License. See accompanying | ||
| # file Copyright.txt or https://cmake.org/licensing for details. | ||
|
|
||
|
|
||
| cmake_minimum_required(VERSION ${CMAKE_VERSION}) | ||
| project(DumpInformation) | ||
|
|
||
| # first get the standard information for the platform | ||
| include_directories("This does not exist") | ||
| get_directory_property(incl INCLUDE_DIRECTORIES) | ||
| set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES "${DumpInformation_BINARY_DIR};${DumpInformation_SOURCE_DIR}") | ||
|
|
||
| configure_file("${CMAKE_ROOT}/Modules/SystemInformation.in" "${RESULT_FILE}") | ||
|
|
||
|
|
||
| file(APPEND "${RESULT_FILE}" | ||
| "\n=================================================================\n") | ||
| file(APPEND "${RESULT_FILE}" | ||
| "=== VARIABLES\n") | ||
| file(APPEND "${RESULT_FILE}" | ||
| "=================================================================\n") | ||
| get_cmake_property(res VARIABLES) | ||
| foreach(var ${res}) | ||
| file(APPEND "${RESULT_FILE}" "${var} \"${${var}}\"\n") | ||
| endforeach() | ||
|
|
||
| file(APPEND "${RESULT_FILE}" | ||
| "\n=================================================================\n") | ||
| file(APPEND "${RESULT_FILE}" | ||
| "=== COMMANDS\n") | ||
| file(APPEND "${RESULT_FILE}" | ||
| "=================================================================\n") | ||
| get_cmake_property(res COMMANDS) | ||
| foreach(var ${res}) | ||
| file(APPEND "${RESULT_FILE}" "${var}\n") | ||
| endforeach() | ||
|
|
||
| file(APPEND "${RESULT_FILE}" | ||
| "\n=================================================================\n") | ||
| file(APPEND "${RESULT_FILE}" | ||
| "=== MACROS\n") | ||
| file(APPEND "${RESULT_FILE}" | ||
| "=================================================================\n") | ||
| file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/AllMacros.txt "") | ||
| get_cmake_property(res MACROS) | ||
| foreach(var ${res}) | ||
| file(APPEND "${RESULT_FILE}" "${var}\n") | ||
| endforeach() | ||
|
|
||
| file(APPEND "${RESULT_FILE}" | ||
| "\n=================================================================\n") | ||
| file(APPEND "${RESULT_FILE}" | ||
| "=== OTHER\n") | ||
| file(APPEND "${RESULT_FILE}" | ||
| "=================================================================\n") | ||
| get_directory_property(res INCLUDE_DIRECTORIES) | ||
| foreach(var ${res}) | ||
| file(APPEND "${RESULT_FILE}" "INCLUDE_DIRECTORY: ${var}\n") | ||
| endforeach() | ||
|
|
||
| get_directory_property(res LINK_DIRECTORIES) | ||
| foreach(var ${res}) | ||
| file(APPEND "${RESULT_FILE}" "LINK_DIRECTORIES: ${var}\n") | ||
| endforeach() | ||
|
|
||
| get_directory_property(res INCLUDE_REGULAR_EXPRESSION) | ||
| file(APPEND "${RESULT_FILE}" "INCLUDE_REGULAR_EXPRESSION: ${res}\n") | ||
|
|
||
| # include other files if they are present, such as when run from within the | ||
| # binary tree | ||
| macro(DUMP_FILE THE_FILE) | ||
| if (EXISTS "${THE_FILE}") | ||
| file(APPEND "${RESULT_FILE}" | ||
| "\n=================================================================\n") | ||
| file(APPEND "${RESULT_FILE}" | ||
| "=== ${THE_FILE}\n") | ||
| file(APPEND "${RESULT_FILE}" | ||
| "=================================================================\n") | ||
|
|
||
| file(READ "${THE_FILE}" FILE_CONTENTS LIMIT 50000) | ||
| file(APPEND "${RESULT_FILE}" "${FILE_CONTENTS}") | ||
| endif () | ||
| endmacro() | ||
|
|
||
| DUMP_FILE("../CMakeCache.txt") | ||
| DUMP_FILE("../CMakeFiles/CMakeSystem.cmake") | ||
|
|
||
| foreach (EXTRA_FILE ${EXTRA_DUMP_FILES}) | ||
| DUMP_FILE("${EXTRA_FILE}") | ||
| endforeach () | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| add_entrypoint_object( | ||
| utimes | ||
| SRCS | ||
| utimes.cpp | ||
| HDRS | ||
| ../utimes.h | ||
| DEPENDS | ||
| libc.hdr.types.struct_timeval | ||
| libc.src.__support.OSUtil.osutil | ||
| libc.include.sys_stat | ||
| libc.include.sys_syscall | ||
| libc.include.fcntl | ||
| libc.src.__support.OSUtil.osutil | ||
| libc.src.errno.errno | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| //===-- Linux implementation of utimes -------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===/ | ||
|
|
||
| #include "src/sys/time/utimes.h" | ||
|
|
||
| #include "hdr/types/struct_timeval.h" | ||
|
|
||
| #include "src/__support/OSUtil/syscall.h" | ||
| #include "src/__support/common.h" | ||
|
|
||
| #include "src/errno/libc_errno.h" | ||
|
|
||
| #include <cerrno> | ||
| #include <sys/syscall.h> | ||
| #include <sys/stat.h> | ||
| #include <fcntl.h> | ||
hoarfrost32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, utimes, (const char *path, const struct timeval times[2])) { | ||
hoarfrost32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| int ret; | ||
|
|
||
| #ifdef SYS_utimensat | ||
| //the utimensat syscall requires a timespec struct, not timeval. | ||
| struct timespec ts[2]; | ||
| struct timespec *ts_ptr = nullptr; // default value if times is NULL | ||
|
|
||
| // convert the microsec values in timeval struct times | ||
| // to nanosecond values in timespec struct ts | ||
| if (times != NULL) { | ||
|
|
||
| // ensure consistent values | ||
| if ((times[0].tv_usec < 0 || times[1].tv_usec < 0) || | ||
| (times[0].tv_usec >= 1000000 || times[1].tv_usec >= 1000000)) { | ||
| libc_errno = EINVAL; | ||
| return -1; | ||
| } | ||
|
|
||
| // set seconds in ts | ||
| ts[0].tv_sec = times[0].tv_sec; | ||
| ts[1].tv_sec = times[1].tv_sec; | ||
|
|
||
| // convert u-seconds to nanoseconds | ||
| ts[0].tv_nsec = times[0].tv_usec * 1000; | ||
| ts[1].tv_nsec = times[1].tv_usec * 1000; | ||
|
|
||
| ts_ptr = ts; | ||
| } | ||
|
|
||
| // If times was NULL, ts_ptr remains NULL, which utimensat interprets | ||
| // as setting times to the current time. | ||
|
|
||
| // utimensat syscall. | ||
| // flags=0 means don't follow symlinks (like utimes) | ||
| ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_utimensat, AT_FDCWD, path, | ||
| ts_ptr, 0); | ||
|
|
||
| #elif defined(SYS_utimes) | ||
hoarfrost32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // No need to define a timespec struct, use the syscall directly. | ||
| ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_utimes, path, times); | ||
| #else | ||
| #error "utimensat and utimes syscalls not available." | ||
| // To avoid compilation errors when neither is defined, return an error. | ||
| libc_errno = ENOSYS; // Function not implemented | ||
| return -1; | ||
hoarfrost32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #endif // SYS_utimensat | ||
|
|
||
| if (ret < 0) { | ||
| libc_errno = -ret; | ||
| return -1; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //===-- Implementation header for utimes -----------------------------------===// | ||
hoarfrost32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // | ||
| // 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 | ||
|
|
||
| #include "hdr/types/struct_timeval.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| int utimes(const char *path, const struct timeval times[2]); | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_LIBC_SRC_SYS_TIME_UTIMES_H | ||
hoarfrost32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| add_custom_target(libc_sys_time_unittests) | ||
|
|
||
| add_subdirectory(testdata) | ||
|
|
||
| add_libc_unittest( | ||
| utimes_test | ||
| SUITE | ||
| libc_sys_time_unittests | ||
| SRCS | ||
| utimes_test.cpp | ||
| DEPENDS | ||
| libc.hdr.fcntl_macros | ||
| libc.include.sys_stat | ||
| libc.src.errno.errno | ||
| libc.src.fcntl.open | ||
| libc.src.sys.time.utimes | ||
| libc.src.unistd.close | ||
| libc.src.unistd.read | ||
| libc.src.unistd.unlink | ||
hoarfrost32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| libc.src.unistd.write | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.