36 lines · c
1//===------------ Implementation of getrandom function ----------*- C++ -*-===//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#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_GETRANDOM_H10#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_GETRANDOM_H11 12#include "hdr/types/ssize_t.h"13#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl14#include "src/__support/common.h"15#include "src/__support/error_or.h"16#include "src/__support/macros/config.h"17#include <sys/syscall.h> // For syscall numbers18 19namespace LIBC_NAMESPACE_DECL {20namespace internal {21 22LIBC_INLINE static ErrorOr<ssize_t> getrandom(void *buf, size_t buflen,23 unsigned int flags) {24 ssize_t ret =25 LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_getrandom, buf, buflen, flags);26 if (ret < 0) {27 return Error(-static_cast<int>(ret));28 }29 return ret;30}31 32} // namespace internal33} // namespace LIBC_NAMESPACE_DECL34 35#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_GETRANDOM_H36