brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 979e178 Raw
38 lines · cpp
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-exception6//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/OSUtil/linux/auxv.h"15#include "src/__support/libc_errno.h"16#include "src/__support/macros/config.h"17 18namespace LIBC_NAMESPACE_DECL {19 20LLVM_LIBC_FUNCTION(long, sysconf, (int name)) {21  long ret = 0;22  if (name == _SC_PAGESIZE) {23    cpp::optional<unsigned long> page_size = auxv::get(AT_PAGESZ);24    if (page_size)25      return static_cast<long>(*page_size);26    ret = -1;27  }28 29  // TODO: Complete the rest of the sysconf options.30  if (ret < 0) {31    libc_errno = EINVAL;32    return -1;33  }34  return ret;35}36 37} // namespace LIBC_NAMESPACE_DECL38