brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 9bb669c Raw
37 lines · cpp
1//===---------- Linux implementation of the ioctl function ----------------===//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/sys/ioctl/ioctl.h"10 11#include "src/__support/OSUtil/syscall.h" // For internal syscall function.12#include "src/__support/common.h"13#include "src/__support/libc_errno.h"14#include <stdarg.h>15#include <sys/syscall.h> // For syscall numbers.16 17namespace LIBC_NAMESPACE_DECL {18 19LLVM_LIBC_FUNCTION(int, ioctl, (int fd, unsigned long request, ...)) {20  va_list vargs;21  va_start(vargs, request);22  void *data_pointer = va_arg(vargs, void *);23  int ret =24      LIBC_NAMESPACE::syscall_impl<int>(SYS_ioctl, fd, request, data_pointer);25  va_end(vargs);26 27  // Some ioctls can be expected to return positive values28  if (ret >= 0)29    return ret;30 31  // If there is an error, errno is set and -1 is returned.32  libc_errno = -ret;33  return -1;34}35 36} // namespace LIBC_NAMESPACE_DECL37