µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
directory.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2015 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
30
32
33#include <cerrno>
34#include <cassert>
35#include <string.h>
36
37// ----------------------------------------------------------------------------
38
39namespace os
40{
41 namespace posix
42 {
43 // ========================================================================
44
46 impl_ (impl)
47 {
48#if defined(OS_TRACE_POSIX_IO_DIRECTORY)
49 trace::printf ("directory::%s()=%p\n", __func__, this);
50#endif
51 }
52
54 {
55#if defined(OS_TRACE_POSIX_IO_DIRECTORY)
56 trace::printf ("directory::%s() @%p\n", __func__, this);
57#endif
58 }
59
60 // ------------------------------------------------------------------------
61
62 struct dirent*
64 {
65#if defined(OS_TRACE_POSIX_IO_DIRECTORY)
66 trace::printf ("directory::%s() @%p\n", __func__, this);
67#endif
68
69 // assert(file_system_ != nullptr);
70
71 // POSIX requires not to change errno when end of directory is
72 // encountered. However, in this implementation, errno is
73 // always cleared when entering system calls.
74 errno = 0;
75
76 // Execute the implementation specific code.
77 return impl ().do_read ();
78 }
79
80 void
82 {
83#if defined(OS_TRACE_POSIX_IO_DIRECTORY)
84 trace::printf ("directory::%s() @%p\n", __func__, this);
85#endif
86
87 // assert(file_system_ != nullptr);
88
89 // POSIX does not mention what to do with errno.
90 errno = 0;
91
92 // Execute the implementation specific code.
93 impl ().do_rewind ();
94 }
95
96 int
98 {
99#if defined(OS_TRACE_POSIX_IO_DIRECTORY)
100 trace::printf ("directory::%s() @%p\n", __func__, this);
101#endif
102
103 // assert(file_system_ != nullptr);
104 errno = 0;
105
106 // Execute the implementation specific code.
107 int ret = impl ().do_close ();
108 if (ret != 0)
109 {
110 trace::printf ("directory::%s() @%p do_close() returned %d\n",
111 __func__, this, ret);
112 }
113
114 // The file object will be deallocated at the next open.
116
117 return ret;
118 }
119
120 // ========================================================================
121
123 file_system_ (fs)
124 {
125#if defined(OS_TRACE_POSIX_IO_DIRECTORY)
126 trace::printf ("directory_impl::%s()=%p\n", __func__, this);
127#endif
128 memset (&dir_entry_, 0, sizeof(struct dirent));
129 }
130
132 {
133#if defined(OS_TRACE_POSIX_IO_DIRECTORY)
134 trace::printf ("directory_impl::%s() @%p\n", __func__, this);
135#endif
136 }
137
138 // ========================================================================
139
140 } /* namespace posix */
141} /* namespace os */
142
143// ----------------------------------------------------------------------------
virtual struct dirent * do_read(void)=0
virtual int do_close(void)=0
directory_impl(class file_system &fs)
virtual void do_rewind(void)=0
virtual int close(void)
Definition directory.cpp:97
virtual struct dirent * read(void)
Definition directory.cpp:63
class file_system & file_system(void) const
Definition directory.h:474
directory(directory_impl &impl)
Definition directory.cpp:45
virtual void rewind(void)
Definition directory.cpp:81
directory_impl & impl(void) const
Definition directory.h:486
File system class.
void add_deferred_directory(directory *dir)
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:74
System namespace.