GCC Code Coverage Report


Directory: ./
File: Posix/Directory.hpp
Date: 2026-09-03 22:13:09
Exec Total Coverage
Lines: 1 1 100.0%
Functions: 1 1 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 // ======================================================================
2 // \title Os/Posix/Directory.hpp
3 // \brief Posix definitions for Os::Directory
4 // ======================================================================
5 #ifndef OS_POSIX_DIRECTORY_HPP
6 #define OS_POSIX_DIRECTORY_HPP
7 #include <dirent.h>
8 #include <Os/Directory.hpp>
9
10 namespace Os {
11 namespace Posix {
12 namespace Directory {
13
14 struct PosixDirectoryHandle : public DirectoryHandle {
15 DIR* m_dir_descriptor = nullptr;
16 };
17
18 //! \brief Posix implementation of Os::Directory
19 //!
20 //! Posix implementation of `DirectoryInterface` for use as a delegate class handling error-only file operations.
21 class PosixDirectory : public DirectoryInterface {
22 public:
23 //! \brief constructor
24 PosixDirectory();
25
26 //! \brief destructor
27 4 ~PosixDirectory() = default;
28
29 //! \brief return the underlying mutex handle (implementation specific)
30 //! \return internal mutex handle representation
31 DirectoryHandle* getHandle() override;
32
33 // ------------------------------------------------------------
34 // Implementation-specific Directory member functions
35 // ------------------------------------------------------------
36
37 //! \brief Open or create a directory
38 //!
39 //! Using the path provided, this function will open or create a directory.
40 //! Use OpenMode::READ to open an existing directory and error if the directory is not found
41 //! Use OpenMode::CREATE_IF_MISSING to open a directory, creating the directory if it doesn't exist
42 //! Use OpenMode::CREATE_EXCLUSIVE to open a directory, creating the directory and erroring if it already exists
43 //!
44 //! It is invalid to pass `nullptr` as the path.
45 //! It is invalid to supply `mode` as a non-enumerated value.
46 //!
47 //! \param path: path of directory to open
48 //! \param mode: enum (READ, CREATE_IF_MISSING, CREATE_EXCLUSIVE). See notes above for more information
49 //! \return status of the operation
50 Status open(const char* path, OpenMode mode) override;
51
52 //! \brief Check if Directory is open or not
53 //! \return true if Directory is open, false otherwise
54 bool isOpen();
55
56 //! \brief Rewind directory stream
57 //!
58 //! Each read operation moves the seek position forward. This function resets the seek position to the beginning.
59 //!
60 //! \return status of the operation
61 Status rewind() override;
62
63 //! \brief Get next filename from directory stream
64 //!
65 //! Writes at most buffSize characters of the file name to fileNameBuffer.
66 //! This function skips the current directory (.) and parent directory (..) entries.
67 //! Returns NO_MORE_FILES if there are no more files to read from the buffer.
68 //!
69 //! It is invalid to pass `nullptr` as fileNameBuffer.
70 //!
71 //! \param fileNameBuffer: buffer to store filename
72 //! \param buffSize: size of fileNameBuffer
73 //! \return status of the operation
74 Status read(char* fileNameBuffer, FwSizeType buffSize) override;
75
76 //! \brief Close directory
77 void close() override;
78
79 private:
80 //! Handle for PosixDirectory
81 PosixDirectoryHandle m_handle;
82 };
83
84 } // namespace Directory
85 } // namespace Posix
86 } // namespace Os
87 #endif // OS_POSIX_DIRECTORY_HPP
88