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.");
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;
115 off_t original = ::lseek(this->m_handle.
m_file_descriptor, current_position, SEEK_SET);
121 size_result = end_of_file;
144 #if _POSIX_C_SOURCE >= 200112L
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, offset, (seekType == SeekType::ABSOLUTE) ? SEEK_SET : SEEK_CUR);
193 }
else if ((seekType == SeekType::ABSOLUTE) && (actual != offset)) {
213 ? std::numeric_limits<FwSignedSizeType>::max()
219 static_cast<size_t>(
size - accumulated));
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));
261 if (EINTR != errno_store) {
267 accumulated += write_size;
282 return &this->m_handle;
uint8_t U8
8-bit unsigned integer
static U32 min(const U32 a, const U32 b)
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
PlatformSignedSizeType FwSignedSizeType
@ OP_OK
Operation was successful.
@ OPEN_WRITE
Open file for writing.
@ OPEN_CREATE
Open file for writing and truncates file if it exists, ie same flags as creat()
@ OPEN_READ
Open file for reading.
@ OPEN_APPEND
Open file for appending.
@ OPEN_SYNC_WRITE
Open file for writing; writes don't return until data is on disk.
posix implementation of Os::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
Status seek(FwSignedSizeType offset, SeekType seekType) override
seek the file pointer to the given offset
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
Status write(const U8 *buffer, FwSignedSizeType &size, WaitType wait) override
read data from this file into supplied buffer bounded by size
FileHandle * getHandle() override
returns the raw file handle
PosixFile()=default
constructor
Status size(FwSignedSizeType &size_result) override
get size of currently open file
Status flush() override
flush file contents to storage
PosixFile & operator=(const PosixFile &other)
assignment operator that copies the internal representation
Os::FileInterface::Status open(const char *path, Mode mode, OverwriteType overwrite) override
open file with supplied path and mode
@ OP_OK
Operation succeeded.
File::Status errno_to_file_status(PlatformIntType errno_input)
@ OTHER_ERROR
A catch-all for other errors. Have to look in implementation-specific code.
base implementation of FileHandle
PlatformIntType m_file_descriptor
Posix file descriptor.
static constexpr PlatformIntType INVALID_FILE_DESCRIPTOR
static constexpr PlatformIntType ERROR_RETURN_VALUE