µ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-2023 Liviu Ionescu. All rights reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from https://opensource.org/licenses/mit/.
11 */
12
13#if defined(OS_USE_OS_APP_CONFIG_H)
14#include <cmsis-plus/os-app-config.h>
15#endif
16
19
21
22#include <cerrno>
23#include <cassert>
24#include <string.h>
25
26// ----------------------------------------------------------------------------
27
28namespace os
29{
30 namespace posix
31 {
32 // ========================================================================
33
35 impl_ (impl)
36 {
37#if defined(OS_TRACE_POSIX_IO_DIRECTORY)
38 trace::printf ("directory::%s()=%p\n", __func__, this);
39#endif
40 }
41
43 {
44#if defined(OS_TRACE_POSIX_IO_DIRECTORY)
45 trace::printf ("directory::%s() @%p\n", __func__, this);
46#endif
47 }
48
49 // ------------------------------------------------------------------------
50
51 /* struct */ dirent*
53 {
54#if defined(OS_TRACE_POSIX_IO_DIRECTORY)
55 trace::printf ("directory::%s() @%p\n", __func__, this);
56#endif
57
58 // assert(file_system_ != nullptr);
59
60 // POSIX requires not to change errno when end of directory is
61 // encountered. However, in this implementation, errno is
62 // always cleared when entering system calls.
63 errno = 0;
64
65 // Execute the implementation specific code.
66 return impl ().do_read ();
67 }
68
69 void
71 {
72#if defined(OS_TRACE_POSIX_IO_DIRECTORY)
73 trace::printf ("directory::%s() @%p\n", __func__, this);
74#endif
75
76 // assert(file_system_ != nullptr);
77
78 // POSIX does not mention what to do with errno.
79 errno = 0;
80
81 // Execute the implementation specific code.
82 impl ().do_rewind ();
83 }
84
85 int
87 {
88#if defined(OS_TRACE_POSIX_IO_DIRECTORY)
89 trace::printf ("directory::%s() @%p\n", __func__, this);
90#endif
91
92 // assert(file_system_ != nullptr);
93 errno = 0;
94
95 // Execute the implementation specific code.
96 int ret = impl ().do_close ();
97 if (ret != 0)
98 {
99 trace::printf ("directory::%s() @%p do_close() returned %d\n",
100 __func__, this, ret);
101 }
102
103 // The file object will be deallocated at the next open.
105
106 return ret;
107 }
108
109 // ========================================================================
110
112 file_system_ (fs)
113 {
114#if defined(OS_TRACE_POSIX_IO_DIRECTORY)
115 trace::printf ("directory_impl::%s()=%p\n", __func__, this);
116#endif
117 memset (&dir_entry_, 0, sizeof(/* struct */ dirent));
118 }
119
121 {
122#if defined(OS_TRACE_POSIX_IO_DIRECTORY)
123 trace::printf ("directory_impl::%s() @%p\n", __func__, this);
124#endif
125 }
126
127 // ========================================================================
128
129 } /* namespace posix */
130} /* namespace os */
131
132// ----------------------------------------------------------------------------
virtual int do_close(void)=0
directory_impl(file_system &fs)
virtual dirent * do_read(void)=0
virtual void do_rewind(void)=0
virtual int close(void)
Definition directory.cpp:86
class file_system & get_file_system(void) const
Definition directory.h:500
virtual dirent * read(void)
Definition directory.cpp:52
directory(directory_impl &impl)
Definition directory.cpp:34
virtual void rewind(void)
Definition directory.cpp:70
directory_impl & impl(void) const
Definition directory.h:512
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:60
System namespace.