1 //===-- Linux implementation of lseek -------------------------------------===// 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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "src/unistd/lseek.h" 10 #include "src/errno/libc_errno.h" 11 12 #include "src/__support/File/linux/lseekImpl.h" 13 #include "src/__support/OSUtil/syscall.h" // For internal syscall function. 14 #include "src/__support/common.h" 15 16 #include <sys/syscall.h> // For syscall numbers. 17 #include <unistd.h> // For off_t. 18 19 namespace LIBC_NAMESPACE { 20 21 LLVM_LIBC_FUNCTION(off_t, lseek, (int fd, off_t offset, int whence)) { 22 auto result = internal::lseekimpl(fd, offset, whence); 23 if (!result.has_value()) { 24 libc_errno = result.error(); 25 return -1; 26 } 27 return result.value(); 28 } 29 30 } // namespace LIBC_NAMESPACE 31