Directory.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef _Directory_hpp_
  2. #define _Directory_hpp_
  3. #include <FpConfig.hpp>
  4. namespace Os {
  5. // This class encapsulates a very simple directory interface that has the most often-used features
  6. class Directory {
  7. public:
  8. typedef enum {
  9. OP_OK, //!< Operation was successful
  10. DOESNT_EXIST, //!< Directory doesn't exist
  11. NO_PERMISSION, //!< No permission to read directory
  12. NOT_OPENED, //!< Directory hasn't been opened yet
  13. NOT_DIR, //!< Path is not a directory
  14. NO_MORE_FILES, //!< Directory stream has no more files
  15. OTHER_ERROR, //!< A catch-all for other errors. Have to look in implementation-specific code
  16. } Status;
  17. Directory(); //!< Constructor
  18. virtual ~Directory(); //!< Destructor. Will close directory if still open
  19. Status open(const char* dirName); //!< open directory. Directory must already exist
  20. bool isOpen(); //!< check if file descriptor is open or not.
  21. Status rewind(); //!< rewind directory stream to the beginning
  22. Status read(char * fileNameBuffer, U32 bufSize); //!< get next filename from directory
  23. Status read(char * fileNameBuffer, U32 bufSize, I64& inode); //!< get next filename and inode from directory
  24. void close(); //!< close directory
  25. NATIVE_INT_TYPE getLastError(); //!< read back last error code (typically errno)
  26. const char* getLastErrorString(); //!< get a string of the last error (typically from strerror)
  27. private:
  28. POINTER_CAST m_dir; //!< Stored directory pointer (type varies across implementations)
  29. NATIVE_INT_TYPE m_lastError; //!< stores last error
  30. };
  31. }
  32. #endif