11ac525b2SMichael Jones //===-- Linux implementation of sysconf -----------------------------------===// 21ac525b2SMichael Jones // 31ac525b2SMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 41ac525b2SMichael Jones // See https://llvm.org/LICENSE.txt for license information. 51ac525b2SMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 61ac525b2SMichael Jones // 71ac525b2SMichael Jones //===----------------------------------------------------------------------===// 81ac525b2SMichael Jones 91ac525b2SMichael Jones #include "src/unistd/sysconf.h" 101ac525b2SMichael Jones 111ac525b2SMichael Jones #include "src/__support/common.h" 121ac525b2SMichael Jones 13*7477b61bSTristan Ross #include "hdr/unistd_macros.h" 145ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 15803437dbSMichael Jones #include "src/errno/libc_errno.h" 160cf20c29SSchrodinger ZHU Yifan #include "src/sys/auxv/getauxval.h" 170cf20c29SSchrodinger ZHU Yifan #include <sys/auxv.h> 181ac525b2SMichael Jones 195ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 201ac525b2SMichael Jones 211ac525b2SMichael Jones LLVM_LIBC_FUNCTION(long, sysconf, (int name)) { 221ac525b2SMichael Jones long ret = 0; 230cf20c29SSchrodinger ZHU Yifan if (name == _SC_PAGESIZE) 240cf20c29SSchrodinger ZHU Yifan return static_cast<long>(getauxval(AT_PAGESZ)); 250cf20c29SSchrodinger ZHU Yifan 261ac525b2SMichael Jones // TODO: Complete the rest of the sysconf options. 271ac525b2SMichael Jones if (ret < 0) { 28204587a3SSiva Chandra Reddy libc_errno = EINVAL; 291ac525b2SMichael Jones return -1; 301ac525b2SMichael Jones } 311ac525b2SMichael Jones return ret; 321ac525b2SMichael Jones } 331ac525b2SMichael Jones 345ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 35