diff --git a/runtime-light/k2-platform/k2-api.h b/runtime-light/k2-platform/k2-api.h index 5818964385..a5b8436c56 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 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}; + } + 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`. *