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