xref: /aosp_15_r20/external/llvm-libc/src/unistd/linux/sysconf.cpp (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
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 "src/__support/macros/config.h"
14 #include "src/errno/libc_errno.h"
15 #include "src/sys/auxv/getauxval.h"
16 #include <sys/auxv.h>
17 #include <unistd.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