00001
00002
00003
00004
00005 #include "ace/OS_NS_unistd.h"
00006 #include "ace/OS_NS_fcntl.h"
00007 #include "ace/OS_NS_errno.h"
00008 #include "ace/OS_NS_macros.h"
00009
00010 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00011
00012 namespace ACE_OS
00013 {
00014
00015 ACE_INLINE ACE_HANDLE
00016 creat (const ACE_TCHAR *filename, mode_t mode)
00017 {
00018 ACE_OS_TRACE ("ACE_OS::creat");
00019 #if defined (ACE_WIN32)
00020 return ACE_OS::open (filename, O_CREAT|O_TRUNC|O_WRONLY, mode);
00021 #else
00022 ACE_OSCALL_RETURN (::creat (ACE_TEXT_ALWAYS_CHAR (filename), mode),
00023 ACE_HANDLE, ACE_INVALID_HANDLE);
00024 #endif
00025 }
00026
00027 #if !defined (ACE_WIN32)
00028
00029 ACE_INLINE int
00030 fstat (ACE_HANDLE handle, ACE_stat *stp)
00031 {
00032 ACE_OS_TRACE ("ACE_OS::fstat");
00033 #if defined (ACE_HAS_X86_STAT_MACROS)
00034
00035
00036
00037 ACE_OSCALL_RETURN (::_fxstat (_STAT_VER, handle, stp), int, -1);
00038 #elif defined (ACE_WIN32)
00039 ACE_OSCALL_RETURN (::_fstat (handle, stp), int, -1);
00040 #else
00041 # if defined (ACE_OPENVMS)
00042 ::fsync(handle);
00043 # endif
00044 ACE_OSCALL_RETURN (::fstat (handle, stp), int, -1);
00045 # endif
00046 }
00047
00048 #else
00049
00050 ACE_INLINE int
00051 fstat (ACE_HANDLE handle, ACE_stat *stp)
00052 {
00053 ACE_OS_TRACE ("ACE_OS::fstat");
00054 # if 1
00055 BY_HANDLE_FILE_INFORMATION fdata;
00056
00057 if (::GetFileInformationByHandle (handle, &fdata) == FALSE)
00058 {
00059 ACE_OS::set_errno_to_last_error ();
00060 return -1;
00061 }
00062 else if (fdata.nFileSizeHigh != 0)
00063 {
00064 errno = EINVAL;
00065 return -1;
00066 }
00067 else
00068 {
00069 stp->st_size = fdata.nFileSizeLow;
00070 stp->st_atime = ACE_Time_Value (fdata.ftLastAccessTime).sec ();
00071 stp->st_mtime = ACE_Time_Value (fdata.ftLastWriteTime).sec ();
00072 stp->st_ctime = ACE_Time_Value (fdata.ftCreationTime).sec ();
00073 stp->st_nlink = static_cast<short> (fdata.nNumberOfLinks);
00074 stp->st_dev = stp->st_rdev = 0;
00075 stp->st_mode = S_IXOTH | S_IROTH |
00076 (fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY ? 0 : S_IWOTH) |
00077 (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? S_IFDIR : S_IFREG);
00078 }
00079 return 0;
00080 # else
00081
00082 int retval = -1;
00083 int fd = ::_open_osfhandle ((long) handle, 0);
00084 if (fd != -1)
00085 retval = ::_fstat (fd, stp);
00086
00087 ::_close (fd);
00088
00089 return retval;
00090 # endif
00091 }
00092
00093 #endif
00094
00095
00096
00097
00098 ACE_INLINE ACE_LOFF_T
00099 filesize (ACE_HANDLE handle)
00100 {
00101 ACE_OS_TRACE ("ACE_OS::filesize");
00102 ACE_stat sb;
00103 return ACE_OS::fstat (handle, &sb) == -1 ? -1 : sb.st_size;
00104 }
00105
00106 ACE_INLINE ACE_LOFF_T
00107 filesize (const ACE_TCHAR *filename)
00108 {
00109 ACE_OS_TRACE ("ACE_OS::filesize");
00110
00111 ACE_HANDLE h = ACE_OS::open (filename, O_RDONLY);
00112 if (h != ACE_INVALID_HANDLE)
00113 {
00114 ACE_LOFF_T size = ACE_OS::filesize (h);
00115 ACE_OS::close (h);
00116 return size;
00117 }
00118 else
00119 return -1;
00120 }
00121
00122 ACE_INLINE int
00123 lstat (const char *file, ACE_stat *stp)
00124 {
00125 ACE_OS_TRACE ("ACE_OS::lstat");
00126 # if defined (ACE_LACKS_LSTAT)
00127 return ACE_OS::stat (file, stp);
00128 # elif defined (ACE_HAS_X86_STAT_MACROS)
00129
00130
00131 ACE_OSCALL_RETURN (::_lxstat (_STAT_VER, file, stp), int, -1);
00132 # else
00133 ACE_OSCALL_RETURN (::lstat (file, stp), int, -1);
00134 # endif
00135 }
00136
00137 #if defined (ACE_HAS_WCHAR)
00138 ACE_INLINE int
00139 lstat (const wchar_t *file, ACE_stat *stp)
00140 {
00141 ACE_OS_TRACE ("ACE_OS::lstat");
00142 # if defined (ACE_LACKS_LSTAT)
00143 return ACE_OS::stat (file, stp);
00144 # else
00145 return ACE_OS::lstat (ACE_Wide_To_Ascii (file).char_rep (), stp);
00146 # endif
00147 }
00148 #endif
00149
00150 ACE_INLINE int
00151 mkdir (const char *path, mode_t mode)
00152 {
00153 #if defined (ACE_WIN32) && defined (__IBMCPP__) && (__IBMCPP__ >= 400)
00154 ACE_UNUSED_ARG (mode);
00155 ACE_OSCALL_RETURN (::_mkdir (const_cast <char *> (path)), int, -1);
00156 #elif defined (ACE_HAS_WINCE)
00157 ACE_UNUSED_ARG (mode);
00158 ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::CreateDirectory (ACE_TEXT_CHAR_TO_TCHAR (path), 0),
00159 ace_result_),
00160 int, -1);
00161 #elif defined (ACE_MKDIR_LACKS_MODE)
00162 ACE_UNUSED_ARG (mode);
00163 ACE_OSCALL_RETURN (::mkdir (path), int, -1);
00164 #else
00165 ACE_OSCALL_RETURN (::mkdir (path, mode), int, -1);
00166 #endif
00167 }
00168
00169 #if defined (ACE_HAS_WCHAR)
00170
00171 ACE_INLINE int
00172 mkdir (const wchar_t *path, mode_t mode)
00173 {
00174 #if defined (ACE_HAS_WINCE)
00175 ACE_UNUSED_ARG (mode);
00176 ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (CreateDirectoryW (path, 0),
00177 ace_result_),
00178 int, -1);
00179 #elif defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
00180 ACE_UNUSED_ARG (mode);
00181 ACE_OSCALL_RETURN (::_wmkdir (path), int, -1);
00182 #else
00183 return ACE_OS::mkdir (ACE_Wide_To_Ascii (path).char_rep (), mode);
00184 #endif
00185 }
00186
00187 #endif
00188
00189 ACE_INLINE int
00190 mkfifo (const ACE_TCHAR *file, mode_t mode)
00191 {
00192 ACE_OS_TRACE ("ACE_OS::mkfifo");
00193 #if defined (ACE_LACKS_MKFIFO)
00194 ACE_UNUSED_ARG (file);
00195 ACE_UNUSED_ARG (mode);
00196 ACE_NOTSUP_RETURN (-1);
00197 #else
00198 ACE_OSCALL_RETURN (::mkfifo (ACE_TEXT_ALWAYS_CHAR (file), mode), int, -1);
00199 #endif
00200 }
00201
00202 ACE_INLINE int
00203 stat (const char *file, ACE_stat *stp)
00204 {
00205 ACE_OS_TRACE ("ACE_OS::stat");
00206 #if defined (ACE_HAS_NONCONST_STAT)
00207 ACE_OSCALL_RETURN (::stat (const_cast <char *> (file), stp), int, -1);
00208 #elif defined (ACE_HAS_WINCE)
00209 ACE_TEXT_WIN32_FIND_DATA fdata;
00210
00211 HANDLE fhandle;
00212
00213 fhandle = ::FindFirstFile (ACE_TEXT_CHAR_TO_TCHAR (file), &fdata);
00214 if (fhandle == INVALID_HANDLE_VALUE)
00215 {
00216 ACE_OS::set_errno_to_last_error ();
00217 return -1;
00218 }
00219 else if (fdata.nFileSizeHigh != 0)
00220 {
00221 errno = EINVAL;
00222 return -1;
00223 }
00224 else
00225 {
00226 stp->st_mode = static_cast<unsigned short>(fdata.dwFileAttributes);
00227 stp->st_size = fdata.nFileSizeLow;
00228 stp->st_atime = ACE_Time_Value (fdata.ftLastAccessTime);
00229 stp->st_mtime = ACE_Time_Value (fdata.ftLastWriteTime);
00230 }
00231 return 0;
00232 #elif defined (ACE_HAS_X86_STAT_MACROS)
00233
00234
00235 ACE_OSCALL_RETURN (::_xstat (_STAT_VER, file, stp), int, -1);
00236 #elif defined (ACE_WIN32)
00237 # if defined(__IBMCPP__) || defined (__MINGW32__)
00238 ACE_OSCALL_RETURN (::_stat (file, stp), int, -1);
00239 # elif defined (__BORLANDC__)
00240 ACE_OSCALL_RETURN (::_stati64 (file, stp), int, -1);
00241 # elif defined _MSC_VER && _MSC_VER >= 1300 && _MSC_VER < 1400 // vc71
00242 ACE_OSCALL_RETURN (::_stati64 (file, stp), int, -1);
00243 # else
00244 ACE_OSCALL_RETURN (::_stat64 (file, stp), int, -1);
00245 # endif
00246 #else
00247 ACE_OSCALL_RETURN (::stat (file, stp), int, -1);
00248 #endif
00249 }
00250
00251 #if defined (ACE_HAS_WCHAR)
00252 ACE_INLINE int
00253 stat (const wchar_t *file, ACE_stat *stp)
00254 {
00255 ACE_OS_TRACE ("ACE_OS::stat");
00256 #if defined (ACE_HAS_WINCE)
00257 WIN32_FIND_DATAW fdata;
00258
00259 HANDLE fhandle;
00260
00261 fhandle = ::FindFirstFileW (file, &fdata);
00262 if (fhandle == INVALID_HANDLE_VALUE)
00263 {
00264 ACE_OS::set_errno_to_last_error ();
00265 return -1;
00266 }
00267 else if (fdata.nFileSizeHigh != 0)
00268 {
00269 errno = EINVAL;
00270 return -1;
00271 }
00272 else
00273 {
00274 stp->st_mode = static_cast<unsigned short>(fdata.dwFileAttributes);
00275 stp->st_size = fdata.nFileSizeLow;
00276 stp->st_atime = ACE_Time_Value (fdata.ftLastAccessTime);
00277 stp->st_mtime = ACE_Time_Value (fdata.ftLastWriteTime);
00278 }
00279 return 0;
00280 #elif defined (__BORLANDC__)
00281 ACE_OSCALL_RETURN (::_wstati64 (file, stp), int, -1);
00282 #elif defined (ACE_WIN32) && defined _MSC_VER && _MSC_VER >= 1300 && _MSC_VER < 1400 // vc71
00283 ACE_OSCALL_RETURN (::_wstati64 (file, stp), int, -1);
00284 #elif defined (__MINGW32__)
00285 ACE_OSCALL_RETURN (::_wstat (file, stp), int, -1);
00286 #elif defined (ACE_WIN32)
00287 ACE_OSCALL_RETURN (::_wstat64 (file, stp), int, -1);
00288 #else
00289 ACE_Wide_To_Ascii nfile (file);
00290 return ACE_OS::stat (nfile.char_rep (), stp);
00291 #endif
00292 }
00293 #endif
00294
00295 ACE_INLINE mode_t
00296 umask (mode_t cmask)
00297 {
00298 ACE_OS_TRACE ("ACE_OS::umask");
00299 # if defined (ACE_LACKS_UMASK)
00300 ACE_UNUSED_ARG (cmask);
00301 ACE_NOTSUP_RETURN ((mode_t)-1);
00302 # elif defined (ACE_WIN32) && !defined (__BORLANDC__)
00303 ACE_OSCALL_RETURN (::_umask (cmask), mode_t, -1);
00304 # else
00305 return ::umask (cmask);
00306 # endif
00307 }
00308
00309 }
00310
00311 ACE_END_VERSIONED_NAMESPACE_DECL