105dc5d92SSchrodinger ZHU Yifan //===-- Linux implementation of statvfs -----------------------------------===// 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/statvfs.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, statvfs, 1805dc5d92SSchrodinger ZHU Yifan (const char *__restrict path, 1905dc5d92SSchrodinger ZHU Yifan struct statvfs *__restrict buf)) { 2005dc5d92SSchrodinger ZHU Yifan using namespace statfs_utils; 2105dc5d92SSchrodinger ZHU Yifan cpp::optional<LinuxStatFs> result = linux_statfs(path); 2205dc5d92SSchrodinger ZHU Yifan if (result) { 2305dc5d92SSchrodinger ZHU Yifan LIBC_ASSERT(buf != nullptr); 2405dc5d92SSchrodinger ZHU Yifan *buf = statfs_to_statvfs(*result); 2505dc5d92SSchrodinger ZHU Yifan } 2605dc5d92SSchrodinger ZHU Yifan return result ? 0 : -1; 2705dc5d92SSchrodinger ZHU Yifan } 2805dc5d92SSchrodinger ZHU Yifan 29*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 30