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