1 //===-- Linux implementation of lseek -------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC___SUPPORT_FILE_LINUX_LSEEKIMPL_H
10 #define LLVM_LIBC_SRC___SUPPORT_FILE_LINUX_LSEEKIMPL_H
12 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
13 #include "src/__support/common.h"
14 #include "src/__support/error_or.h"
15 #include "src/errno/libc_errno.h"
17 #include <stdint.h> // For uint64_t.
18 #include <sys/syscall.h> // For syscall numbers.
19 #include <unistd.h> // For off_t.
21 namespace LIBC_NAMESPACE
{
24 LIBC_INLINE ErrorOr
<off_t
> lseekimpl(int fd
, off_t offset
, int whence
) {
27 int ret
= LIBC_NAMESPACE::syscall_impl
<int>(SYS_lseek
, fd
, offset
, whence
);
29 #elif defined(SYS_llseek) || defined(SYS__llseek)
30 static_assert(sizeof(size_t) == 4, "size_t must be 32 bits.");
32 constexpr long LLSEEK_SYSCALL_NO
= SYS_llseek
;
33 #elif defined(SYS__llseek)
34 constexpr long LLSEEK_SYSCALL_NO
= SYS__llseek
;
36 off_t offset_64
= offset
;
37 int ret
= LIBC_NAMESPACE::syscall_impl
<int>(
38 LLSEEK_SYSCALL_NO
, fd
, offset_64
>> 32, offset_64
, &result
, whence
);
40 #error "lseek, llseek and _llseek syscalls not available."
47 } // namespace internal
48 } // namespace LIBC_NAMESPACE
50 #endif // LLVM_LIBC_SRC___SUPPORT_FILE_LINUX_LSEEKIMPL_H