Mistake on this page?
Report an issue in GitHub or email us
Dir.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2015 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef DIR_H
18 #define DIR_H
19 
20 #include "filesystem/FileSystem.h"
21 #include "platform/DirHandle.h"
22 
23 namespace mbed {
24 /** \addtogroup filesystem */
25 /** @{*/
26 
27 
28 /** Dir class
29  */
30 class Dir : public DirHandle {
31 public:
32  /** Create an uninitialized directory
33  *
34  * Must call open to initialize the directory on a file system
35  */
36  Dir();
37 
38  /** Open a directory on a filesystem
39  *
40  * @param fs Filesystem as target for a directory
41  * @param path Name of the directory to open
42  */
43  Dir(FileSystem *fs, const char *path);
44 
45  /** Destroy a file
46  *
47  * Closes file if the file is still open
48  */
49  virtual ~Dir();
50 
51  /** Open a directory on the filesystem
52  *
53  * @param fs Filesystem as target for a directory
54  * @param path Name of the directory to open
55  * @return 0 on success, negative error code on failure
56  */
57  virtual int open(FileSystem *fs, const char *path);
58 
59  /** Close a directory
60  *
61  * @return 0 on success, negative error code on failure
62  */
63  virtual int close();
64 
65  /** Read the next directory entry
66  *
67  * @param ent The directory entry to fill out
68  * @return 1 on reading a filename, 0 at end of directory, negative error on failure
69  */
70  virtual ssize_t read(struct dirent *ent);
71 
72  /** Set the current position of the directory
73  *
74  * @param offset Offset of the location to seek to,
75  * must be a value returned from tell
76  */
77  virtual void seek(off_t offset);
78 
79  /** Get the current position of the directory
80  *
81  * @return Position of the directory that can be passed to rewind
82  */
83  virtual off_t tell();
84 
85  /** Rewind the current position to the beginning of the directory
86  */
87  virtual void rewind();
88 
89  /** Get the sizeof the directory
90  *
91  * @return Number of files in the directory
92  */
93  virtual size_t size();
94 
95 private:
96  FileSystem *_fs;
97  fs_dir_t _dir;
98 };
99 
100 
101 /** @}*/
102 } // namespace mbed
103 
104 #endif
virtual int open(FileSystem *fs, const char *path)
Open a directory on the filesystem.
Represents a directory stream.
Definition: DirHandle.h:56
virtual size_t size()
Get the sizeof the directory.
virtual int close()
Close a directory.
virtual void rewind()
Rewind the current position to the beginning of the directory.
Dir class.
Definition: Dir.h:30
virtual ~Dir()
Destroy a file.
A file system object.
Definition: FileSystem.h:49
virtual ssize_t read(struct dirent *ent)
Read the next directory entry.
Dir()
Create an uninitialized directory.
virtual off_t tell()
Get the current position of the directory.
virtual void seek(off_t offset)
Set the current position of the directory.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.