7 #ifndef __LIBCAMERA_INTERNAL_FILE_H__
8 #define __LIBCAMERA_INTERNAL_FILE_H__
12 #include <sys/types.h>
14 #include <libcamera/span.h>
33 File(
const std::string &name);
38 File &operator=(
const File &) =
delete;
40 const std::string &
fileName()
const {
return name_; }
45 bool isOpen()
const {
return fd_ != -1; }
49 int error()
const {
return error_; }
52 Span<uint8_t>
map(off_t offset = 0, ssize_t
size = -1,
54 bool unmap(uint8_t *addr);
56 static bool exists(
const std::string &name);
66 std::map<void *, size_t> maps_;
Interface for I/O operations on files.
Definition: file.h:19
MapFlag
Flags for the File::map() function.
Definition: file.h:21
@ MapNoOption
No option (used as default value)
Definition: file.h:22
@ MapPrivate
The memory region is mapped as private, changes are not reflected in the file constents.
Definition: file.h:23
int error() const
Retrieve the file error status.
Definition: file.h:49
const std::string & fileName() const
Retrieve the file name.
Definition: file.h:40
bool exists() const
Check if the file specified by fileName() exists.
Definition: file.cpp:141
bool open(OpenMode mode)
Open the file in the given mode.
Definition: file.cpp:158
void close()
Close the file.
Definition: file.cpp:197
Span< uint8_t > map(off_t offset=0, ssize_t size=-1, MapFlag flags=MapNoOption)
Map a region of the file in the process memory.
Definition: file.cpp:262
bool isOpen() const
Check if the file is open.
Definition: file.h:45
~File()
Destroy a File instance.
Definition: file.cpp:97
File()
Construct a File without an associated name.
Definition: file.cpp:86
OpenMode
Mode in which a file is opened.
Definition: file.h:26
@ WriteOnly
The file is open for writing.
Definition: file.h:29
@ ReadWrite
The file is open for reading and writing.
Definition: file.h:30
@ NotOpen
The file is not open.
Definition: file.h:27
@ ReadOnly
The file is open for reading.
Definition: file.h:28
OpenMode openMode() const
Retrieve the file open mode.
Definition: file.h:46
bool unmap(uint8_t *addr)
Unmap a region mapped with map()
Definition: file.cpp:309
ssize_t size() const
Retrieve the file size.
Definition: file.cpp:227
void setFileName(const std::string &name)
Set the name of the file.
Definition: file.cpp:118