OS_NS_unistd.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // $Id: OS_NS_unistd.inl 81696 2008-05-14 18:15:31Z johnnyw $
00004 
00005 #include "ace/OS_NS_sys_utsname.h"
00006 #include "ace/OS_NS_string.h"
00007 #include "ace/OS_NS_errno.h"
00008 #include "ace/OS_NS_macros.h"
00009 #include "ace/OS_NS_fcntl.h"
00010 #include "ace/Default_Constants.h"
00011 #include "ace/OS_Memory.h"
00012 #include "ace/Truncate.h"
00013 
00014 #if defined (ACE_HAS_CLOCK_GETTIME)
00015 # include "ace/os_include/os_time.h"
00016 #endif /* ACE_HAS_CLOCK_GETTIME */
00017 
00018 #if defined (ACE_LACKS_ACCESS)
00019 #  include "ace/OS_NS_stdio.h"
00020 #endif /* ACE_LACKS_ACCESS */
00021 
00022 #if defined (ACE_VXWORKS) || defined (ACE_HAS_WINCE)
00023 #  include "ace/os_include/os_unistd.h"
00024 #  if defined (ACE_VXWORKS) && (((ACE_VXWORKS >= 0x620) && (ACE_VXWORKS <= 0x660)) || defined (ACE_HAS_VXWORKS551_MEDUSA))
00025 #    if defined (__RTP__)
00026 #      include "ace/os_include/os_strings.h"
00027 #    else
00028 #      include "ace/os_include/os_string.h"
00029 #    endif
00030 #  endif
00031 #endif /* VXWORKS || ACE_HAS_WINCE */
00032 
00033 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00034 
00035 ACE_INLINE int
00036 ACE_OS::access (const char *path, int amode)
00037 {
00038   ACE_OS_TRACE ("ACE_OS::access");
00039 #if defined (ACE_LACKS_ACCESS)
00040 #  if defined (ACE_HAS_WINCE) || defined (ACE_VXWORKS)
00041   // @@ WINCE: There should be a Win32 API that can do this.
00042   // Hard coded read access here.
00043   ACE_UNUSED_ARG (amode);
00044   FILE* handle = ACE_OS::fopen (ACE_TEXT_CHAR_TO_TCHAR(path),
00045                                 ACE_TEXT ("r"));
00046   if (handle != 0)
00047     {
00048       ACE_OS::fclose (handle);
00049       return 0;
00050     }
00051   return (-1);
00052 #  else
00053     ACE_UNUSED_ARG (path);
00054     ACE_UNUSED_ARG (amode);
00055     ACE_NOTSUP_RETURN (-1);
00056 #  endif  // ACE_HAS_WINCE
00057 #elif defined(ACE_WIN32)
00058   // Windows doesn't support checking X_OK(6)
00059   ACE_OSCALL_RETURN (::access (path, amode & 6), int, -1);
00060 #else
00061   ACE_OSCALL_RETURN (::access (path, amode), int, -1);
00062 #endif /* ACE_LACKS_ACCESS */
00063 }
00064 
00065 
00066 #if defined (ACE_HAS_WCHAR)
00067 ACE_INLINE int
00068 ACE_OS::access (const wchar_t *path, int amode)
00069 {
00070 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
00071   ACE_OSCALL_RETURN (::_waccess (path, amode), int, -1);
00072 #else /* ACE_WIN32 && !ACE_HAS_WINCE */
00073   return ACE_OS::access (ACE_Wide_To_Ascii (path).char_rep (), amode);
00074 #endif /* ACE_WIN32 && !ACE_HAS_WINCE */
00075 }
00076 #endif /* ACE_HAS_WCHAR */
00077 
00078 ACE_INLINE u_int
00079 ACE_OS::alarm (u_int secs)
00080 {
00081   ACE_OS_TRACE ("ACE_OS::alarm");
00082 #if defined (ACE_LACKS_ALARM)
00083   ACE_UNUSED_ARG (secs);
00084   ACE_NOTSUP_RETURN (0);
00085 #else
00086   return ::alarm (secs);
00087 #endif /* ACE_LACKS_ALARM */
00088 }
00089 
00090 ACE_INLINE long
00091 ACE_OS::getpagesize (void)
00092 {
00093   ACE_OS_TRACE ("ACE_OS::getpagesize");
00094 #if defined (ACE_WIN32) && !defined (ACE_HAS_PHARLAP)
00095   SYSTEM_INFO sys_info;
00096   ::GetSystemInfo (&sys_info);
00097   return (long) sys_info.dwPageSize;
00098 #elif defined (_SC_PAGESIZE) && !defined (ACE_HAS_NOTSUP_SC_PAGESIZE)
00099   return ::sysconf (_SC_PAGESIZE);
00100 #elif defined (ACE_HAS_GETPAGESIZE)
00101   return ::getpagesize ();
00102 #else
00103   // Use the default set in config.h
00104   return ACE_PAGE_SIZE;
00105 #endif /* ACE_WIN32 */
00106 }
00107 
00108 ACE_INLINE long
00109 ACE_OS::allocation_granularity (void)
00110 {
00111 #if defined (ACE_WIN32)
00112   SYSTEM_INFO sys_info;
00113   ::GetSystemInfo (&sys_info);
00114   return sys_info.dwAllocationGranularity;
00115 #else
00116   return ACE_OS::getpagesize ();
00117 #endif /* ACE_WIN32 */
00118 }
00119 
00120 #if !defined (ACE_LACKS_CHDIR)
00121 ACE_INLINE int
00122 ACE_OS::chdir (const char *path)
00123 {
00124   ACE_OS_TRACE ("ACE_OS::chdir");
00125 #if defined (ACE_HAS_NONCONST_CHDIR)
00126   ACE_OSCALL_RETURN (::chdir (const_cast<char *> (path)), int, -1);
00127 #elif defined (ACE_HAS_WINCE)
00128   ACE_UNUSED_ARG (path);
00129   ACE_NOTSUP_RETURN (-1);
00130 #else
00131   ACE_OSCALL_RETURN (::chdir (path), int, -1);
00132 #endif /* ACE_HAS_NONCONST_CHDIR */
00133 }
00134 
00135 #if defined (ACE_HAS_WCHAR)
00136 ACE_INLINE int
00137 ACE_OS::chdir (const wchar_t *path)
00138 {
00139 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
00140   ACE_OSCALL_RETURN (::_wchdir (path), int, -1);
00141 #else /* ACE_WIN32 */
00142   return ACE_OS::chdir (ACE_Wide_To_Ascii (path).char_rep ());
00143 #endif /* ACE_WIN32 */
00144 }
00145 #endif /* ACE_HAS_WCHAR */
00146 #endif /* ACE_LACKS_CHDIR */
00147 
00148 ACE_INLINE int
00149 ACE_OS::rmdir (const char *path)
00150 {
00151 #if defined (ACE_HAS_WINCE)
00152   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::RemoveDirectory (ACE_TEXT_CHAR_TO_TCHAR (path)),
00153                                           ace_result_),
00154                         int, -1);
00155 #else
00156   ACE_OSCALL_RETURN (::rmdir (path), int, -1);
00157 #endif /* ACE_WIN32 */
00158 }
00159 
00160 #if defined (ACE_HAS_WCHAR)
00161 ACE_INLINE int
00162 ACE_OS::rmdir (const wchar_t *path)
00163 {
00164 #if defined (ACE_HAS_WINCE)
00165   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::RemoveDirectoryW (path),
00166                                           ace_result_),
00167                         int, -1);
00168 #elif defined (ACE_WIN32)
00169   ACE_OSCALL_RETURN (::_wrmdir (path), int, -1);
00170 #else
00171   ACE_Wide_To_Ascii n_path (path);
00172   return ACE_OS::rmdir (n_path.char_rep ());
00173 #endif /* ACE_HAS_WINCE */
00174 }
00175 #endif /* ACE_HAS_WCHAR */
00176 
00177 // @todo: which 4 and why???  dhinton
00178 // NOTE: The following four function definitions must appear before
00179 // ACE_OS::sema_init ().
00180 
00181 ACE_INLINE int
00182 ACE_OS::close (ACE_HANDLE handle)
00183 {
00184   ACE_OS_TRACE ("ACE_OS::close");
00185 #if defined (ACE_WIN32)
00186   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::CloseHandle (handle), ace_result_), int, -1);
00187 #else
00188   ACE_OSCALL_RETURN (::close (handle), int, -1);
00189 #endif /* ACE_WIN32 */
00190 }
00191 
00192 ACE_INLINE ACE_HANDLE
00193 ACE_OS::dup (ACE_HANDLE handle)
00194 {
00195   ACE_OS_TRACE ("ACE_OS::dup");
00196 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
00197   ACE_HANDLE new_fd;
00198   if (::DuplicateHandle(::GetCurrentProcess (),
00199                         handle,
00200                         ::GetCurrentProcess(),
00201                         &new_fd,
00202                         0,
00203                         TRUE,
00204                         DUPLICATE_SAME_ACCESS))
00205     return new_fd;
00206   else
00207     ACE_FAIL_RETURN (ACE_INVALID_HANDLE);
00208   /* NOTREACHED */
00209 #elif defined (ACE_LACKS_DUP)
00210   ACE_UNUSED_ARG (handle);
00211   ACE_NOTSUP_RETURN (-1);
00212 #elif defined (ACE_HAS_WINCE)
00213   ACE_UNUSED_ARG (handle);
00214   ACE_NOTSUP_RETURN (0);
00215 #else
00216   ACE_OSCALL_RETURN (::dup (handle), ACE_HANDLE, ACE_INVALID_HANDLE);
00217 #endif /* ACE_WIN32 && !ACE_HAS_WINCE */
00218 }
00219 
00220 ACE_INLINE int
00221 ACE_OS::dup2 (ACE_HANDLE oldhandle, ACE_HANDLE newhandle)
00222 {
00223   ACE_OS_TRACE ("ACE_OS::dup2");
00224 #if defined (ACE_LACKS_DUP2)
00225   // msvcrt has _dup2 ?!
00226   ACE_UNUSED_ARG (oldhandle);
00227   ACE_UNUSED_ARG (newhandle);
00228   ACE_NOTSUP_RETURN (-1);
00229 #else
00230   ACE_OSCALL_RETURN (::dup2 (oldhandle, newhandle), int, -1);
00231 #endif /* ACE_LACKS_DUP2 */
00232 }
00233 
00234 ACE_INLINE int
00235 ACE_OS::execv (const char *path,
00236                char *const argv[])
00237 {
00238   ACE_OS_TRACE ("ACE_OS::execv");
00239 #if defined (ACE_LACKS_EXEC)
00240   ACE_UNUSED_ARG (path);
00241   ACE_UNUSED_ARG (argv);
00242 
00243   ACE_NOTSUP_RETURN (-1);
00244 #elif defined (ACE_WIN32)
00245 # if defined (__BORLANDC__) /* VSB */
00246   return ::execv (path, argv);
00247 # elif defined (__MINGW32__)
00248   return ::_execv (path, (char *const *) argv);
00249 # else
00250   // Why this odd-looking code? If execv() returns at all, it's an error.
00251   // Windows defines this as returning an intptr_t rather than a simple int,
00252   // and the conversion triggers compile warnings. So just return -1 if
00253   // the call returns.
00254   ::_execv (path, (const char *const *) argv);
00255   return -1;
00256 # endif /* __BORLANDC__ */
00257 #else
00258   ACE_OSCALL_RETURN (::execv (path, argv), int, -1);
00259 #endif /* ACE_LACKS_EXEC */
00260 }
00261 
00262 ACE_INLINE int
00263 ACE_OS::execve (const char *path,
00264                 char *const argv[],
00265                 char *const envp[])
00266 {
00267   ACE_OS_TRACE ("ACE_OS::execve");
00268 #if defined (ACE_LACKS_EXEC)
00269   ACE_UNUSED_ARG (path);
00270   ACE_UNUSED_ARG (argv);
00271   ACE_UNUSED_ARG (envp);
00272 
00273   ACE_NOTSUP_RETURN (-1);
00274 #elif defined (ACE_WIN32)
00275 # if defined (__BORLANDC__) /* VSB */
00276   return ::execve (path, argv, envp);
00277 # elif defined (__MINGW32__)
00278   return ::_execve (path, (char *const *) argv, (char *const *) envp);
00279 # else
00280   // Why this odd-looking code? If execv() returns at all, it's an error.
00281   // Windows defines this as returning an intptr_t rather than a simple int,
00282   // and the conversion triggers compile warnings. So just return -1 if
00283   // the call returns.
00284   ::_execve (path, (const char *const *) argv, (const char *const *) envp);
00285   return -1;
00286 # endif /* __BORLANDC__ */
00287 #else
00288   ACE_OSCALL_RETURN (::execve (path, argv, envp), int, -1);
00289 #endif /* ACE_LACKS_EXEC */
00290 }
00291 
00292 ACE_INLINE int
00293 ACE_OS::execvp (const char *file,
00294                 char *const argv[])
00295 {
00296   ACE_OS_TRACE ("ACE_OS::execvp");
00297 #if defined (ACE_LACKS_EXEC)
00298   ACE_UNUSED_ARG (file);
00299   ACE_UNUSED_ARG (argv);
00300 
00301   ACE_NOTSUP_RETURN (-1);
00302 #elif defined (ACE_WIN32)
00303 # if defined (__BORLANDC__) /* VSB */
00304   return ::execvp (file, argv);
00305 # elif defined (__MINGW32__)
00306   return ::_execvp (file, (char *const *) argv);
00307 # else
00308   // Why this odd-looking code? If execv() returns at all, it's an error.
00309   // Windows defines this as returning an intptr_t rather than a simple int,
00310   // and the conversion triggers compile warnings. So just return -1 if
00311   // the call returns.
00312   ::_execvp (file, (const char *const *) argv);
00313   return -1;
00314 # endif /* __BORLANDC__ */
00315 #else
00316   ACE_OSCALL_RETURN (::execvp (file, argv), int, -1);
00317 #endif /* ACE_LACKS_EXEC */
00318 }
00319 
00320 ACE_INLINE pid_t
00321 ACE_OS::fork (void)
00322 {
00323   ACE_OS_TRACE ("ACE_OS::fork");
00324 #if defined (ACE_LACKS_FORK)
00325   ACE_NOTSUP_RETURN (pid_t (-1));
00326 #else
00327   ACE_OSCALL_RETURN (::fork (), pid_t, -1);
00328 #endif /* ACE_LACKS_FORK */
00329 }
00330 
00331 ACE_INLINE int
00332 ACE_OS::fsync (ACE_HANDLE handle)
00333 {
00334   ACE_OS_TRACE ("ACE_OS::fsync");
00335 # if defined (ACE_LACKS_FSYNC)
00336   ACE_UNUSED_ARG (handle);
00337   ACE_NOTSUP_RETURN (-1);
00338 # elif defined (ACE_WIN32)
00339   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::FlushFileBuffers (handle), ace_result_), int, -1);
00340 # else
00341   ACE_OSCALL_RETURN (::fsync (handle), int, -1);
00342 # endif /* ACE_LACKS_FSYNC */
00343 }
00344 
00345 ACE_INLINE int
00346 ACE_OS::ftruncate (ACE_HANDLE handle, ACE_OFF_T offset)
00347 {
00348   ACE_OS_TRACE ("ACE_OS::ftruncate");
00349 #if defined (ACE_WIN32)
00350 #  if !defined (ACE_LACKS_WIN32_SETFILEPOINTEREX)
00351   LARGE_INTEGER loff;
00352   loff.QuadPart = offset;
00353   if (::SetFilePointerEx (handle, loff, 0, FILE_BEGIN))
00354 #  else
00355   if (::SetFilePointer (handle,
00356                         offset,
00357                         0,
00358                         FILE_BEGIN) != INVALID_SET_FILE_POINTER)
00359 #  endif
00360     ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::SetEndOfFile (handle), ace_result_), int, -1);
00361   else
00362     ACE_FAIL_RETURN (-1);
00363 #else
00364   ACE_OSCALL_RETURN (::ftruncate (handle, offset), int, -1);
00365 #endif /* ACE_WIN32 */
00366 }
00367 
00368 ACE_INLINE char *
00369 ACE_OS::getcwd (char *buf, size_t size)
00370 {
00371   ACE_OS_TRACE ("ACE_OS::getcwd");
00372 #if defined (ACE_LACKS_GETCWD)
00373   ACE_UNUSED_ARG (buf);
00374   ACE_UNUSED_ARG (size);
00375   ACE_NOTSUP_RETURN (0);
00376 #elif defined (ACE_WIN32)
00377   return ::getcwd (buf, static_cast<int> (size));
00378 #else
00379   ACE_OSCALL_RETURN (::getcwd (buf, size), char *, 0);
00380 #endif /* ACE_LACKS_GETCWD */
00381 }
00382 
00383 #if defined (ACE_HAS_WCHAR)
00384 ACE_INLINE wchar_t *
00385 ACE_OS::getcwd (wchar_t *buf, size_t size)
00386 {
00387 #  if defined (ACE_HAS_WINCE)
00388   ACE_UNUSED_ARG (buf);
00389   ACE_UNUSED_ARG (size);
00390   ACE_NOTSUP_RETURN (0);
00391 #  elif defined (ACE_WIN32)
00392   return ::_wgetcwd (buf, static_cast<int> (size));
00393 #  else
00394   char *narrow_buf = new char[size];
00395   char *result = 0;
00396   result = ACE_OS::getcwd (narrow_buf, size);
00397   ACE_Ascii_To_Wide wide_buf (result);
00398   delete [] narrow_buf;
00399   if (result != 0)
00400     ACE_OS::strsncpy (buf, wide_buf.wchar_rep (), size);
00401   return result == 0 ? 0 : buf;
00402 #  endif /* ACE_WIN32 */
00403 }
00404 #endif /* ACE_HAS_WCHAR */
00405 
00406 ACE_INLINE gid_t
00407 ACE_OS::getgid (void)
00408 {
00409   ACE_OS_TRACE ("ACE_OS::getgid");
00410 #if defined (ACE_LACKS_GETGID)
00411   ACE_NOTSUP_RETURN (static_cast<gid_t> (-1));
00412 # else
00413   ACE_OSCALL_RETURN (::getgid (), gid_t, static_cast<gid_t> (-1));
00414 # endif /* ACE_LACKS_GETGID */
00415 }
00416 
00417 ACE_INLINE gid_t
00418 ACE_OS::getegid (void)
00419 {
00420   ACE_OS_TRACE ("ACE_OS::getegid");
00421 #if defined (ACE_LACKS_GETEGID)
00422   ACE_NOTSUP_RETURN (static_cast<gid_t> (-1));
00423 # else
00424   ACE_OSCALL_RETURN (::getegid (), gid_t, static_cast<gid_t> (-1));
00425 # endif /* ACE_LACKS_GETEGID */
00426 }
00427 
00428 ACE_INLINE int
00429 ACE_OS::getopt (int argc, char *const *argv, const char *optstring)
00430 {
00431   ACE_OS_TRACE ("ACE_OS::getopt");
00432 #if defined (ACE_LACKS_GETOPT)
00433   ACE_UNUSED_ARG (argc);
00434   ACE_UNUSED_ARG (argv);
00435   ACE_UNUSED_ARG (optstring);
00436   ACE_NOTSUP_RETURN (-1);
00437 # else
00438   ACE_OSCALL_RETURN (::getopt (argc, argv, optstring), int, -1);
00439 # endif /* ACE_LACKS_GETOPT */
00440 }
00441 
00442 ACE_INLINE pid_t
00443 ACE_OS::getpgid (pid_t pid)
00444 {
00445   ACE_OS_TRACE ("ACE_OS::getpgid");
00446 #if defined (ACE_LACKS_GETPGID)
00447   ACE_UNUSED_ARG (pid);
00448   ACE_NOTSUP_RETURN (-1);
00449 #elif defined (linux) && __GLIBC__ > 1 && __GLIBC_MINOR__ >= 0
00450   // getpgid() is from SVR4, which appears to be the reason why GLIBC
00451   // doesn't enable its prototype by default.
00452   // Rather than create our own extern prototype, just use the one
00453   // that is visible (ugh).
00454   ACE_OSCALL_RETURN (::__getpgid (pid), pid_t, -1);
00455 #else
00456   ACE_OSCALL_RETURN (::getpgid (pid), pid_t, -1);
00457 #endif /* ACE_LACKS_GETPGID */
00458 }
00459 
00460 ACE_INLINE pid_t
00461 ACE_OS::getpid (void)
00462 {
00463   // ACE_OS_TRACE ("ACE_OS::getpid");
00464 #if defined (ACE_LACKS_GETPID)
00465   ACE_NOTSUP_RETURN (-1);
00466 #elif defined (ACE_WIN32)
00467   return ::GetCurrentProcessId ();
00468 #else
00469   ACE_OSCALL_RETURN (::getpid (), int, -1);
00470 #endif /* ACE_LACKS_GETPID */
00471 }
00472 
00473 ACE_INLINE pid_t
00474 ACE_OS::getppid (void)
00475 {
00476   ACE_OS_TRACE ("ACE_OS::getppid");
00477 #if defined (ACE_LACKS_GETPPID)
00478   ACE_NOTSUP_RETURN (-1);
00479 #else
00480   ACE_OSCALL_RETURN (::getppid (), pid_t, -1);
00481 #endif /* ACE_LACKS_GETPPID */
00482 }
00483 
00484 ACE_INLINE uid_t
00485 ACE_OS::getuid (void)
00486 {
00487   ACE_OS_TRACE ("ACE_OS::getuid");
00488 #if defined (ACE_LACKS_GETUID)
00489   ACE_NOTSUP_RETURN (static_cast<uid_t> (-1));
00490 # else
00491   ACE_OSCALL_RETURN (::getuid (), uid_t, static_cast<uid_t> (-1));
00492 # endif /* ACE_LACKS_GETUID*/
00493 }
00494 
00495 ACE_INLINE uid_t
00496 ACE_OS::geteuid (void)
00497 {
00498   ACE_OS_TRACE ("ACE_OS::geteuid");
00499 #if defined (ACE_LACKS_GETEUID)
00500   ACE_NOTSUP_RETURN (static_cast<uid_t> (-1));
00501 # else
00502   ACE_OSCALL_RETURN (::geteuid (), uid_t, (uid_t) -1);
00503 # endif /* ACE_LACKS_GETEUID */
00504 }
00505 
00506 ACE_INLINE int
00507 ACE_OS::hostname (char name[], size_t maxnamelen)
00508 {
00509   ACE_OS_TRACE ("ACE_OS::hostname");
00510 #if defined (ACE_HAS_PHARLAP)
00511   // PharLap only can do net stuff with the RT version.
00512 #   if defined (ACE_HAS_PHARLAP_RT)
00513   // @@This is not at all reliable... requires ethernet and BOOTP to be used.
00514   // A more reliable way is to go thru the devices w/ EtsTCPGetDeviceCfg until
00515   // a legit IP address is found, then get its name w/ gethostbyaddr.
00516   ACE_SOCKCALL_RETURN (gethostname (name, maxnamelen), int, SOCKET_ERROR);
00517 #   else
00518   ACE_UNUSED_ARG (name);
00519   ACE_UNUSED_ARG (maxnamelen);
00520   ACE_NOTSUP_RETURN (-1);
00521 #   endif /* ACE_HAS_PHARLAP_RT */
00522 #elif defined (ACE_VXWORKS) || defined (ACE_HAS_WINCE)
00523   ACE_OSCALL_RETURN (::gethostname (name, maxnamelen), int, -1);
00524 #elif defined (ACE_WIN32)
00525   if (::gethostname (name, ACE_Utils::truncate_cast<int> (maxnamelen)) == 0)
00526   {
00527     return 0;
00528   }
00529   else
00530   {
00531     ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::GetComputerNameA (name,
00532                                             LPDWORD (&maxnamelen)),
00533                                             ace_result_), int, -1);
00534   }
00535 #else /* ACE_HAS_PHARLAP */
00536   ACE_utsname host_info;
00537 
00538   if (ACE_OS::uname (&host_info) == -1)
00539     return -1;
00540   else
00541     {
00542       ACE_OS::strsncpy (name, host_info.nodename, maxnamelen);
00543       return 0;
00544     }
00545 #endif /* ACE_HAS_PHARLAP */
00546 }
00547 
00548 #if defined (ACE_HAS_WCHAR)
00549 ACE_INLINE int
00550 ACE_OS::hostname (wchar_t name[], size_t maxnamelen)
00551 {
00552 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
00553   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (GetComputerNameW (name,
00554                                                         LPDWORD (&maxnamelen)),
00555                                           ace_result_), int, -1);
00556 #else /* ACE_WIN32 && !ACE_HAS_WINCE */
00557   // Emulate using the char version
00558   char *char_name = 0;
00559   int result = 0;
00560 
00561   ACE_NEW_RETURN (char_name, char[maxnamelen], -1);
00562 
00563   result = ACE_OS::hostname(char_name, maxnamelen);
00564   ACE_OS::strcpy (name, ACE_Ascii_To_Wide (char_name).wchar_rep ());
00565 
00566   delete [] char_name;
00567   return result;
00568 #endif /* ACE_WIN32 && !ACE_HAS_WINCE */
00569 }
00570 #endif /* ACE_HAS_WCHAR */
00571 
00572 ACE_INLINE int
00573 ACE_OS::isatty (int handle)
00574 {
00575   ACE_OS_TRACE ("ACE_OS::isatty");
00576 #if defined (ACE_LACKS_ISATTY)
00577   ACE_UNUSED_ARG (handle);
00578   return 0;
00579 # elif defined (ACE_WIN32)
00580   return ::_isatty (handle);
00581 # else
00582   ACE_OSCALL_RETURN (::isatty (handle), int, -1);
00583 # endif /* ACE_LACKS_ISATTY */
00584 }
00585 
00586 #if defined (ACE_WIN32)
00587 ACE_INLINE int
00588 ACE_OS::isatty (ACE_HANDLE handle)
00589 {
00590 #if defined (ACE_LACKS_ISATTY)
00591   ACE_UNUSED_ARG (handle);
00592   return 0;
00593 #else
00594   int fd = ::_open_osfhandle (intptr_t (handle), 0);
00595   int status = ::_isatty (fd);
00596   ::_close (fd);
00597   return status;
00598 #endif /* ACE_LACKS_ISATTY */
00599 }
00600 
00601 #endif /* ACE_WIN32 */
00602 
00603 ACE_INLINE ACE_OFF_T
00604 ACE_OS::lseek (ACE_HANDLE handle, ACE_OFF_T offset, int whence)
00605 {
00606   ACE_OS_TRACE ("ACE_OS::lseek");
00607 #if defined (ACE_WIN32)
00608 # if SEEK_SET != FILE_BEGIN || SEEK_CUR != FILE_CURRENT || SEEK_END != FILE_END
00609   //#error Windows NT is evil AND rude!
00610   switch (whence)
00611     {
00612     case SEEK_SET:
00613       whence = FILE_BEGIN;
00614       break;
00615     case SEEK_CUR:
00616       whence = FILE_CURRENT;
00617       break;
00618     case SEEK_END:
00619       whence = FILE_END;
00620       break;
00621     default:
00622       errno = EINVAL;
00623       return static_cast<ACE_OFF_T> (-1); // rather safe than sorry
00624     }
00625 # endif  /* SEEK_SET != FILE_BEGIN || SEEK_CUR != FILE_CURRENT || SEEK_END != FILE_END */
00626   LONG low_offset = ACE_LOW_PART(offset);
00627   LONG high_offset = ACE_HIGH_PART(offset);
00628   DWORD const result =
00629     ::SetFilePointer (handle, low_offset, &high_offset, whence);
00630   if (result == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
00631     ACE_FAIL_RETURN (static_cast<ACE_OFF_T> (-1));
00632   else
00633     return result;
00634 #else
00635   ACE_OSCALL_RETURN (::lseek (handle, offset, whence), ACE_OFF_T, -1);
00636 #endif /* ACE_WIN32 */
00637 }
00638 
00639 #if defined (ACE_HAS_LLSEEK) || defined (ACE_HAS_LSEEK64)
00640 ACE_INLINE ACE_LOFF_T
00641 ACE_OS::llseek (ACE_HANDLE handle, ACE_LOFF_T offset, int whence)
00642 {
00643   ACE_OS_TRACE ("ACE_OS::llseek");
00644 
00645 #if ACE_SIZEOF_LONG == 8
00646   /* The native lseek is 64 bit.  Use it. */
00647   return ACE_OS::lseek (handle, offset, whence);
00648 #elif defined (ACE_HAS_LLSEEK) && defined (ACE_HAS_LSEEK64)
00649 # error Either ACE_HAS_LSEEK64 and ACE_HAS_LLSEEK should be defined, not both!
00650 #elif defined (ACE_HAS_LSEEK64)
00651   ACE_OSCALL_RETURN (::lseek64 (handle, offset, whence), ACE_LOFF_T, -1);
00652 #elif defined (ACE_HAS_LLSEEK)
00653 # if defined (ACE_WIN32)
00654 #  ifndef ACE_LACKS_WIN32_SETFILEPOINTEREX
00655   LARGE_INTEGER distance, new_file_pointer;
00656 
00657   distance.QuadPart = offset;
00658 
00659   return
00660     (::SetFilePointerEx (handle, distance, &new_file_pointer, whence)
00661      ? new_file_pointer.QuadPart
00662      : static_cast<ACE_LOFF_T> (-1));
00663 #  else
00664   LARGE_INTEGER l_offset;
00665   l_offset.QuadPart = offset;
00666   LONG low_offset = l_offset.LowPart;
00667   LONG high_offset = l_offset.HighPart;
00668 
00669   l_offset.LowPart = ::SetFilePointer (handle,
00670                                        low_offset,
00671                                        &high_offset,
00672                                        whence);
00673   if (l_offset.LowPart == INVALID_SET_FILE_POINTER &&
00674       GetLastError () != NO_ERROR)
00675     return static_cast<ACE_LOFF_T> (-1);
00676   l_offset.HighPart = high_offset;
00677   return l_offset.QuadPart;
00678 #  endif  /* ACE_LACKS_WIN32_SETFILEPOINTEREX */
00679 # else
00680     ACE_OSCALL_RETURN (::llseek (handle, offset, whence), ACE_LOFF_T, -1);
00681 # endif /* WIN32 */
00682 #endif
00683 }
00684 #endif /* ACE_HAS_LLSEEK || ACE_HAS_LSEEK64 */
00685 
00686 ACE_INLINE ssize_t
00687 ACE_OS::read (ACE_HANDLE handle, void *buf, size_t len)
00688 {
00689   ACE_OS_TRACE ("ACE_OS::read");
00690 #if defined (ACE_WIN32)
00691   DWORD ok_len;
00692   if (::ReadFile (handle, buf, static_cast<DWORD> (len), &ok_len, 0))
00693     return (ssize_t) ok_len;
00694   else
00695     ACE_FAIL_RETURN (-1);
00696 #else
00697 
00698   ssize_t result;
00699 
00700 # if defined (ACE_HAS_CHARPTR_SOCKOPT)
00701   ACE_OSCALL (::read (handle, static_cast <char *> (buf), len), ssize_t, -1, result);
00702 # else
00703   ACE_OSCALL (::read (handle, buf, len), ssize_t, -1, result);
00704 # endif /* ACE_HAS_CHARPTR_SOCKOPT */
00705 
00706 # if !(defined (EAGAIN) && defined (EWOULDBLOCK) && EAGAIN == EWOULDBLOCK)
00707   // Optimize this code out if we can detect that EAGAIN ==
00708   // EWOULDBLOCK at compile time.  If we cannot detect equality at
00709   // compile-time (e.g. if EAGAIN or EWOULDBLOCK are not preprocessor
00710   // macros) perform the check at run-time.  The goal is to avoid two
00711   // TSS accesses in the _REENTRANT case when EAGAIN == EWOULDBLOCK.
00712   if (result == -1
00713 #  if !defined (EAGAIN) || !defined (EWOULDBLOCK)
00714       && EAGAIN != EWOULDBLOCK
00715 #  endif  /* !EAGAIN || !EWOULDBLOCK */
00716       && errno == EAGAIN)
00717     {
00718       errno = EWOULDBLOCK;
00719     }
00720 # endif /* EAGAIN != EWOULDBLOCK*/
00721 
00722   return result;
00723 #endif /* ACE_WIN32 */
00724 }
00725 
00726 ACE_INLINE ssize_t
00727 ACE_OS::read (ACE_HANDLE handle, void *buf, size_t len,
00728               ACE_OVERLAPPED *overlapped)
00729 {
00730   ACE_OS_TRACE ("ACE_OS::read");
00731   overlapped = overlapped;
00732 #if defined (ACE_WIN32)
00733   DWORD ok_len;
00734   DWORD short_len = static_cast<DWORD> (len);
00735   if (::ReadFile (handle, buf, short_len, &ok_len, overlapped))
00736     return (ssize_t) ok_len;
00737   else
00738     ACE_FAIL_RETURN (-1);
00739 #else
00740   return ACE_OS::read (handle, buf, len);
00741 #endif /* ACE_WIN32 */
00742 }
00743 
00744 ACE_INLINE ssize_t
00745 ACE_OS::readlink (const char *path, char *buf, size_t bufsiz)
00746 {
00747   ACE_OS_TRACE ("ACE_OS::readlink");
00748 # if defined (ACE_LACKS_READLINK)
00749   ACE_UNUSED_ARG (path);
00750   ACE_UNUSED_ARG (buf);
00751   ACE_UNUSED_ARG (bufsiz);
00752   ACE_NOTSUP_RETURN (-1);
00753 # else
00754 #   if !defined(ACE_HAS_NONCONST_READLINK)
00755       ACE_OSCALL_RETURN (::readlink (path, buf, bufsiz), ssize_t, -1);
00756 #   else
00757       ACE_OSCALL_RETURN (
00758         ::readlink (const_cast <char *>(path), buf, bufsiz), ssize_t, -1);
00759 #   endif
00760 # endif /* ACE_LACKS_READLINK */
00761 }
00762 
00763 ACE_INLINE int
00764 ACE_OS::pipe (ACE_HANDLE fds[])
00765 {
00766   ACE_OS_TRACE ("ACE_OS::pipe");
00767 # if defined (ACE_LACKS_PIPE)
00768   ACE_UNUSED_ARG (fds);
00769   ACE_NOTSUP_RETURN (-1);
00770 # elif defined (ACE_WIN32)
00771   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL
00772                         (::CreatePipe (&fds[0], &fds[1], 0, 0),
00773                          ace_result_), int, -1);
00774 # else
00775   ACE_OSCALL_RETURN (::pipe (fds), int, -1);
00776 # endif /* ACE_LACKS_PIPE */
00777 }
00778 
00779 ACE_INLINE void *
00780 ACE_OS::sbrk (intptr_t brk)
00781 {
00782 #if defined (ACE_LACKS_SBRK)
00783   ACE_UNUSED_ARG (brk);
00784   ACE_NOTSUP_RETURN (0);
00785 #else
00786   ACE_OSCALL_RETURN (::sbrk (brk), void *, 0);
00787 #endif /* ACE_LACKS_SBRK */
00788 }
00789 
00790 ACE_INLINE int
00791 ACE_OS::setgid (gid_t gid)
00792 {
00793   ACE_OS_TRACE ("ACE_OS::setgid");
00794 #if defined (ACE_LACKS_SETGID)
00795   ACE_UNUSED_ARG (gid);
00796   ACE_NOTSUP_RETURN (-1);
00797 # else
00798   ACE_OSCALL_RETURN (::setgid (gid), int,  -1);
00799 # endif /* ACE_LACKS_SETGID */
00800 }
00801 
00802 ACE_INLINE int
00803 ACE_OS::setegid (gid_t gid)
00804 {
00805   ACE_OS_TRACE ("ACE_OS::setegid");
00806 #if defined (ACE_LACKS_SETEGID)
00807   ACE_UNUSED_ARG (gid);
00808   ACE_NOTSUP_RETURN (-1);
00809 # else
00810   ACE_OSCALL_RETURN (::setegid (gid), int,  -1);
00811 # endif /* ACE_LACKS_SETEGID */
00812 }
00813 
00814 ACE_INLINE int
00815 ACE_OS::setpgid (pid_t pid, pid_t pgid)
00816 {
00817   ACE_OS_TRACE ("ACE_OS::setpgid");
00818 #if defined (ACE_LACKS_SETPGID)
00819   ACE_UNUSED_ARG (pid);
00820   ACE_UNUSED_ARG (pgid);
00821   ACE_NOTSUP_RETURN (-1);
00822 #else
00823   ACE_OSCALL_RETURN (::setpgid (pid, pgid), int, -1);
00824 #endif /* ACE_LACKS_SETPGID */
00825 }
00826 
00827 ACE_INLINE int
00828 ACE_OS::setregid (gid_t rgid, gid_t egid)
00829 {
00830   ACE_OS_TRACE ("ACE_OS::setregid");
00831 #if defined (ACE_LACKS_SETREGID)
00832   ACE_UNUSED_ARG (rgid);
00833   ACE_UNUSED_ARG (egid);
00834   ACE_NOTSUP_RETURN (-1);
00835 #else
00836   ACE_OSCALL_RETURN (::setregid (rgid, egid), int, -1);
00837 #endif /* ACE_LACKS_SETREGID */
00838 }
00839 
00840 ACE_INLINE int
00841 ACE_OS::setreuid (uid_t ruid, uid_t euid)
00842 {
00843   ACE_OS_TRACE ("ACE_OS::setreuid");
00844 #if defined (ACE_LACKS_SETREUID)
00845   ACE_UNUSED_ARG (ruid);
00846   ACE_UNUSED_ARG (euid);
00847   ACE_NOTSUP_RETURN (-1);
00848 #else
00849   ACE_OSCALL_RETURN (::setreuid (ruid, euid), int, -1);
00850 #endif /* ACE_LACKS_SETREUID */
00851 }
00852 
00853 ACE_INLINE pid_t
00854 ACE_OS::setsid (void)
00855 {
00856   ACE_OS_TRACE ("ACE_OS::setsid");
00857 #if defined (ACE_LACKS_SETSID)
00858   ACE_NOTSUP_RETURN (-1);
00859 #else
00860   ACE_OSCALL_RETURN (::setsid (), int, -1);
00861 # endif /* ACE_LACKS_SETSID */
00862 }
00863 
00864 ACE_INLINE int
00865 ACE_OS::setuid (uid_t uid)
00866 {
00867   ACE_OS_TRACE ("ACE_OS::setuid");
00868 #if defined (ACE_LACKS_SETUID)
00869   ACE_UNUSED_ARG (uid);
00870   ACE_NOTSUP_RETURN (-1);
00871 # else
00872   ACE_OSCALL_RETURN (::setuid (uid), int,  -1);
00873 # endif /* ACE_LACKS_SETUID */
00874 }
00875 
00876 ACE_INLINE int
00877 ACE_OS::seteuid (uid_t uid)
00878 {
00879   ACE_OS_TRACE ("ACE_OS::seteuid");
00880 #if defined (ACE_LACKS_SETEUID)
00881   ACE_UNUSED_ARG (uid);
00882   ACE_NOTSUP_RETURN (-1);
00883 # else
00884   ACE_OSCALL_RETURN (::seteuid (uid), int,  -1);
00885 # endif /* ACE_LACKS_SETEUID */
00886 }
00887 
00888 ACE_INLINE int
00889 ACE_OS::sleep (u_int seconds)
00890 {
00891   ACE_OS_TRACE ("ACE_OS::sleep");
00892 #if defined (ACE_WIN32)
00893   ::Sleep (seconds * ACE_ONE_SECOND_IN_MSECS);
00894   return 0;
00895 #elif defined (ACE_HAS_CLOCK_GETTIME)
00896   struct timespec rqtp;
00897   // Initializer doesn't work with Green Hills 1.8.7
00898   rqtp.tv_sec = seconds;
00899   rqtp.tv_nsec = 0L;
00900   //FUZZ: disable check_for_lack_ACE_OS
00901   ACE_OSCALL_RETURN (::nanosleep (&rqtp, 0), int, -1);
00902   //FUZZ: enable check_for_lack_ACE_OS
00903 #else
00904   ACE_OSCALL_RETURN (::sleep (seconds), int, -1);
00905 #endif /* ACE_WIN32 */
00906 }
00907 
00908 ACE_INLINE int
00909 ACE_OS::sleep (const ACE_Time_Value &tv)
00910 {
00911   ACE_OS_TRACE ("ACE_OS::sleep");
00912 #if defined (ACE_WIN32)
00913   ::Sleep (tv.msec ());
00914   return 0;
00915 #elif defined (ACE_HAS_CLOCK_GETTIME)
00916   timespec_t rqtp = tv;
00917   //FUZZ: disable check_for_lack_ACE_OS
00918   ACE_OSCALL_RETURN (::nanosleep (&rqtp, 0), int, -1);
00919   //FUZZ: enable check_for_lack_ACE_OS
00920 #else
00921 # if defined (ACE_HAS_NONCONST_SELECT_TIMEVAL)
00922   // Copy the timeval, because this platform doesn't declare the timeval
00923   // as a pointer to const.
00924   timeval tv_copy = tv;
00925 #  if defined(ACE_TANDEM_T1248_PTHREADS)
00926      ACE_OSCALL_RETURN (::spt_select (0, 0, 0, 0, &tv_copy), int, -1);
00927 #  else
00928      //FUZZ: disable check_for_lack_ACE_OS
00929      ACE_OSCALL_RETURN (::select (0, 0, 0, 0, &tv_copy), int, -1);
00930      //FUZZ: enable check_for_lack_ACE_OS
00931 #  endif
00932 # else  /* ! ACE_HAS_NONCONST_SELECT_TIMEVAL */
00933   const timeval *tvp = tv;
00934   //FUZZ: disable check_for_lack_ACE_OS
00935   ACE_OSCALL_RETURN (::select (0, 0, 0, 0, tvp), int, -1);
00936   //FUZZ: enable check_for_lack_ACE_OS
00937 # endif /* ACE_HAS_NONCONST_SELECT_TIMEVAL */
00938 #endif /* ACE_WIN32 */
00939 }
00940 
00941 ACE_INLINE void
00942 ACE_OS::swab (const void *src,
00943               void *dest,
00944               ssize_t length)
00945 {
00946 #if defined (ACE_LACKS_SWAB)
00947   // ------------------------------------------------------------
00948   // The following copyright notice applies to the swab()
00949   // implementation within this "ACE_LACKS_SWAB" block of code.
00950   // ------------------------------------------------------------
00951   /*
00952     Copyright (c) 1994-2006  Red Hat, Inc. All rights reserved.
00953 
00954     This copyrighted material is made available to anyone wishing to
00955     use, modify, copy, or redistribute it subject to the terms and
00956     conditions of the BSD License.   This program is distributed in
00957     the hope that it will be useful, but WITHOUT ANY WARRANTY
00958     expressed or implied, including the implied warranties of
00959     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  A copy of
00960     this license is available at
00961     http://www.opensource.org/licenses. Any Red Hat trademarks that
00962     are incorporated in the source code or documentation are not
00963     subject to the BSD License and may only be used or replicated with
00964     the express permission of Red Hat, Inc.
00965   */
00966 
00967   const char *from = static_cast<const char*> (src);
00968   char *to = static_cast<char *> (dest);
00969   ssize_t ptr = 0;
00970   for (ptr = 1; ptr < length; ptr += 2)
00971     {
00972       char p = from[ptr];
00973       char q = from[ptr-1];
00974       to[ptr-1] = p;
00975       to[ptr  ] = q;
00976     }
00977   if (ptr == length) /* I.e., if length is odd, */
00978     to[ptr-1] = 0;   /* then pad with a NUL. */
00979 #elif defined (ACE_HAS_NONCONST_SWAB)
00980   const char *tmp = static_cast<const char*> (src);
00981   char *from = const_cast<char *> (tmp);
00982   char *to = static_cast<char *> (dest);
00983   ::swab (from, to, length);
00984 #elif defined (ACE_HAS_CONST_CHAR_SWAB)
00985   const char *from = static_cast<const char*> (src);
00986   char *to = static_cast<char *> (dest);
00987   ::swab (from, to, length);
00988 #else
00989   ::swab (src, dest, length);
00990 #endif /* ACE_LACKS_SWAB */
00991 
00992 }
00993 
00994 ACE_INLINE long
00995 ACE_OS::sysconf (int name)
00996 {
00997   ACE_OS_TRACE ("ACE_OS::sysconf");
00998 #if defined (ACE_LACKS_SYSCONF)
00999   ACE_UNUSED_ARG (name);
01000   ACE_NOTSUP_RETURN (-1);
01001 #else
01002   ACE_OSCALL_RETURN (::sysconf (name), long, -1);
01003 #endif /* ACE_LACKS_SYSCONF */
01004 }
01005 
01006 ACE_INLINE long
01007 ACE_OS::sysinfo (int cmd, char *buf, long count)
01008 {
01009   ACE_OS_TRACE ("ACE_OS::sysinfo");
01010 #if defined (ACE_HAS_SYSINFO)
01011   ACE_OSCALL_RETURN (::sysinfo (cmd, buf, count), long, -1);
01012 #else
01013   ACE_UNUSED_ARG (cmd);
01014   ACE_UNUSED_ARG (buf);
01015   ACE_UNUSED_ARG (count);
01016 
01017   ACE_NOTSUP_RETURN (0);
01018 #endif /* ACE_HAS_SYSINFO */
01019 }
01020 
01021 ACE_INLINE int
01022 ACE_OS::truncate (const ACE_TCHAR *filename,
01023                   ACE_OFF_T offset)
01024 {
01025   ACE_OS_TRACE ("ACE_OS::truncate");
01026 #if defined (ACE_WIN32)
01027   ACE_HANDLE handle = ACE_OS::open (filename,
01028                                     O_WRONLY,
01029                                     ACE_DEFAULT_FILE_PERMS);
01030 
01031 #  if !defined (ACE_LACKS_WIN32_SETFILEPOINTEREX)
01032   LARGE_INTEGER loffset;
01033   loffset.QuadPart = offset;
01034 #else
01035   LONG low_offset = ACE_LOW_PART(offset);
01036   LONG high_offset = ACE_HIGH_PART(offset);
01037 #endif
01038 
01039   if (handle == ACE_INVALID_HANDLE)
01040     ACE_FAIL_RETURN (-1);
01041 
01042 #  if !defined (ACE_LACKS_WIN32_SETFILEPOINTEREX)
01043   else if (::SetFilePointerEx (handle,
01044                                loffset,
01045                                0,
01046                                FILE_BEGIN))
01047 #  else
01048   else if (::SetFilePointer (handle,
01049                              low_offset,
01050                              &high_offset,
01051                              FILE_BEGIN) != INVALID_SET_FILE_POINTER
01052            || GetLastError () == NO_ERROR)
01053 #  endif /* ACE_LACKS_WIN32_SETFILEPOINTEREX */
01054     {
01055       BOOL result = ::SetEndOfFile (handle);
01056       ::CloseHandle (handle);
01057       ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (result, ace_result_), int, -1);
01058     }
01059   else
01060     {
01061       ::CloseHandle (handle);
01062       ACE_FAIL_RETURN (-1);
01063     }
01064   /* NOTREACHED */
01065 #elif !defined (ACE_LACKS_TRUNCATE)
01066   ACE_OSCALL_RETURN
01067     (::truncate (ACE_TEXT_ALWAYS_CHAR (filename), offset), int, -1);
01068 #else
01069   ACE_UNUSED_ARG (filename);
01070   ACE_UNUSED_ARG (offset);
01071   ACE_NOTSUP_RETURN (-1);
01072 #endif /* ACE_WIN32 */
01073 }
01074 
01075 ACE_INLINE useconds_t
01076 ACE_OS::ualarm (useconds_t usecs, useconds_t interval)
01077 {
01078   ACE_OS_TRACE ("ACE_OS::ualarm");
01079 
01080 #if defined (ACE_HAS_UALARM)
01081   return ::ualarm (usecs, interval);
01082 #elif !defined (ACE_LACKS_UNIX_SIGNALS)
01083   ACE_UNUSED_ARG (interval);
01084   return ::alarm (usecs * ACE_ONE_SECOND_IN_USECS);
01085 #else
01086   ACE_UNUSED_ARG (usecs);
01087   ACE_UNUSED_ARG (interval);
01088   ACE_NOTSUP_RETURN (0);
01089 #endif /* ACE_HAS_UALARM */
01090 }
01091 
01092 ACE_INLINE useconds_t
01093 ACE_OS::ualarm (const ACE_Time_Value &tv,
01094                 const ACE_Time_Value &tv_interval)
01095 {
01096   ACE_OS_TRACE ("ACE_OS::ualarm");
01097 
01098 #if defined (ACE_HAS_UALARM)
01099   useconds_t usecs = (tv.sec () * ACE_ONE_SECOND_IN_USECS) + tv.usec ();
01100   useconds_t interval =
01101     (tv_interval.sec () * ACE_ONE_SECOND_IN_USECS) + tv_interval.usec ();
01102   return ::ualarm (usecs, interval);
01103 #elif !defined (ACE_LACKS_UNIX_SIGNALS)
01104   ACE_UNUSED_ARG (tv_interval);
01105   return ::alarm (tv.sec ());
01106 #else
01107   ACE_UNUSED_ARG (tv_interval);
01108   ACE_UNUSED_ARG (tv);
01109   ACE_NOTSUP_RETURN (0);
01110 #endif /* ACE_HAS_UALARM */
01111 }
01112 
01113 ACE_INLINE int
01114 ACE_OS::unlink (const char *path)
01115 {
01116   ACE_OS_TRACE ("ACE_OS::unlink");
01117 # if defined (ACE_HAS_NONCONST_UNLINK)
01118   ACE_OSCALL_RETURN (::unlink (const_cast<char *> (path)), int, -1);
01119 # elif defined (ACE_HAS_WINCE)
01120   // @@ The problem is, DeleteFile is not actually equals to unlink. ;(
01121   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::DeleteFile (ACE_TEXT_CHAR_TO_TCHAR (path)), ace_result_),
01122                         int, -1);
01123 # elif defined (ACE_LACKS_UNLINK)
01124   ACE_UNUSED_ARG (path);
01125   ACE_NOTSUP_RETURN (-1);
01126 # else
01127   ACE_OSCALL_RETURN (::unlink (path), int, -1);
01128 # endif /* ACE_HAS_NONCONST_UNLINK */
01129 }
01130 
01131 #if defined (ACE_HAS_WCHAR)
01132 ACE_INLINE int
01133 ACE_OS::unlink (const wchar_t *path)
01134 {
01135   ACE_OS_TRACE ("ACE_OS::unlink");
01136 # if defined (ACE_HAS_WINCE)
01137   // @@ The problem is, DeleteFile is not actually equals to unlink. ;(
01138   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::DeleteFileW (path), ace_result_),
01139                         int, -1);
01140 # elif defined (ACE_WIN32)
01141   ACE_OSCALL_RETURN (::_wunlink (path), int, -1);
01142 # else
01143   ACE_Wide_To_Ascii npath (path);
01144   return ACE_OS::unlink (npath.char_rep ());
01145 # endif /* ACE_HAS_WINCE */
01146 }
01147 #endif /* ACE_HAS_WCHAR */
01148 
01149 ACE_INLINE ssize_t
01150 ACE_OS::write (ACE_HANDLE handle, const void *buf, size_t nbyte)
01151 {
01152   ACE_OS_TRACE ("ACE_OS::write");
01153 #if defined (ACE_WIN32)
01154   DWORD bytes_written; // This is set to 0 byte WriteFile.
01155 
01156   // Strictly correctly, we should loop writing all the data if more
01157   // than a DWORD length can hold.
01158   DWORD short_nbyte = static_cast<DWORD> (nbyte);
01159   if (::WriteFile (handle, buf, short_nbyte, &bytes_written, 0))
01160     return (ssize_t) bytes_written;
01161   else
01162     ACE_FAIL_RETURN (-1);
01163 #else
01164 # if defined (ACE_HAS_CHARPTR_SOCKOPT)
01165   ACE_OSCALL_RETURN (::write (handle, static_cast <char *> (const_cast <void *> (buf)), nbyte), ssize_t, -1);
01166 # else
01167   ACE_OSCALL_RETURN (::write (handle, buf, nbyte), ssize_t, -1);
01168 # endif /* ACE_HAS_CHARPTR_SOCKOPT */
01169 #endif /* ACE_WIN32 */
01170 }
01171 
01172 ACE_INLINE ssize_t
01173 ACE_OS::write (ACE_HANDLE handle,
01174                const void *buf,
01175                size_t nbyte,
01176                ACE_OVERLAPPED *overlapped)
01177 {
01178   ACE_OS_TRACE ("ACE_OS::write");
01179   overlapped = overlapped;
01180 #if defined (ACE_WIN32)
01181   DWORD bytes_written; // This is set to 0 byte WriteFile.
01182 
01183   DWORD short_nbyte = static_cast<DWORD> (nbyte);
01184   if (::WriteFile (handle, buf, short_nbyte, &bytes_written, overlapped))
01185     return (ssize_t) bytes_written;
01186   else
01187     ACE_FAIL_RETURN (-1);
01188 #else
01189   return ACE_OS::write (handle, buf, nbyte);
01190 #endif /* ACE_WIN32 */
01191 }
01192 
01193 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:18:41 2010 for ACE by  doxygen 1.4.7