1 //===-- Linux implementation of fstatvfs ----------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "src/sys/statvfs/fstatvfs.h" 10 #include "src/__support/common.h" 11 #include "src/__support/libc_assert.h" 12 #include "src/__support/macros/config.h" 13 #include "src/sys/statvfs/linux/statfs_utils.h" 14 15 namespace LIBC_NAMESPACE_DECL { 16 17 LLVM_LIBC_FUNCTION(int, fstatvfs, (int fd, struct statvfs *buf)) { 18 using namespace statfs_utils; 19 cpp::optional<LinuxStatFs> result = linux_fstatfs(fd); 20 if (result) { 21 LIBC_ASSERT(buf != nullptr); 22 *buf = statfs_to_statvfs(*result); 23 } 24 return result ? 0 : -1; 25 } 26 27 } // namespace LIBC_NAMESPACE_DECL 28