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.");
48 #ifndef TGT_OS_TYPE_VXWORKS
55 #ifndef TGT_OS_TYPE_VXWORKS
69 switch (requested_mode) {
71 mode_flags = O_RDONLY;
74 mode_flags = O_WRONLY | O_CREAT;
77 mode_flags = O_WRONLY | O_CREAT | O_SYNC;
81 O_WRONLY | O_CREAT | O_TRUNC | ((overwrite == PosixFile::OverwriteType::OVERWRITE) ? 0 : O_EXCL);
84 mode_flags = O_WRONLY | O_CREAT | O_APPEND;
119 off_t original = ::lseek(this->m_handle.
m_file_descriptor, current_position, SEEK_SET);
125 size_result = end_of_file;
148 #if _POSIX_C_SOURCE >= 200112L
153 if (Os::File::Status::NOT_SUPPORTED == status) {
156 status = this->
size(file_size);
160 status = this->
position(file_position);
163 if ((std::numeric_limits<FwSignedSizeType>::max() - offset - length) < 0) {
165 }
else if (file_size < (offset + length)) {
167 status = this->
seek(file_size, PosixFile::SeekType::ABSOLUTE);
172 status = this->
write(
reinterpret_cast<const U8*
>(
"\0"), write_size,
173 PosixFile::WaitType::NO_WAIT);
180 status = this->
seek(file_position, PosixFile::SeekType::ABSOLUTE);
193 ::lseek(this->m_handle.
m_file_descriptor, offset, (seekType == SeekType::ABSOLUTE) ? SEEK_SET : SEEK_CUR);
197 }
else if ((seekType == SeekType::ABSOLUTE) && (actual != offset)) {
217 ? std::numeric_limits<FwSignedSizeType>::max()
223 static_cast<size_t>(
size - accumulated));
228 if (EINTR != errno_store) {
235 else if (read_size == 0) {
238 accumulated += read_size;
253 ? std::numeric_limits<FwSignedSizeType>::max()
260 static_cast<size_t>(
size - accumulated));
265 if (EINTR != errno_store) {
271 accumulated += write_size;
286 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