105dc5d92SSchrodinger ZHU Yifan //===-- Linux implementation of fstatvfs ----------------------------------===// 205dc5d92SSchrodinger ZHU Yifan // 305dc5d92SSchrodinger ZHU Yifan // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 405dc5d92SSchrodinger ZHU Yifan // See https://llvm.org/LICENSE.txt for license information. 505dc5d92SSchrodinger ZHU Yifan // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 605dc5d92SSchrodinger ZHU Yifan // 705dc5d92SSchrodinger ZHU Yifan //===----------------------------------------------------------------------===// 805dc5d92SSchrodinger ZHU Yifan 905dc5d92SSchrodinger ZHU Yifan #include "src/sys/statvfs/fstatvfs.h" 1005dc5d92SSchrodinger ZHU Yifan #include "src/__support/common.h" 1105dc5d92SSchrodinger ZHU Yifan #include "src/__support/libc_assert.h" 12*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 1305dc5d92SSchrodinger ZHU Yifan #include "src/sys/statvfs/linux/statfs_utils.h" 1405dc5d92SSchrodinger ZHU Yifan 15*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 1605dc5d92SSchrodinger ZHU Yifan 1705dc5d92SSchrodinger ZHU Yifan LLVM_LIBC_FUNCTION(int, fstatvfs, (int fd, struct statvfs *buf)) { 1805dc5d92SSchrodinger ZHU Yifan using namespace statfs_utils; 1905dc5d92SSchrodinger ZHU Yifan cpp::optional<LinuxStatFs> result = linux_fstatfs(fd); 2005dc5d92SSchrodinger ZHU Yifan if (result) { 2105dc5d92SSchrodinger ZHU Yifan LIBC_ASSERT(buf != nullptr); 2205dc5d92SSchrodinger ZHU Yifan *buf = statfs_to_statvfs(*result); 2305dc5d92SSchrodinger ZHU Yifan } 2405dc5d92SSchrodinger ZHU Yifan return result ? 0 : -1; 2505dc5d92SSchrodinger ZHU Yifan } 2605dc5d92SSchrodinger ZHU Yifan 27*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 28