1 | //===-- Linux implementation of sysconf -----------------------------------===// |
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/unistd/sysconf.h" |
10 | |
11 | #include "src/__support/common.h" |
12 | |
13 | #include "hdr/unistd_macros.h" |
14 | #include "src/__support/libc_errno.h" |
15 | #include "src/__support/macros/config.h" |
16 | #include "src/sys/auxv/getauxval.h" |
17 | #include <sys/auxv.h> |
18 | |
19 | namespace LIBC_NAMESPACE_DECL { |
20 | |
21 | LLVM_LIBC_FUNCTION(long, sysconf, (int name)) { |
22 | long ret = 0; |
23 | if (name == _SC_PAGESIZE) |
24 | return static_cast<long>(getauxval(AT_PAGESZ)); |
25 | |
26 | // TODO: Complete the rest of the sysconf options. |
27 | if (ret < 0) { |
28 | libc_errno = EINVAL; |
29 | return -1; |
30 | } |
31 | return ret; |
32 | } |
33 | |
34 | } // namespace LIBC_NAMESPACE_DECL |
35 | |