From 64818de665560118bec16cb18c1d39abbb3a43e6 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Thu, 29 Jan 2026 17:08:49 +0300 Subject: [PATCH 1/3] added fstat --- runtime-light/k2-platform/k2-api.h | 7 +++++++ runtime-light/k2-platform/k2-header.h | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/runtime-light/k2-platform/k2-api.h b/runtime-light/k2-platform/k2-api.h index 5818964385..9015c6e3c4 100644 --- a/runtime-light/k2-platform/k2-api.h +++ b/runtime-light/k2-platform/k2-api.h @@ -415,6 +415,13 @@ inline auto canonicalize(std::string_view path) noexcept { return return_type{{unique_ptr_type{resolved_path, std::invoke(deleter_creator, resolved_path_len, resolved_path_align)}, resolved_path_len}}; } +inline std::expected k2_fstat(uint64_t fd, struct stat* stat) noexcept { + if (auto error_code{k2_fstat(fd, stat)}; error_code != k2::errno_ok) [[unlikely]] { + return std::unexpected{error_code}; + } + return {}; +} + inline std::expected stat(std::string_view path, struct stat* stat) noexcept { if (auto error_code{k2_stat(path.data(), path.size(), stat)}; error_code != k2::errno_ok) [[unlikely]] { return std::unexpected{error_code}; diff --git a/runtime-light/k2-platform/k2-header.h b/runtime-light/k2-platform/k2-header.h index 5d16c73890..44473b6536 100644 --- a/runtime-light/k2-platform/k2-header.h +++ b/runtime-light/k2-platform/k2-header.h @@ -719,6 +719,11 @@ size_t k2_backtrace(void** buffer, size_t size); */ int32_t k2_canonicalize(const char* path, size_t pathlen, char* const* resolved_path, size_t* resolved_pathlen, size_t* resolved_path_align); +/** + * Semantically equivalent to libc's `fstat`. + */ +int32_t k2_fstat(uint64_t fd, struct stat* statbuf); + /** * Semantically equivalent to libc's `stat`. * From 7bcb8c2e76bb0122d9c6080aa19e27a7fec83010 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Thu, 29 Jan 2026 17:09:51 +0300 Subject: [PATCH 2/3] rename --- runtime-light/k2-platform/k2-api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime-light/k2-platform/k2-api.h b/runtime-light/k2-platform/k2-api.h index 9015c6e3c4..66ebcf5a17 100644 --- a/runtime-light/k2-platform/k2-api.h +++ b/runtime-light/k2-platform/k2-api.h @@ -415,7 +415,7 @@ inline auto canonicalize(std::string_view path) noexcept { return return_type{{unique_ptr_type{resolved_path, std::invoke(deleter_creator, resolved_path_len, resolved_path_align)}, resolved_path_len}}; } -inline std::expected k2_fstat(uint64_t fd, struct stat* stat) noexcept { +inline std::expected fstat(uint64_t fd, struct stat* stat) noexcept { if (auto error_code{k2_fstat(fd, stat)}; error_code != k2::errno_ok) [[unlikely]] { return std::unexpected{error_code}; } From f1a24714181e2d1a78c785f79a61805e0cadc006 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Thu, 29 Jan 2026 22:05:38 +0300 Subject: [PATCH 3/3] minor fix --- runtime-light/k2-platform/k2-api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime-light/k2-platform/k2-api.h b/runtime-light/k2-platform/k2-api.h index 66ebcf5a17..a5b8436c56 100644 --- a/runtime-light/k2-platform/k2-api.h +++ b/runtime-light/k2-platform/k2-api.h @@ -415,7 +415,7 @@ inline auto canonicalize(std::string_view path) noexcept { return return_type{{unique_ptr_type{resolved_path, std::invoke(deleter_creator, resolved_path_len, resolved_path_align)}, resolved_path_len}}; } -inline std::expected fstat(uint64_t fd, struct stat* stat) noexcept { +inline std::expected fstat(k2::descriptor fd, struct stat* stat) noexcept { if (auto error_code{k2_fstat(fd, stat)}; error_code != k2::errno_ok) [[unlikely]] { return std::unexpected{error_code}; }