Skip to content

Commit bcdece1

Browse files
authored
[k2] add fstat (#1515)
1 parent 24b3128 commit bcdece1

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

runtime-light/k2-platform/k2-api.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,13 @@ inline auto canonicalize(std::string_view path) noexcept {
426426
return return_type{{unique_ptr_type{resolved_path, std::invoke(deleter_creator, resolved_path_len, resolved_path_align)}, resolved_path_len}};
427427
}
428428

429+
inline std::expected<void, int32_t> fstat(k2::descriptor fd, struct stat* stat) noexcept {
430+
if (auto error_code{k2_fstat(fd, stat)}; error_code != k2::errno_ok) [[unlikely]] {
431+
return std::unexpected{error_code};
432+
}
433+
return {};
434+
}
435+
429436
inline std::expected<void, int32_t> stat(std::string_view path, struct stat* stat) noexcept {
430437
if (auto error_code{k2_stat(path.data(), path.size(), stat)}; error_code != k2::errno_ok) [[unlikely]] {
431438
return std::unexpected{error_code};

runtime-light/k2-platform/k2-header.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,11 @@ size_t k2_backtrace(void** buffer, size_t size);
732732
*/
733733
int32_t k2_canonicalize(const char* path, size_t pathlen, char* const* resolved_path, size_t* resolved_pathlen, size_t* resolved_path_align);
734734

735+
/**
736+
* Semantically equivalent to libc's `fstat`.
737+
*/
738+
int32_t k2_fstat(uint64_t fd, struct stat* statbuf);
739+
735740
/**
736741
* Semantically equivalent to libc's `stat`.
737742
*

0 commit comments

Comments
 (0)