Use override/default for RTPortableServer
[ACE_TAO.git] / ACE / ace / OS_NS_fcntl.cpp
blobab6bd35fef201f8ee668de3f46b71ff562a9e680
1 #include "ace/OS_NS_fcntl.h"
3 #if !defined (ACE_HAS_INLINED_OSCALLS)
4 # include "ace/OS_NS_fcntl.inl"
5 #endif /* ACE_HAS_INLINED_OSCALLS */
7 #include "ace/OS_NS_stdio.h"
8 #include "ace/OS_NS_Thread.h"
9 #include "ace/OS_NS_macros.h"
10 #include "ace/Object_Manager_Base.h"
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 ACE_HANDLE
15 ACE_OS::open (const char *filename,
16 int mode,
17 mode_t perms,
18 LPSECURITY_ATTRIBUTES sa)
20 ACE_OS_TRACE ("ACE_OS::open");
22 #if defined (ACE_WIN32)
23 DWORD access = GENERIC_READ;
24 if (ACE_BIT_ENABLED (mode, O_WRONLY))
25 access = GENERIC_WRITE;
26 else if (ACE_BIT_ENABLED (mode, O_RDWR))
27 access = GENERIC_READ | GENERIC_WRITE;
29 DWORD creation = OPEN_EXISTING;
31 if ((mode & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
32 creation = CREATE_NEW;
33 else if ((mode & (_O_CREAT | _O_TRUNC)) == (_O_CREAT | _O_TRUNC))
34 creation = CREATE_ALWAYS;
35 else if (ACE_BIT_ENABLED (mode, _O_CREAT))
36 creation = OPEN_ALWAYS;
37 else if (ACE_BIT_ENABLED (mode, _O_TRUNC))
38 creation = TRUNCATE_EXISTING;
40 DWORD flags = 0;
42 if (ACE_BIT_ENABLED (mode, _O_TEMPORARY))
43 flags |= FILE_FLAG_DELETE_ON_CLOSE | FILE_ATTRIBUTE_TEMPORARY;
45 if (ACE_BIT_ENABLED (mode, FILE_FLAG_WRITE_THROUGH))
46 flags |= FILE_FLAG_WRITE_THROUGH;
47 if (ACE_BIT_ENABLED (mode, FILE_FLAG_OVERLAPPED))
48 flags |= FILE_FLAG_OVERLAPPED;
49 if (ACE_BIT_ENABLED (mode, FILE_FLAG_NO_BUFFERING))
50 flags |= FILE_FLAG_NO_BUFFERING;
51 if (ACE_BIT_ENABLED (mode, FILE_FLAG_RANDOM_ACCESS))
52 flags |= FILE_FLAG_RANDOM_ACCESS;
53 if (ACE_BIT_ENABLED (mode, FILE_FLAG_SEQUENTIAL_SCAN))
54 flags |= FILE_FLAG_SEQUENTIAL_SCAN;
55 if (ACE_BIT_ENABLED (mode, FILE_FLAG_DELETE_ON_CLOSE))
56 flags |= FILE_FLAG_DELETE_ON_CLOSE;
57 if (ACE_BIT_ENABLED (mode, FILE_FLAG_BACKUP_SEMANTICS))
58 flags |= FILE_FLAG_BACKUP_SEMANTICS;
59 if (ACE_BIT_ENABLED (mode, FILE_FLAG_POSIX_SEMANTICS))
60 flags |= FILE_FLAG_POSIX_SEMANTICS;
62 ACE_MT (ACE_thread_mutex_t *ace_os_monitor_lock = 0;)
64 if (ACE_BIT_ENABLED (mode, _O_APPEND))
66 ACE_MT
68 ace_os_monitor_lock = static_cast <ACE_thread_mutex_t *> (
69 ACE_OS_Object_Manager::preallocated_object[
70 ACE_OS_Object_Manager::ACE_OS_MONITOR_LOCK]);
71 ACE_OS::thread_mutex_lock (ace_os_monitor_lock);
75 DWORD shared_mode = perms;
76 SECURITY_ATTRIBUTES sa_buffer;
77 SECURITY_DESCRIPTOR sd_buffer;
79 ACE_HANDLE h = ::CreateFileA (filename,
80 access,
81 shared_mode,
82 ACE_OS::default_win32_security_attributes_r
83 (sa, &sa_buffer, &sd_buffer),
84 creation,
85 flags,
86 0);
88 if (ACE_BIT_ENABLED (mode, _O_APPEND))
90 LONG high_size = 0;
91 if (h != ACE_INVALID_HANDLE
92 && ::SetFilePointer (h,
94 &high_size,
95 FILE_END) == INVALID_SET_FILE_POINTER
96 && GetLastError () != NO_ERROR)
98 ACE_MT (ACE_OS::thread_mutex_unlock (ace_os_monitor_lock);)
99 ACE_FAIL_RETURN (ACE_INVALID_HANDLE);
102 ACE_MT (ACE_OS::thread_mutex_unlock (ace_os_monitor_lock);)
105 if (h == ACE_INVALID_HANDLE)
106 ACE_FAIL_RETURN (h);
107 else
108 return h;
109 #elif defined (INTEGRITY)
110 ACE_UNUSED_ARG (sa);
111 if(!strcmp(filename,ACE_DEV_NULL)) {
112 return ::AllocateNullConsoleDescriptor();
114 else {
115 return ::open (filename, mode, perms);
117 #elif defined (ACE_MQX)
118 ACE_UNUSED_ARG (perms);
119 ACE_UNUSED_ARG (sa);
120 return MQX_Filesystem::inst ().open (filename, mode);
121 #else
122 ACE_UNUSED_ARG (sa);
123 return ::open (filename, mode, perms);
124 #endif /* ACE_WIN32 */
127 #if defined (ACE_HAS_WCHAR)
128 ACE_HANDLE
129 ACE_OS::open (const wchar_t *filename,
130 int mode,
131 mode_t perms,
132 LPSECURITY_ATTRIBUTES sa)
134 #if defined (ACE_WIN32)
135 // @@ (brunsch) Yuck, maybe there is a way to combine the code
136 // here with the char version
138 DWORD access = GENERIC_READ;
139 if (ACE_BIT_ENABLED (mode, O_WRONLY))
140 access = GENERIC_WRITE;
141 else if (ACE_BIT_ENABLED (mode, O_RDWR))
142 access = GENERIC_READ | GENERIC_WRITE;
144 DWORD creation = OPEN_EXISTING;
146 if ((mode & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
147 creation = CREATE_NEW;
148 else if ((mode & (_O_CREAT | _O_TRUNC)) == (_O_CREAT | _O_TRUNC))
149 creation = CREATE_ALWAYS;
150 else if (ACE_BIT_ENABLED (mode, _O_CREAT))
151 creation = OPEN_ALWAYS;
152 else if (ACE_BIT_ENABLED (mode, _O_TRUNC))
153 creation = TRUNCATE_EXISTING;
155 DWORD flags = 0;
157 if (ACE_BIT_ENABLED (mode, _O_TEMPORARY))
158 flags |= FILE_FLAG_DELETE_ON_CLOSE | FILE_ATTRIBUTE_TEMPORARY;
160 if (ACE_BIT_ENABLED (mode, FILE_FLAG_WRITE_THROUGH))
161 flags |= FILE_FLAG_WRITE_THROUGH;
162 if (ACE_BIT_ENABLED (mode, FILE_FLAG_OVERLAPPED))
163 flags |= FILE_FLAG_OVERLAPPED;
164 if (ACE_BIT_ENABLED (mode, FILE_FLAG_NO_BUFFERING))
165 flags |= FILE_FLAG_NO_BUFFERING;
166 if (ACE_BIT_ENABLED (mode, FILE_FLAG_RANDOM_ACCESS))
167 flags |= FILE_FLAG_RANDOM_ACCESS;
168 if (ACE_BIT_ENABLED (mode, FILE_FLAG_SEQUENTIAL_SCAN))
169 flags |= FILE_FLAG_SEQUENTIAL_SCAN;
170 if (ACE_BIT_ENABLED (mode, FILE_FLAG_DELETE_ON_CLOSE))
171 flags |= FILE_FLAG_DELETE_ON_CLOSE;
172 if (ACE_BIT_ENABLED (mode, FILE_FLAG_BACKUP_SEMANTICS))
173 flags |= FILE_FLAG_BACKUP_SEMANTICS;
174 if (ACE_BIT_ENABLED (mode, FILE_FLAG_POSIX_SEMANTICS))
175 flags |= FILE_FLAG_POSIX_SEMANTICS;
177 ACE_MT (ACE_thread_mutex_t *ace_os_monitor_lock = 0;)
179 if (ACE_BIT_ENABLED (mode, _O_APPEND))
181 ACE_MT
183 ace_os_monitor_lock = static_cast <ACE_thread_mutex_t *> (
184 ACE_OS_Object_Manager::preallocated_object[
185 ACE_OS_Object_Manager::ACE_OS_MONITOR_LOCK]);
186 ACE_OS::thread_mutex_lock (ace_os_monitor_lock);
190 DWORD shared_mode = perms;
191 SECURITY_ATTRIBUTES sa_buffer;
192 SECURITY_DESCRIPTOR sd_buffer;
194 ACE_HANDLE h = ::CreateFileW (filename,
195 access,
196 shared_mode,
197 ACE_OS::default_win32_security_attributes_r
198 (sa, &sa_buffer, &sd_buffer),
199 creation,
200 flags,
203 if (ACE_BIT_ENABLED (mode, _O_APPEND))
205 LONG high_size = 0;
206 if (h != ACE_INVALID_HANDLE
207 && ::SetFilePointer (h,
209 &high_size,
210 FILE_END) == INVALID_SET_FILE_POINTER
211 && GetLastError () != NO_ERROR)
213 ACE_MT (ACE_OS::thread_mutex_unlock (ace_os_monitor_lock);)
214 ACE_FAIL_RETURN (ACE_INVALID_HANDLE);
217 ACE_MT (ACE_OS::thread_mutex_unlock (ace_os_monitor_lock);)
220 if (h == ACE_INVALID_HANDLE)
221 ACE_FAIL_RETURN (h);
222 else
223 return h;
224 #else /* ACE_WIN32 */
225 // Just emulate with ascii version
226 return ACE_OS::open (ACE_Wide_To_Ascii (filename).char_rep (),
227 mode,
228 perms,
229 sa);
230 #endif /* ACE_WIN32 */
232 #endif /* ACE_HAS_WCHAR */
234 ACE_END_VERSIONED_NAMESPACE_DECL