23 #if defined(S_IREAD) && defined(S_IWRITE) 24 #define USER_FLAGS (S_IREAD | S_IWRITE) 25 #elif defined(S_IRUSR) && defined(S_IWUSR) 26 #define USER_FLAGS (S_IRUSR | S_IWUSR) 28 #define USER_FLAGS (0) 33 "FwSizeType is not large enough to store values of type off_t");
35 "FwSizeType is not large enough to store values of type ssize_t");
38 static_assert(std::numeric_limits<FwSignedSizeType>::max() >= std::numeric_limits<off_t>::max(),
39 "Maximum value of FwSizeType less than the maximum value of off_t. Configure a larger type.");
40 static_assert(std::numeric_limits<FwSignedSizeType>::max() >= std::numeric_limits<ssize_t>::max(),
41 "Maximum value of FwSizeType less than the maximum value of ssize_t. Configure a larger type.");
43 "Minimum value of FwSizeType larger than the minimum value of off_t. Configure a larger type.");
45 "Minimum value of FwSizeType larger than the minimum value of ssize_t. Configure a larger type.");
63 PlatformIntType mode_flags = 0;
65 switch (requested_mode) {
67 mode_flags = O_RDONLY;
70 mode_flags = O_WRONLY | O_CREAT;
73 mode_flags = O_WRONLY | O_CREAT | O_SYNC;
77 O_WRONLY | O_CREAT | O_TRUNC | ((overwrite == PosixFile::OverwriteType::OVERWRITE) ? 0 : O_EXCL);
80 mode_flags = O_WRONLY | O_CREAT | O_APPEND;
88 PlatformIntType errno_store = errno;
111 PlatformIntType errno_store = errno;
115 off_t original = ::lseek(this->m_handle.
m_file_descriptor, static_cast<off_t>(current_position), SEEK_SET);
117 PlatformIntType errno_store = errno;
121 size_result = end_of_file;
131 PlatformIntType errno_store = errno;
144 #if _POSIX_C_SOURCE >= 200112L 145 PlatformIntType errno_status = ::posix_fallocate(this->m_handle.
m_file_descriptor, static_cast<off_t>(offset), static_cast<off_t>(length));
149 if (Os::File::Status::NOT_SUPPORTED == status) {
152 status = this->
size(file_size);
156 status = this->
position(file_position);
159 if ((std::numeric_limits<FwSignedSizeType>::max() - offset - length) < 0) {
161 }
else if (file_size < (offset + length)) {
163 status = this->
seek(file_size, PosixFile::SeekType::ABSOLUTE);
168 status = this->
write(reinterpret_cast<const U8*>(
"\0"), write_size,
169 PosixFile::WaitType::NO_WAIT);
176 status = this->
seek(file_position, PosixFile::SeekType::ABSOLUTE);
189 ::lseek(this->m_handle.
m_file_descriptor, static_cast<off_t>(offset), (seekType == SeekType::ABSOLUTE) ? SEEK_SET : SEEK_CUR);
190 PlatformIntType errno_store = errno;
193 }
else if ((seekType == SeekType::ABSOLUTE) && (actual != offset)) {
202 PlatformIntType errno_store = errno;
213 ? std::numeric_limits<FwSignedSizeType>::max()
219 static_cast<size_t>(
size - accumulated));
222 PlatformIntType errno_store = errno;
224 if (EINTR != errno_store) {
231 else if (read_size == 0) {
234 accumulated += read_size;
249 ? std::numeric_limits<FwSignedSizeType>::max()
256 static_cast<size_t>(
size - accumulated));
259 PlatformIntType errno_store = errno;
261 if (EINTR != errno_store) {
267 accumulated += write_size;
274 PlatformIntType errno_store = errno;
282 return &this->m_handle;
static constexpr PlatformIntType ERROR_RETURN_VALUE
base implementation of FileHandle
Status preallocate(FwSignedSizeType offset, FwSignedSizeType length) override
pre-allocate file storage
Status read(U8 *buffer, FwSignedSizeType &size, WaitType wait) override
read data from this file into supplied buffer bounded by size
A catch-all for other errors. Have to look in implementation-specific code.
PosixFile()=default
constructor
Open file for writing; writes don't return until data is on disk.
static constexpr PlatformIntType INVALID_FILE_DESCRIPTOR
posix implementation of Os::File
Status size(FwSignedSizeType &size_result) override
get size of currently open file
Status position(FwSignedSizeType &position_result) override
get file pointer position of the currently open file
void close() override
close the file, if not opened then do nothing
uint8_t U8
8-bit unsigned integer
PosixFile & operator=(const PosixFile &other)
assignment operator that copies the internal representation
static U32 min(const U32 a, const U32 b)
File::Status errno_to_file_status(PlatformIntType errno_input)
Operation was successful.
Status seek(FwSignedSizeType offset, SeekType seekType) override
seek the file pointer to the given offset
PlatformSignedSizeType FwSignedSizeType
Status flush() override
flush file contents to storage
FileHandle * getHandle() override
returns the raw file handle
Status write(const U8 *buffer, FwSignedSizeType &size, WaitType wait) override
read data from this file into supplied buffer bounded by size
PlatformIntType m_file_descriptor
Posix file descriptor.
Os::FileInterface::Status open(const char *path, Mode mode, OverwriteType overwrite) override
open file with supplied path and mode
Open file for writing and truncates file if it exists, ie same flags as creat()