2 #include "ace/OS_NS_unistd.h"
3 #include "ace/OS_NS_fcntl.h"
4 #include "ace/OS_NS_errno.h"
5 #include "ace/OS_NS_macros.h"
8 # include "ace/MQX_Filesystem.h"
11 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
17 creat (const ACE_TCHAR *filename, mode_t mode)
19 ACE_OS_TRACE ("ACE_OS::creat");
20 #if defined (ACE_WIN32) || defined (ACE_MQX)
21 return ACE_OS::open (filename, O_CREAT|O_TRUNC|O_WRONLY, mode);
23 return ::creat (ACE_TEXT_ALWAYS_CHAR (filename), mode);
24 #endif /* ACE_WIN32 */
28 fstat (ACE_HANDLE handle, ACE_stat *stp)
30 ACE_OS_TRACE ("ACE_OS::fstat");
31 #if defined (ACE_WIN32)
32 BY_HANDLE_FILE_INFORMATION fdata;
34 if (::GetFileInformationByHandle (handle, &fdata) == FALSE)
36 ACE_OS::set_errno_to_last_error ();
39 else if (fdata.nFileSizeHigh != 0)
46 stp->st_size = fdata.nFileSizeLow;
47 stp->st_atime = ACE_Time_Value (fdata.ftLastAccessTime).sec ();
48 stp->st_mtime = ACE_Time_Value (fdata.ftLastWriteTime).sec ();
49 stp->st_ctime = ACE_Time_Value (fdata.ftCreationTime).sec ();
50 stp->st_nlink = static_cast<short> (fdata.nNumberOfLinks);
51 stp->st_dev = stp->st_rdev = 0; // No equivalent conversion.
52 stp->st_mode = S_IXOTH | S_IROTH |
53 (fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY ? 0 : S_IWOTH) |
54 (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? S_IFDIR : S_IFREG);
57 #elif defined (ACE_LACKS_FSTAT)
58 ACE_NOTSUP_RETURN (-1);
59 #elif defined (ACE_MQX)
60 return MQX_Filesystem::inst ().fstat (handle, stp);
62 return ::fstat (handle, stp);
63 #endif /* !ACE_WIN32 */
66 // This function returns the number of bytes in the file referenced by
69 filesize (ACE_HANDLE handle)
71 ACE_OS_TRACE ("ACE_OS::filesize");
72 #if defined (ACE_WIN32)
73 # if defined (_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
76 (::GetFileSizeEx (handle, &size)
78 : (ACE_OS::set_errno_to_last_error (), -1));
80 DWORD const size = ::GetFileSize (handle, 0);
82 (size != INVALID_FILE_SIZE
83 ? static_cast<ACE_OFF_T> (size)
84 : (ACE_OS::set_errno_to_last_error (), -1));
85 # endif /* _FILE_OFFSET_BITS == 64 */
86 #else /* !ACE_WIN32 */
88 return ACE_OS::fstat (handle, &sb) == -1 ?
89 static_cast<ACE_OFF_T> (-1) : sb.st_size;
94 filesize (const ACE_TCHAR *filename)
96 ACE_OS_TRACE ("ACE_OS::filesize");
98 #if defined (ACE_LACKS_STAT)
99 ACE_HANDLE const h = ACE_OS::open (filename, O_RDONLY);
100 if (h != ACE_INVALID_HANDLE)
102 ACE_OFF_T const size = ACE_OS::filesize (h);
108 #else /* !ACE_LACKS_STAT */
110 return ACE_OS::stat (filename, &sb) == -1 ?
111 static_cast<ACE_OFF_T> (-1) : sb.st_size;
112 #endif /* ACE_LACKS_STAT */
116 lstat (const char *file, ACE_stat *stp)
118 ACE_OS_TRACE ("ACE_OS::lstat");
119 # if defined (ACE_LACKS_LSTAT)
120 return ACE_OS::stat (file, stp);
121 # else /* !ACE_LACKS_LSTAT */
122 return ::lstat (file, stp);
123 # endif /* ACE_LACKS_LSTAT */
126 #if defined (ACE_HAS_WCHAR)
128 lstat (const wchar_t *file, ACE_stat *stp)
130 ACE_OS_TRACE ("ACE_OS::lstat");
131 # if defined (ACE_LACKS_LSTAT)
132 return ACE_OS::stat (file, stp);
134 return ACE_OS::lstat (ACE_Wide_To_Ascii (file).char_rep (), stp);
135 # endif /* ACE_LACKS_LSTAT */
137 #endif /* ACE_HAS_WCHAR */
140 mkdir (const char *path, mode_t mode)
142 #if defined (ACE_MKDIR_LACKS_MODE)
143 ACE_UNUSED_ARG (mode);
144 # if defined (ACE_MKDIR_EQUIVALENT)
145 return ACE_MKDIR_EQUIVALENT (path);
147 return ::mkdir (path);
150 return::mkdir (path, mode);
154 #if defined (ACE_HAS_WCHAR)
157 mkdir (const wchar_t *path, mode_t mode)
159 #if defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
160 ACE_UNUSED_ARG (mode);
161 return ::_wmkdir (path);
163 return ACE_OS::mkdir (ACE_Wide_To_Ascii (path).char_rep (), mode);
164 #endif /* ACE_WIN32 && ACE_USES_WCHAR */
167 #endif /* ACE_HAS_WCHAR */
170 mkfifo (const ACE_TCHAR *file, mode_t mode)
172 ACE_OS_TRACE ("ACE_OS::mkfifo");
173 #if defined (ACE_LACKS_MKFIFO)
174 ACE_UNUSED_ARG (file);
175 ACE_UNUSED_ARG (mode);
176 ACE_NOTSUP_RETURN (-1);
178 return ::mkfifo (ACE_TEXT_ALWAYS_CHAR (file), mode);
179 #endif /* ACE_LACKS_MKFIFO */
183 stat (const char *file, ACE_stat *stp)
185 ACE_OS_TRACE ("ACE_OS::stat");
186 #if defined (ACE_LACKS_STAT)
187 ACE_NOTSUP_RETURN (-1);
188 #elif defined (ACE_MQX)
189 return MQX_Filesystem::inst ().stat (file, stp);
191 return ACE_STAT_FUNC_NAME (file, stp);
192 #endif /* ACE_LACKS_STAT */
195 #if defined (ACE_HAS_WCHAR)
197 stat (const wchar_t *file, ACE_stat *stp)
199 ACE_OS_TRACE ("ACE_OS::stat");
200 #if defined (__BORLANDC__) \
201 || defined (_MSC_VER) \
202 || (defined (__MINGW32__) && !defined (__MINGW64_VERSION_MAJOR))
203 return ACE_WSTAT_FUNC_NAME (file, stp);
205 ACE_Wide_To_Ascii nfile (file);
206 return ACE_OS::stat (nfile.char_rep (), stp);
207 #endif /* __BORLANDC__ */
209 #endif /* ACE_HAS_WCHAR */
214 ACE_OS_TRACE ("ACE_OS::umask");
215 # if defined (ACE_LACKS_UMASK)
216 ACE_UNUSED_ARG (cmask);
217 ACE_NOTSUP_RETURN ((mode_t)-1);
218 # elif defined (ACE_HAS_TR24731_2005_CRT)
220 int const new_mode = static_cast<int> (cmask);
221 ACE_SECURECRTCALL (_umask_s (new_mode, &old_mode), mode_t, -1, old_mode);
222 return static_cast<mode_t> (old_mode);
223 # elif defined (ACE_WIN32) && !defined (__BORLANDC__)
224 return ::_umask (cmask);
226 return ::umask (cmask); // This call shouldn't fail...
227 # endif /* ACE_LACKS_UMASK */
230 } // ACE_OS namespace
232 ACE_END_VERSIONED_NAMESPACE_DECL