FINAL CUT
fsystemimpl.h
1 /***********************************************************************
2 * fsystemimpl.h - FSystem implementation *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2019-2023 Markus Gans *
7 * *
8 * FINAL CUT is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation; either version 3 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * FINAL CUT is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this program. If not, see *
20 * <http://www.gnu.org/licenses/>. *
21 ***********************************************************************/
22 
23 /* Inheritance diagram
24  * ═══════════════════
25  *
26  * ▕▔▔▔▔▔▔▔▔▔▏
27  * ▕ FSystem ▏
28  * ▕▁▁▁▁▁▁▁▁▁▏
29  * ▲
30  * │
31  * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
32  * ▕ FSystemImpl ▏
33  * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
34  */
35 
36 #ifndef FSYSTEMIMPL_H
37 #define FSYSTEMIMPL_H
38 
39 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
40  #error "Only <final/final.h> can be included directly."
41 #endif
42 
43 #if defined(__linux__)
44 
45  #if defined(__arm__) && defined(__GLIBC__) && defined(__GLIBC_PREREQ)
46  // ISA sysctl support on arm processors only up to glibc-2.29
47  #if !__GLIBC_PREREQ(2,30)
48  #define ARM_ISA_SYSCTL
49  #endif
50  #endif
51 
52  #if defined(__x86_64__) || defined(__i386) || defined(ARM_ISA_SYSCTL)
53  #define ISA_SYSCTL_SUPPORT
54  #include <sys/io.h>
55  #endif // defined(__x86_64__) || defined(__i386) || defined(ARM_ISA_SYSCTL)
56 
57 #endif // defined(__linux__)
58 
59 
60 #include <sys/ioctl.h>
61 #include <sys/stat.h>
62 #include <sys/types.h>
63 
64 #include <cstdarg>
65 #include <fcntl.h>
66 #include <unistd.h>
67 
68 #include "final/fc.h"
69 #include "final/util/fsystem.h"
70 
71 namespace finalcut
72 {
73 
74 //----------------------------------------------------------------------
75 // class FSystemImpl
76 //----------------------------------------------------------------------
77 
78 class FSystemImpl : public FSystem
79 {
80  public:
81  // Constructor
82  FSystemImpl() = default;
83 
84  // Destructor
85  ~FSystemImpl() noexcept override;
86 
87  // Methods
88 #if defined(ISA_SYSCTL_SUPPORT)
89  inline auto inPortByte (uShort port) -> uChar override
90  {
91  return ::inb (port);
92  }
93 #else
94  inline uChar inPortByte (uShort) override
95  {
96  return 0;
97  }
98 #endif
99 
100 
101 #if defined(ISA_SYSCTL_SUPPORT)
102  inline void outPortByte (uChar value, uShort port) override
103  {
104  ::outb (value, port);
105  }
106 #else
107  inline void outPortByte (uChar, uShort) override
108  { }
109 #endif
110 
111  inline auto isTTY (int file_descriptor) const -> int override
112  {
113  return ::isatty(file_descriptor);
114  }
115 
116  inline auto ioctl (int file_descriptor, uLong request, ...) -> int override
117  {
118  va_list args{};
119  va_start (args, request);
120  void* argp = va_arg (args, void*);
121  int ret = ::ioctl (file_descriptor, request, argp);
122  va_end (args);
123  return ret;
124  }
125 
126  inline auto pipe (PipeData& pipe) -> int override
127  {
128  return ::pipe(pipe.getArrayData());
129  }
130 
131  inline auto open (const char* pathname, int flags, ...) -> int override
132  {
133  va_list args{};
134  va_start (args, flags);
135  auto mode = static_cast<mode_t>(va_arg (args, int));
136  int ret = ::open (pathname, flags, mode);
137  va_end (args);
138  return ret;
139  }
140 
141  inline auto close (int file_descriptor) -> int override
142  {
143  return ::close(file_descriptor);
144  }
145 
146  inline auto fopen (const char* path, const char* mode) -> FILE* override
147  {
148  return std::fopen (path, mode);
149  }
150 
151  inline auto fclose (FILE* file_ptr) -> int override
152  {
153  return std::fclose (file_ptr);
154  }
155 
156  inline auto fputs (const char* str, FILE* stream) -> int override
157  {
158  return std::fputs (str, stream);
159  }
160 
161  inline auto putchar (int c) -> int override
162  {
163 #if defined(__sun) && defined(__SVR4)
164  return std::putchar(char(c));
165 #else
166  return std::putchar(c);
167 #endif
168  }
169 
170  auto sigaction ( int, const struct sigaction*
171  , struct sigaction* ) -> int override;
172  auto timer_create ( clockid_t, struct sigevent*
173  , timer_t* ) -> int override;
174  auto timer_settime ( timer_t, int
175  , const struct itimerspec*
176  , struct itimerspec* ) -> int override;
177  auto timer_delete (timer_t) -> int override;
178  auto kqueue() -> int override;
179  auto kevent ( int, const struct ::kevent*
180  , int, struct ::kevent*
181  , int, const struct timespec* ) -> int override;
182 
183  inline auto getuid() -> uid_t override
184  {
185  return ::getuid();
186  }
187 
188  inline auto geteuid() -> uid_t override
189  {
190  return ::geteuid();
191  }
192 
193  auto getpwuid_r ( uid_t, struct passwd*, char*, size_t
194  , struct passwd** ) -> int override;
195 
196  auto realpath (const char*, char*) -> char* override;
197 };
198 
199 } // namespace finalcut
200 
201 #endif // FSYSTEMIMPL_H
202 
203 
Definition: fsystemimpl.h:78
Definition: fsystem.h:57
Definition: class_template.cpp:25
Definition: pipedata.h:47