100.00% Lines (8/8)
100.00% Functions (4/4)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | + | // | ||||||
| 2 | + | // Copyright (c) 2026 Michael Vandeberg | ||||||
| 3 | + | // | ||||||
| 4 | + | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||||||
| 5 | + | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||||||
| 6 | + | // | ||||||
| 7 | + | // Official repository: https://github.com/cppalliance/corosio | ||||||
| 8 | + | // | ||||||
| 9 | + | |||||||
| 10 | + | #ifndef BOOST_COROSIO_NATIVE_DETAIL_POSIX_LARGE_FILE_HPP | ||||||
| 11 | + | #define BOOST_COROSIO_NATIVE_DETAIL_POSIX_LARGE_FILE_HPP | ||||||
| 12 | + | |||||||
| 13 | + | #include <boost/corosio/detail/platform.hpp> | ||||||
| 14 | + | |||||||
| 15 | + | #if BOOST_COROSIO_POSIX | ||||||
| 16 | + | |||||||
| 17 | + | #include <fcntl.h> | ||||||
| 18 | + | #include <sys/stat.h> | ||||||
| 19 | + | #include <sys/types.h> | ||||||
| 20 | + | #include <sys/uio.h> | ||||||
| 21 | + | #include <unistd.h> | ||||||
| 22 | + | |||||||
| 23 | + | /* 64-bit file offsets in every build. | ||||||
| 24 | + | |||||||
| 25 | + | 32-bit glibc has a 32-bit off_t unless the including translation | ||||||
| 26 | + | unit defines _FILE_OFFSET_BITS=64, which the library cannot require | ||||||
| 27 | + | of its users. The plain calls then fail past 2 GiB: EOVERFLOW for an | ||||||
| 28 | + | offset that does not fit, and EFBIG for a file opened without | ||||||
| 29 | + | O_LARGEFILE. There the explicit *64 calls and O_LARGEFILE are used. | ||||||
| 30 | + | Everywhere else off_t is already 64-bit, and the plain calls are | ||||||
| 31 | + | kept, so the fault harness's shadows of them still apply. | ||||||
| 32 | + | */ | ||||||
| 33 | + | |||||||
| 34 | + | namespace boost::corosio::detail { | ||||||
| 35 | + | |||||||
| 36 | + | #if defined(__GLIBC__) && !defined(__OFF_T_MATCHES_OFF64_T) | ||||||
| 37 | + | |||||||
| 38 | + | using file_off_t = off64_t; | ||||||
| 39 | + | using file_stat_t = struct stat64; | ||||||
| 40 | + | |||||||
| 41 | + | /// Add to the flags of every open() of a file the library owns. | ||||||
| 42 | + | inline constexpr int large_file_open_flag = O_LARGEFILE; | ||||||
| 43 | + | |||||||
| 44 | + | inline ssize_t | ||||||
| 45 | + | file_preadv(int fd, iovec const* iov, int n, file_off_t off) noexcept | ||||||
| 46 | + | { | ||||||
| 47 | + | return ::preadv64(fd, iov, n, off); | ||||||
| 48 | + | } | ||||||
| 49 | + | |||||||
| 50 | + | inline ssize_t | ||||||
| 51 | + | file_pwritev(int fd, iovec const* iov, int n, file_off_t off) noexcept | ||||||
| 52 | + | { | ||||||
| 53 | + | return ::pwritev64(fd, iov, n, off); | ||||||
| 54 | + | } | ||||||
| 55 | + | |||||||
| 56 | + | inline int | ||||||
| 57 | + | file_fstat(int fd, file_stat_t* st) noexcept | ||||||
| 58 | + | { | ||||||
| 59 | + | return ::fstat64(fd, st); | ||||||
| 60 | + | } | ||||||
| 61 | + | |||||||
| 62 | + | inline int | ||||||
| 63 | + | file_ftruncate(int fd, file_off_t len) noexcept | ||||||
| 64 | + | { | ||||||
| 65 | + | return ::ftruncate64(fd, len); | ||||||
| 66 | + | } | ||||||
| 67 | + | |||||||
| 68 | + | inline file_off_t | ||||||
| 69 | + | file_lseek(int fd, file_off_t off, int whence) noexcept | ||||||
| 70 | + | { | ||||||
| 71 | + | return ::lseek64(fd, off, whence); | ||||||
| 72 | + | } | ||||||
| 73 | + | |||||||
| 74 | + | #else | ||||||
| 75 | + | |||||||
| 76 | + | using file_off_t = off_t; | ||||||
| 77 | + | using file_stat_t = struct stat; | ||||||
| 78 | + | |||||||
| 79 | + | /// Add to the flags of every open() of a file the library owns. | ||||||
| 80 | + | inline constexpr int large_file_open_flag = 0; | ||||||
| 81 | + | |||||||
| 82 | + | inline ssize_t | ||||||
| HITGNC | 83 | + | 414 | file_preadv(int fd, iovec const* iov, int n, file_off_t off) noexcept | ||||
| 84 | + | { | ||||||
| HITGNC | 85 | + | 414 | return ::preadv(fd, iov, n, off); | ||||
| 86 | + | } | ||||||
| 87 | + | |||||||
| 88 | + | inline ssize_t | ||||||
| HITGNC | 89 | + | 70 | file_pwritev(int fd, iovec const* iov, int n, file_off_t off) noexcept | ||||
| 90 | + | { | ||||||
| HITGNC | 91 | + | 70 | return ::pwritev(fd, iov, n, off); | ||||
| 92 | + | } | ||||||
| 93 | + | |||||||
| 94 | + | inline int | ||||||
| HITGNC | 95 | + | 578 | file_fstat(int fd, file_stat_t* st) noexcept | ||||
| 96 | + | { | ||||||
| HITGNC | 97 | + | 578 | return ::fstat(fd, st); | ||||
| 98 | + | } | ||||||
| 99 | + | |||||||
| 100 | + | inline int | ||||||
| HITGNC | 101 | + | 21 | file_ftruncate(int fd, file_off_t len) noexcept | ||||
| 102 | + | { | ||||||
| HITGNC | 103 | + | 21 | return ::ftruncate(fd, len); | ||||
| 104 | + | } | ||||||
| 105 | + | |||||||
| 106 | + | inline file_off_t | ||||||
| 107 | + | file_lseek(int fd, file_off_t off, int whence) noexcept | ||||||
| 108 | + | { | ||||||
| 109 | + | return ::lseek(fd, off, whence); | ||||||
| 110 | + | } | ||||||
| 111 | + | |||||||
| 112 | + | #endif | ||||||
| 113 | + | |||||||
| 114 | + | } // namespace boost::corosio::detail | ||||||
| 115 | + | |||||||
| 116 | + | #endif // BOOST_COROSIO_POSIX | ||||||
| 117 | + | |||||||
| 118 | + | #endif // BOOST_COROSIO_NATIVE_DETAIL_POSIX_LARGE_FILE_HPP | ||||||