123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- #ifndef MBED_DIRHANDLE_H
- #define MBED_DIRHANDLE_H
- #include <stdint.h>
- #include "platform/platform.h"
- #include "platform/FileHandle.h"
- #include "platform/NonCopyable.h"
- namespace mbed {
- class DirHandle : private NonCopyable<DirHandle> {
- public:
- virtual ~DirHandle() {}
-
- virtual ssize_t read(struct dirent *ent) = 0;
-
- virtual int close() = 0;
-
- virtual void seek(off_t offset) = 0;
-
- virtual off_t tell() = 0;
-
- virtual void rewind() = 0;
-
- virtual size_t size()
- {
- off_t off = tell();
- size_t size = 0;
- struct dirent *ent = new struct dirent;
- rewind();
- while (read(ent) > 0) {
- size += 1;
- }
- seek(off);
- delete ent;
- return size;
- }
-
- MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::close")
- virtual int closedir()
- {
- return close();
- };
-
- MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::read")
- virtual struct dirent *readdir()
- {
- static struct dirent ent;
- return (read(&ent) > 0) ? &ent : NULL;
- }
-
- MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::rewind")
- virtual void rewinddir()
- {
- rewind();
- }
-
- MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::tell")
- virtual off_t telldir()
- {
- return tell();
- }
-
- MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::seek")
- virtual void seekdir(off_t location)
- {
- seek(location);
- }
- };
- }
- #endif
|