Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

OS.i

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // $Id: OS.i,v 1.1.1.4.2.4 2003/06/03 21:54:44 michel_j Exp $
00003 
00004 #if defined (__CYGWIN32__)
00005 #  include /**/ <getopt.h>
00006 #endif
00007 
00008 #if !defined (ACE_HAS_INLINED_OSCALLS)
00009 # undef ACE_INLINE
00010 # define ACE_INLINE
00011 #endif /* ACE_HAS_INLINED_OSCALLS */
00012 
00013 #if defined (ACE_LACKS_RLIMIT_PROTOTYPE)
00014 int getrlimit (int resource, struct rlimit *rlp);
00015 int setrlimit (int resource, const struct rlimit *rlp);
00016 #endif /* ACE_LACKS_RLIMIT_PROTOTYPE */
00017 
00018 #if !defined (ACE_HAS_STRERROR)
00019 # if defined (ACE_HAS_SYS_ERRLIST)
00020 extern char *sys_errlist[];
00021 #   define strerror(err) sys_errlist[err]
00022 # else
00023 #   define strerror(err) "strerror is unsupported"
00024 # endif /* ACE_HAS_SYS_ERRLIST */
00025 #endif /* !ACE_HAS_STERROR */
00026 
00027 #if defined (ACE_HAS_SYS_SIGLIST)
00028 # if !defined (_sys_siglist)
00029 #   define _sys_siglist sys_siglist
00030 # endif /* !defined (sys_siglist) */
00031 //extern char **_sys_siglist;
00032 #endif /* ACE_HAS_SYS_SIGLIST */
00033 
00034 #if defined (ACE_HAS_SOCKLEN_T)
00035 typedef socklen_t ACE_SOCKET_LEN;
00036 #elif defined (ACE_HAS_SIZET_SOCKET_LEN)
00037 typedef size_t ACE_SOCKET_LEN;
00038 #else
00039 typedef int ACE_SOCKET_LEN;
00040 #endif /* ACE_HAS_SIZET_SOCKET_LEN */
00041 
00042 #if defined (ACE_LACKS_CONST_STRBUF_PTR)
00043 typedef struct strbuf *ACE_STRBUF_TYPE;
00044 #else
00045 typedef const struct strbuf *ACE_STRBUF_TYPE;
00046 #endif /* ACE_LACKS_CONST_STRBUF_PTR */
00047 
00048 #if defined (ACE_HAS_VOIDPTR_SOCKOPT)
00049 typedef void *ACE_SOCKOPT_TYPE1;
00050 #elif defined (ACE_HAS_CHARPTR_SOCKOPT)
00051 typedef char *ACE_SOCKOPT_TYPE1;
00052 #else
00053 typedef const char *ACE_SOCKOPT_TYPE1;
00054 #endif /* ACE_HAS_VOIDPTR_SOCKOPT */
00055 
00056 #if (!defined (_BSD_SOURCE) && \
00057     !defined (_XOPEN_SOURCE) && !defined (_XOPEN_SOURCE_EXTENDED)) \
00058     || (defined (_XOPEN_SOURCE) && defined (__GNUC__))
00059 
00060 # if defined (ACE_LACKS_SETREUID_PROTOTYPE)
00061 extern "C" {
00062 extern int setreuid (uid_t ruid, uid_t euid);
00063 }
00064 # endif /* ACE_LACKS_SETREUID_PROTOTYPE */
00065 
00066 # if defined (ACE_LACKS_SETREGID_PROTOTYPE)
00067 extern "C" {
00068 extern int setregid (gid_t rgid, gid_t egid);
00069 }
00070 # endif /* ACE_LACKS_SETREGID_PROTOTYPE */
00071 #endif  /* !_BSD_SOURCE && !_XOPEN_SOURCE && !_XOPEN_SOURCE_EXTENDED
00072            || _XOPEN_SOURCE && __GNUC__ */
00073 
00074 #if defined (ACE_NEEDS_FTRUNCATE)
00075 extern "C" ACE_Export int ftruncate (ACE_HANDLE handle, long len);
00076 #endif /* ACE_NEEDS_FTRUNCATE */
00077 
00078 #if defined (ACE_HAS_VOIDPTR_MMAP)
00079 // Needed for some odd OS's (e.g., SGI).
00080 typedef void *ACE_MMAP_TYPE;
00081 #else
00082 typedef char *ACE_MMAP_TYPE;
00083 #endif /* ACE_HAS_VOIDPTR_MMAP */
00084 
00085 #if defined (ACE_HAS_XLI)
00086 # include /**/ <xliuser.h>
00087 #endif /* ACE_HAS_XLI */
00088 
00089 #if defined (_M_UNIX)
00090 extern "C" int _dlclose (void *);
00091 extern "C" char *_dlerror (void);
00092 extern "C" void *_dlopen (const char *, int);
00093 extern "C" void * _dlsym (void *, const char *);
00094 #endif /* _M_UNIX */
00095 
00096 #if !defined (ACE_HAS_CPLUSPLUS_HEADERS)
00097 # include /**/ <libc.h>
00098 # include /**/ <osfcn.h>
00099 #endif /* ACE_HAS_CPLUSPLUS_HEADERS */
00100 
00101 #if defined (ACE_HAS_SYSENT_H)
00102 # include /**/ <sysent.h>
00103 #endif /* ACE_HAS_SYSENT_H_*/
00104 
00105 #if defined (ACE_USES_STD_NAMESPACE_FOR_STDC_LIB) && \
00106             (ACE_USES_STD_NAMESPACE_FOR_STDC_LIB != 0)
00107 using std::bsearch;
00108 using std::qsort;
00109 # if defined (ACE_WIN32)
00110 using std::_tzset;
00111 # else
00112 using std::tzset;
00113 # endif
00114 using std::ctime;
00115 using std::localtime;
00116 using std::gmtime;
00117 using std::asctime;
00118 using std::strftime;
00119 #endif /* ACE_USES_STD_NAMESPACE_FOR_STDC_LIB */
00120 
00121 #if defined (ACE_HAS_SVR4_GETTIMEOFDAY)
00122 # if !defined (m88k) && !defined (SCO)
00123 extern "C" int gettimeofday (struct timeval *tp, void * = 0);
00124 # else
00125 extern "C" int gettimeofday (struct timeval *tp);
00126 # endif  /*  !m88k && !SCO */
00127 #elif defined (ACE_HAS_OSF1_GETTIMEOFDAY)
00128 extern "C" int gettimeofday (struct timeval *tp, struct timezone * = 0);
00129 #elif defined (ACE_HAS_SUNOS4_GETTIMEOFDAY)
00130 # define ACE_HAS_SVR4_GETTIMEOFDAY
00131 #endif /* ACE_HAS_SVR4_GETTIMEOFDAY */
00132 
00133 #if defined (ACE_LACKS_CONST_TIMESPEC_PTR)
00134 typedef struct timespec * ACE_TIMESPEC_PTR;
00135 #else
00136 typedef const struct timespec * ACE_TIMESPEC_PTR;
00137 #endif /* HPUX */
00138 
00139 #if !defined (ACE_LACKS_MALLOC_H)
00140 # include /**/ <malloc.h>
00141 #endif /* ACE_LACKS_MALLOC_H */
00142 
00143 ACE_INLINE int
00144 ACE_OS::fcntl (ACE_HANDLE handle, int cmd, long arg)
00145 {
00146   ACE_OS_TRACE ("ACE_OS::fcntl");
00147 # if defined (ACE_LACKS_FCNTL)
00148   ACE_UNUSED_ARG (handle);
00149   ACE_UNUSED_ARG (cmd);
00150   ACE_UNUSED_ARG (arg);
00151   ACE_NOTSUP_RETURN (-1);
00152 # else
00153   ACE_OSCALL_RETURN (::fcntl (handle, cmd, arg), int, -1);
00154 # endif /* ACE_LACKS_FCNTL */
00155 }
00156 
00157 #if !defined (ACE_LACKS_CHDIR)
00158 ACE_INLINE int
00159 ACE_OS::chdir (const char *path)
00160 {
00161   ACE_OS_TRACE ("ACE_OS::chdir");
00162 #if defined (VXWORKS)
00163   ACE_OSCALL_RETURN (::chdir (ACE_const_cast (char *, path)), int, -1);
00164 
00165 #elif defined (ACE_PSOS_LACKS_PHILE)
00166   ACE_UNUSED_ARG (path);
00167   ACE_NOTSUP_RETURN (-1);
00168 
00169 #elif defined (ACE_PSOS)
00170     ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::change_dir ((char *) path), ace_result_),
00171                      int, -1);
00172 
00173 // This #elif seems weird... is Visual Age on NT not setting ACE_WIN32?
00174 #elif !defined (ACE_WIN32) && !defined (AIX) && defined (__IBMCPP__) && (__IBMCPP__ >= 400)
00175   ACE_OSCALL_RETURN (::_chdir (path), int, -1);
00176 
00177 #elif defined (ACE_HAS_WINCE)
00178   ACE_UNUSED_ARG (path);
00179   ACE_NOTSUP_RETURN (-1);
00180 
00181 #else
00182   ACE_OSCALL_RETURN (::chdir (path), int, -1);
00183 
00184 #endif /* VXWORKS */
00185 }
00186 
00187 #if defined (ACE_HAS_WCHAR)
00188 ACE_INLINE int
00189 ACE_OS::chdir (const wchar_t *path)
00190 {
00191 #if defined (ACE_WIN32)
00192   ACE_OSCALL_RETURN (::_wchdir (path), int, -1);
00193 #else /* ACE_WIN32 */
00194   return ACE_OS::chdir (ACE_Wide_To_Ascii (path).char_rep ());
00195 #endif /* ACE_WIN32 */
00196 }
00197 #endif /* ACE_HAS_WCHAR */
00198 #endif /* ACE_LACKS_CHDIR */
00199 
00200 #if !defined (ACE_LACKS_MKTEMP)
00201 ACE_INLINE ACE_TCHAR *
00202 ACE_OS::mktemp (ACE_TCHAR *s)
00203 {
00204 # if defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
00205   return ::_wmktemp (s);
00206 # elif defined (ACE_WIN32)
00207   return ::_mktemp (s);
00208 # else /* ACE_WIN32 */
00209   return ::mktemp (s);
00210 # endif /* ACE_WIN32 */
00211 }
00212 #endif /* !ACE_LACKS_MKTEMP */
00213 
00214 #if !defined (ACE_LACKS_MKSTEMP)
00215 ACE_INLINE ACE_HANDLE
00216 ACE_OS::mkstemp (ACE_TCHAR *s)
00217 {
00218   return ::mkstemp (s);
00219 }
00220 #endif /* !ACE_LACKS_MKSTEMP */
00221 
00222 ACE_INLINE int
00223 ACE_OS::mkfifo (const ACE_TCHAR *file, mode_t mode)
00224 {
00225   ACE_OS_TRACE ("ACE_OS::mkfifo");
00226 #if defined (ACE_LACKS_MKFIFO)
00227   ACE_UNUSED_ARG (file);
00228   ACE_UNUSED_ARG (mode);
00229   ACE_NOTSUP_RETURN (-1);
00230 #else
00231   ACE_OSCALL_RETURN (::mkfifo (file, mode), int, -1);
00232 #endif /* ACE_LACKS_MKFIFO */
00233 }
00234 
00235 #if !defined (ACE_WIN32)
00236 
00237 // Matthew Stevens 7-10-95 Fix GNU GCC 2.7 for memchr() problem.
00238 # if defined (ACE_HAS_GNU_CSTRING_H)
00239 // Define this file to keep /usr/include/memory.h from being included.
00240 #   include /**/ <cstring>
00241 # else
00242 #   if defined (ACE_LACKS_MEMORY_H)
00243 #     if !defined (ACE_PSOS_DIAB_MIPS)
00244 #       include /**/ <string.h>
00245 #     endif /* ACE_PSOS_DIAB_MIPS */
00246 #   else
00247 #     include /**/ <memory.h>
00248 #   endif /* VXWORKS */
00249 # endif /* ACE_HAS_GNU_CSTRING_H */
00250 
00251 // These prototypes are chronically lacking from many versions of
00252 // UNIX.
00253 #if !defined (ACE_HAS_ISASTREAM_PROTO)
00254 extern "C" int isastream (int);
00255 #endif /* ACE_HAS_ISASTREAM_PROTO */
00256 
00257 # if !defined (ACE_HAS_GETRUSAGE_PROTO)
00258 extern "C" int getrusage (int who, struct rusage *rusage);
00259 # endif /* ! ACE_HAS_GETRUSAGE_PROTO */
00260 
00261 # if defined (ACE_LACKS_SYSCALL)
00262 extern "C" int syscall (int, ACE_HANDLE, struct rusage *);
00263 # endif /* ACE_LACKS_SYSCALL */
00264 
00265 # if defined (ACE_LACKS_MKTEMP)
00266 extern "C" char *mktemp (char *);
00267 # endif /* ACE_LACKS_MKTEMP */
00268 
00269 // The following are #defines and #includes that must be visible for
00270 // ACE to compile it's OS wrapper class implementation correctly.  We
00271 // put them inside of here to reduce compiler overhead if we're not
00272 // inlining...
00273 
00274 # if defined (ACE_HAS_REGEX)
00275 #   include /**/ <regexpr.h>
00276 # endif /* ACE_HAS_REGEX */
00277 
00278 # if defined (ACE_HAS_SYSINFO)
00279 #   include /**/ <sys/systeminfo.h>
00280 # endif /* ACE_HAS_SYS_INFO */
00281 
00282 # if defined (ACE_HAS_SYSCALL_H)
00283 #   include /**/ <sys/syscall.h>
00284 # endif /* ACE_HAS_SYSCALL_H */
00285 
00286 # if defined (UNIXWARE)  /* See strcasecmp, below */
00287 #   include /**/ <ctype.h>
00288 # endif /* UNIXWARE */
00289 
00290 # if defined (ACE_HAS_GETIFADDRS)
00291 #   include /**/ <ifaddrs.h>
00292 # endif /* ACE_HAS_GETIFADDRS */
00293 
00294 // Adapt the weird threading and synchronization routines (which
00295 // return errno rather than -1) so that they return -1 and set errno.
00296 // This is more consistent with the rest of ACE_OS and enables use to
00297 // use the ACE_OSCALL* macros.
00298 # if defined (VXWORKS)
00299 #   define ACE_ADAPT_RETVAL(OP,RESULT) ((RESULT = (OP)) != OK ? (errno = RESULT, -1) : 0)
00300 # else
00301 #   define ACE_ADAPT_RETVAL(OP,RESULT) ((RESULT = (OP)) != 0 ? (errno = RESULT, -1) : 0)
00302 # endif /* VXWORKS */
00303 
00304 ACE_INLINE int
00305 ACE_OS::fstat (ACE_HANDLE handle, ACE_stat *stp)
00306 {
00307   ACE_OS_TRACE ("ACE_OS::fstat");
00308 #if defined (ACE_PSOS_LACKS_PHILE)
00309   ACE_UNUSED_ARG (handle);
00310   ACE_UNUSED_ARG (stp);
00311   ACE_NOTSUP_RETURN (-1);
00312 #elif defined (ACE_PSOS)
00313   ACE_OSCALL_RETURN (::fstat_f (handle, stp), int, -1);
00314 #else
00315 # if defined (ACE_HAS_X86_STAT_MACROS)
00316     // Solaris for intel uses an macro for fstat(), this is a wrapper
00317     // for _fxstat() use of the macro.
00318     // causes compile and runtime problems.
00319     ACE_OSCALL_RETURN (::_fxstat (_STAT_VER, handle, stp), int, -1);
00320 # elif defined (ACE_WIN32)
00321     ACE_OSCALL_RETURN (::_fstat (handle, stp), int, -1);
00322 # else
00323     ACE_OSCALL_RETURN (::fstat (handle, stp), int, -1);
00324 # endif /* !ACE_HAS_X86_STAT_MACROS */
00325 #endif /* ACE_PSOS_LACKS_PHILE */
00326 }
00327 
00328 ACE_INLINE int
00329 ACE_OS::lstat (const char *file, ACE_stat *stp)
00330 {
00331   ACE_OS_TRACE ("ACE_OS::lstat");
00332 # if defined (ACE_LACKS_LSTAT) || \
00333      defined (ACE_HAS_WINCE) || defined (ACE_WIN32)
00334   ACE_UNUSED_ARG (file);
00335   ACE_UNUSED_ARG (stp);
00336   ACE_NOTSUP_RETURN (-1);
00337 # else
00338 #   if defined (ACE_HAS_X86_STAT_MACROS)
00339    // Solaris for intel uses an macro for lstat(), this macro is a
00340    // wrapper for _lxstat().
00341   ACE_OSCALL_RETURN (::_lxstat (_STAT_VER, file, stp), int, -1);
00342 #   elif defined (ACE_WIN32)
00343   ACE_OSCALL_RETURN (::_lstat (file, stp), int, -1);
00344 #   else /* !ACE_HAS_X86_STAT_MACROS */
00345   ACE_OSCALL_RETURN (::lstat (file, stp), int, -1);
00346 #   endif /* !ACE_HAS_X86_STAT_MACROS */
00347 # endif /* ACE_LACKS_LSTAT */
00348 }
00349 
00350 ACE_INLINE int
00351 ACE_OS::fsync (ACE_HANDLE handle)
00352 {
00353   ACE_OS_TRACE ("ACE_OS::fsync");
00354 # if defined (ACE_LACKS_FSYNC)
00355   ACE_UNUSED_ARG (handle);
00356   ACE_NOTSUP_RETURN (-1);
00357 # else
00358   ACE_OSCALL_RETURN (::fsync (handle), int, -1);
00359 # endif /* ACE_LACKS_FSYNC */
00360 }
00361 
00362 ACE_INLINE int
00363 ACE_OS::getopt (int argc, char *const *argv, const char *optstring)
00364 {
00365   ACE_OS_TRACE ("ACE_OS::getopt");
00366 #if defined (VXWORKS) || defined (ACE_PSOS)
00367   ACE_UNUSED_ARG (argc);
00368   ACE_UNUSED_ARG (argv);
00369   ACE_UNUSED_ARG (optstring);
00370   ACE_NOTSUP_RETURN (-1);
00371 # elif defined (ACE_LACKS_GETOPT_PROTO)
00372   ACE_OSCALL_RETURN (::getopt (argc, (char**) argv, optstring), int, -1);
00373 # elif defined (ACE_LACKS_POSIX_PROTOTYPES)
00374   ACE_OSCALL_RETURN (::getopt (argc, (const char* const *) argv, optstring), int, -1);
00375 # else
00376   ACE_OSCALL_RETURN (::getopt (argc, argv, optstring), int, -1);
00377 # endif /* VXWORKS */
00378 }
00379 
00380 ACE_INLINE int
00381 ACE_OS::pipe (ACE_HANDLE fds[])
00382 {
00383   ACE_OS_TRACE ("ACE_OS::pipe");
00384 # if defined (VXWORKS) || defined (ACE_PSOS)
00385   ACE_UNUSED_ARG (fds);
00386   ACE_NOTSUP_RETURN (-1);
00387 # else
00388   ACE_OSCALL_RETURN (::pipe (fds), int, -1);
00389 # endif /* VXWORKS || ACE_PSOS */
00390 }
00391 
00392 # if defined (DIGITAL_UNIX)
00393 extern "C" {
00394   extern char *_Pctime_r (const time_t *, char *);
00395   extern struct tm *_Plocaltime_r (const time_t *, struct tm *);
00396   extern struct tm *_Pgmtime_r (const time_t *, struct tm *);
00397   extern char *_Pasctime_r (const struct tm *, char *);
00398   extern int _Prand_r (unsigned int *seedptr);
00399   extern int _Pgetpwnam_r (const char *, struct passwd *,
00400                            char *, size_t, struct passwd **);
00401 }
00402 # endif /* DIGITAL_UNIX */
00403 
00404 // VAC++ doesn't correctly grok the ::getpwnam_r - the function is redefined
00405 // in pwd.h, and that redefinition is used here
00406 # if defined (_AIX) && defined (__IBMCPP__) && (__IBMCPP__ >= 400)
00407 extern "C" {
00408   extern int _posix_getpwnam_r(const char *, struct passwd *, char *,
00409                                int, struct passwd **);
00410            }
00411 #endif /* AIX and VAC++ 4 */
00412 
00413 ACE_INLINE int
00414 ACE_OS::rand_r (ACE_RANDR_TYPE &seed)
00415 {
00416   ACE_OS_TRACE ("ACE_OS::rand_r");
00417 # if defined (ACE_HAS_REENTRANT_FUNCTIONS) && \
00418     !defined (ACE_LACKS_RAND_REENTRANT_FUNCTIONS)
00419 #   if defined (DIGITAL_UNIX)
00420   ACE_OSCALL_RETURN (::_Prand_r (&seed), int, -1);
00421 #   elif defined (HPUX_10)
00422   // rand() is thread-safe on HP-UX 10.  rand_r's signature is not consistent
00423   // with latest POSIX and will change in a future HP-UX release so that it
00424   // is consistent.  At that point, this #elif section can be changed or
00425   // removed, and just call rand_r.
00426   ACE_UNUSED_ARG (seed);
00427   ACE_OSCALL_RETURN (::rand(), int, -1);
00428 #   elif defined (ACE_HAS_BROKEN_RANDR)
00429   ACE_OSCALL_RETURN (::rand_r (seed), int, -1);
00430 #   else
00431   ACE_OSCALL_RETURN (::rand_r (&seed), int, -1);
00432 #   endif /* DIGITAL_UNIX */
00433 # else
00434   ACE_UNUSED_ARG (seed);
00435   ACE_OSCALL_RETURN (::rand (), int, -1);
00436 # endif /* ACE_HAS_REENTRANT_FUNCTIONS */
00437 }
00438 
00439 ACE_INLINE pid_t
00440 ACE_OS::setsid (void)
00441 {
00442   ACE_OS_TRACE ("ACE_OS::setsid");
00443 # if defined (VXWORKS) || defined (CHORUS) || defined (ACE_PSOS)
00444   ACE_NOTSUP_RETURN (-1);
00445 # else
00446   ACE_OSCALL_RETURN (::setsid (), int, -1);
00447 # endif /* VXWORKS || CHORUS || ACE_PSOS */
00448 }
00449 
00450 ACE_INLINE mode_t
00451 ACE_OS::umask (mode_t cmask)
00452 {
00453   ACE_OS_TRACE ("ACE_OS::umask");
00454 # if defined (VXWORKS) || defined (ACE_PSOS)
00455   ACE_UNUSED_ARG (cmask);
00456   ACE_NOTSUP_RETURN (-1);
00457 # else
00458   return ::umask (cmask); // This call shouldn't fail...
00459 # endif /* VXWORKS || ACE_PSOS */
00460 }
00461 
00462 #else /* ACE_WIN32 */
00463 
00464 // Adapt the Win32 System Calls (which return BOOLEAN values of TRUE
00465 // and FALSE) into int values expected by the ACE_OSCALL macros.
00466 # define ACE_ADAPT_RETVAL(OP,RESULT) ((RESULT = (OP)) == FALSE ? -1 : 0)
00467 
00468 // Perform a mapping of Win32 error numbers into POSIX errnos.
00469 # define ACE_FAIL_RETURN(RESULT) do { \
00470   switch (ACE_OS::set_errno_to_last_error ()) { \
00471   case ERROR_NOT_ENOUGH_MEMORY: errno = ENOMEM; break; \
00472   case ERROR_FILE_EXISTS:       errno = EEXIST; break; \
00473   case ERROR_SHARING_VIOLATION: errno = EACCES; break; \
00474   case ERROR_PATH_NOT_FOUND:    errno = ENOENT; break; \
00475   } \
00476   return RESULT; } while (0)
00477 
00478 ACE_INLINE LPSECURITY_ATTRIBUTES
00479 ACE_OS::default_win32_security_attributes (LPSECURITY_ATTRIBUTES sa)
00480 {
00481 #if defined (ACE_DEFINES_DEFAULT_WIN32_SECURITY_ATTRIBUTES)
00482   if (sa == 0)
00483     {
00484       // @@ This is a good place to use pthread_once.
00485       static SECURITY_ATTRIBUTES default_sa;
00486       static SECURITY_DESCRIPTOR sd;
00487       InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
00488       SetSecurityDescriptorDacl(&sd, TRUE, 0, FALSE);
00489       default_sa.nLength = sizeof(SECURITY_ATTRIBUTES);
00490       default_sa.lpSecurityDescriptor = &sd;
00491       default_sa.bInheritHandle       = TRUE;
00492       sa = &default_sa;
00493     }
00494   return sa;
00495 #else /* !ACE_DEFINES_DEFAULT_WIN32_SECURITY_ATTRIBUTES */
00496   return sa;
00497 #endif /* ACE_DEFINES_DEFAULT_WIN32_SECURITY_ATTRIBUTES */
00498 }
00499 
00500 ACE_INLINE int
00501 ACE_OS::getopt (int argc, char *const *argv, const char *optstring)
00502 {
00503   ACE_UNUSED_ARG (argc);
00504   ACE_UNUSED_ARG (argv);
00505   ACE_UNUSED_ARG (optstring);
00506 
00507   ACE_OS_TRACE ("ACE_OS::getopt");
00508   ACE_NOTSUP_RETURN (-1);
00509 }
00510 
00511 ACE_INLINE int
00512 ACE_OS::pipe (ACE_HANDLE fds[])
00513 {
00514 # if !defined (ACE_HAS_WINCE) && !defined (__IBMCPP__)
00515   ACE_OS_TRACE ("ACE_OS::pipe");
00516   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL
00517                         (::CreatePipe (&fds[0], &fds[1], 0, 0),
00518                          ace_result_), int, -1);
00519 # else
00520   ACE_NOTSUP_RETURN (-1);
00521 # endif /* ACE_HAS_WINCE && !__IBMCPP__ */
00522 }
00523 
00524 ACE_INLINE int
00525 ACE_OS::rand_r (ACE_RANDR_TYPE& seed)
00526 {
00527   ACE_UNUSED_ARG (seed);
00528 
00529   ACE_OS_TRACE ("ACE_OS::rand_r");
00530   ACE_NOTSUP_RETURN (-1);
00531 }
00532 
00533 ACE_INLINE pid_t
00534 ACE_OS::setsid (void)
00535 {
00536   ACE_OS_TRACE ("ACE_OS::setsid");
00537   ACE_NOTSUP_RETURN (-1);
00538 }
00539 
00540 ACE_INLINE mode_t
00541 ACE_OS::umask (mode_t cmask)
00542 {
00543 #if !defined (ACE_HAS_WINCE)
00544   ACE_OS_TRACE ("ACE_OS::umask");
00545   ACE_OSCALL_RETURN (::_umask (cmask), mode_t, -1);
00546 # else
00547   ACE_NOTSUP_RETURN (-1);
00548 # endif /* ACE_HAS_WINCE */
00549 }
00550 
00551 ACE_INLINE int
00552 ACE_OS::fstat (ACE_HANDLE handle, ACE_stat *stp)
00553 {
00554   ACE_OS_TRACE ("ACE_OS::fstat");
00555 # if 1
00556   BY_HANDLE_FILE_INFORMATION fdata;
00557 
00558   if (::GetFileInformationByHandle (handle, &fdata) == FALSE)
00559     {
00560       ACE_OS::set_errno_to_last_error ();
00561       return -1;
00562     }
00563   else if (fdata.nFileSizeHigh != 0)
00564     {
00565       errno = EINVAL;
00566       return -1;
00567     }
00568   else
00569     {
00570       stp->st_size = fdata.nFileSizeLow;
00571       stp->st_atime = ACE_Time_Value (fdata.ftLastAccessTime).sec ();
00572       stp->st_mtime = ACE_Time_Value (fdata.ftLastWriteTime).sec ();
00573       stp->st_ctime = ACE_Time_Value (fdata.ftCreationTime).sec ();
00574       stp->st_nlink = ACE_static_cast (short, fdata.nNumberOfLinks);
00575       stp->st_dev = stp->st_rdev = 0; // No equivalent conversion.
00576       stp->st_mode = S_IXOTH | S_IROTH |
00577         (fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY ? 0 : S_IWOTH) |
00578         (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? S_IFDIR : S_IFREG);
00579     }
00580   return 0;
00581 # else /* 1 */
00582   // This implementation close the handle.
00583   int retval = -1;
00584   int fd = ::_open_osfhandle ((long) handle, 0);
00585   if (fd != -1)
00586       retval = ::_fstat (fd, stp);
00587 
00588   ::_close (fd);
00589   // Remember to close the file handle.
00590   return retval;
00591 # endif /* 1 */
00592 }
00593 
00594 #endif /* WIN32 */
00595 
00596 ACE_INLINE int
00597 ACE_OS::clock_gettime (clockid_t clockid, struct timespec *ts)
00598 {
00599   ACE_OS_TRACE ("ACE_OS::clock_gettime");
00600 #if defined (ACE_HAS_CLOCK_GETTIME)
00601   ACE_OSCALL_RETURN (::clock_gettime (clockid, ts), int, -1);
00602 # elif defined (ACE_PSOS) && ! defined (ACE_PSOS_DIAB_MIPS)
00603   ACE_UNUSED_ARG (clockid);
00604   ACE_PSOS_Time_t pt;
00605   int result = ACE_PSOS_Time_t::get_system_time (pt);
00606   *ts = ACE_static_cast (struct timespec, pt);
00607   return result;
00608 #else
00609   ACE_UNUSED_ARG (clockid);
00610   ACE_UNUSED_ARG (ts);
00611   ACE_NOTSUP_RETURN (-1);
00612 #endif /* ACE_HAS_CLOCK_GETTIME */
00613 }
00614 
00615 ACE_INLINE ACE_Time_Value
00616 ACE_OS::gettimeofday (void)
00617 {
00618   // ACE_OS_TRACE ("ACE_OS::gettimeofday");
00619 
00620 #if !defined (ACE_HAS_WINCE)&& !defined (ACE_WIN32)
00621   timeval tv;
00622   int result = 0;
00623 #endif // !defined (ACE_HAS_WINCE)&& !defined (ACE_WIN32)
00624 
00625 #if (0)
00626   struct timespec ts;
00627 
00628   ACE_OSCALL (ACE_OS::clock_gettime (CLOCK_REALTIME, &ts), int, -1, result);
00629   tv.tv_sec = ts.tv_sec;
00630   tv.tv_usec = ts.tv_nsec / 1000L;  // timespec has nsec, but timeval has usec
00631 
00632 #elif defined (ACE_HAS_WINCE)
00633   SYSTEMTIME tsys;
00634   FILETIME   tfile;
00635   ::GetSystemTime (&tsys);
00636   ::SystemTimeToFileTime (&tsys, &tfile);
00637   return ACE_Time_Value (tfile);
00638 #elif defined (ACE_WIN32)
00639   FILETIME   tfile;
00640   ::GetSystemTimeAsFileTime (&tfile);
00641   return ACE_Time_Value (tfile);
00642 #if 0
00643   // From Todd Montgomery...
00644   struct _timeb tb;
00645   ::_ftime (&tb);
00646   tv.tv_sec = tb.time;
00647   tv.tv_usec = 1000 * tb.millitm;
00648 #endif /* 0 */
00649 #elif defined (ACE_HAS_AIX_HI_RES_TIMER)
00650   timebasestruct_t tb;
00651 
00652   ::read_real_time (&tb, TIMEBASE_SZ);
00653   ::time_base_to_time (&tb, TIMEBASE_SZ);
00654 
00655   tv.tv_sec = tb.tb_high;
00656   tv.tv_usec = tb.tb_low / 1000L;
00657 #else
00658 # if defined (ACE_HAS_TIMEZONE_GETTIMEOFDAY) || \
00659   (defined (ACE_HAS_SVR4_GETTIMEOFDAY) && !defined (m88k) && !defined (SCO))
00660   ACE_OSCALL (::gettimeofday (&tv, 0), int, -1, result);
00661 # elif defined (VXWORKS) || defined (CHORUS) || defined (ACE_PSOS)
00662   // Assumes that struct timespec is same size as struct timeval,
00663   // which assumes that time_t is a long: it currently (VxWorks
00664   // 5.2/5.3) is.
00665   struct timespec ts;
00666 
00667   ACE_OSCALL (ACE_OS::clock_gettime (CLOCK_REALTIME, &ts), int, -1, result);
00668   tv.tv_sec = ts.tv_sec;
00669   tv.tv_usec = ts.tv_nsec / 1000L;  // timespec has nsec, but timeval has usec
00670 # else
00671   ACE_OSCALL (::gettimeofday (&tv), int, -1, result);
00672 # endif /* ACE_HAS_SVR4_GETTIMEOFDAY */
00673 #endif /* 0 */
00674 #if !defined (ACE_HAS_WINCE)&& !defined (ACE_WIN32)
00675   if (result == -1)
00676     return -1;
00677   else
00678     return ACE_Time_Value (tv);
00679 #endif // !defined (ACE_HAS_WINCE)&& !defined (ACE_WIN32)
00680 }
00681 
00682 ACE_INLINE int
00683 ACE_OS::stat (const ACE_TCHAR *file, ACE_stat *stp)
00684 {
00685   ACE_OS_TRACE ("ACE_OS::stat");
00686 #if defined (VXWORKS)
00687   ACE_OSCALL_RETURN (::stat ((char *) file, stp), int, -1);
00688 #elif defined (ACE_PSOS_LACKS_PHILE)
00689   ACE_UNUSED_ARG (file);
00690   ACE_UNUSED_ARG (stp);
00691   ACE_NOTSUP_RETURN (-1);
00692 #elif defined (ACE_PSOS)
00693   ACE_OSCALL_RETURN (::stat_f ((char *) file, stp), int, -1);
00694 #elif defined (ACE_HAS_WINCE)
00695   ACE_TEXT_WIN32_FIND_DATA fdata;
00696 
00697   HANDLE fhandle;
00698 
00699   fhandle = ::FindFirstFile (file, &fdata);
00700   if (fhandle == INVALID_HANDLE_VALUE)
00701     {
00702       ACE_OS::set_errno_to_last_error ();
00703       return -1;
00704     }
00705   else if (fdata.nFileSizeHigh != 0)
00706     {
00707       errno = EINVAL;
00708       return -1;
00709     }
00710   else
00711     {
00712       stp->st_size = fdata.nFileSizeLow;
00713       stp->st_atime = ACE_Time_Value (fdata.ftLastAccessTime);
00714       stp->st_mtime = ACE_Time_Value (fdata.ftLastWriteTime);
00715     }
00716   return 0;
00717 #elif defined (ACE_HAS_X86_STAT_MACROS)
00718    // Solaris for intel uses an macro for stat(), this macro is a
00719    // wrapper for _xstat().
00720   ACE_OSCALL_RETURN (::_xstat (_STAT_VER, file, stp), int, -1);
00721 #elif defined (__BORLANDC__)  && (__BORLANDC__ <= 0x540) && defined (ACE_USES_WCHAR)
00722   ACE_OSCALL_RETURN (::_wstat (file, stp), int, -1);
00723 #elif defined (ACE_WIN32)
00724 #   if defined (ACE_USES_WCHAR)
00725   ACE_OSCALL_RETURN (::_wstat (file, (struct _stat *) stp), int, -1);
00726 #   else
00727   ACE_OSCALL_RETURN (::_stat (file, (struct _stat *) stp), int, -1);
00728 #   endif /* ACE_USES_WCHAR */
00729 #else /* VXWORKS */
00730   ACE_OSCALL_RETURN (::stat (file, stp), int, -1);
00731 #endif /* VXWORKS */
00732 }
00733 
00734 ACE_INLINE time_t
00735 ACE_OS::time (time_t *tloc)
00736 {
00737 #if !defined (ACE_HAS_WINCE)
00738   ACE_OS_TRACE ("ACE_OS::time");
00739 #  if defined (ACE_PSOS) && ! defined (ACE_PSOS_HAS_TIME)
00740         unsigned long d_date, d_time, d_tick;
00741         tm_get(&d_date, &d_time, &d_tick); // get current time
00742         if (tloc)
00743                 *tloc = d_time; // set time as time_t
00744         return d_time;
00745 #  else
00746   ACE_OSCALL_RETURN (::time (tloc), time_t, (time_t) -1);
00747 #  endif /* ACE_PSOS && ! ACE_PSOS_HAS_TIME */
00748 #else
00749   time_t retv = ACE_OS::gettimeofday ().sec ();
00750   if (tloc)
00751     *tloc = retv;
00752   return retv;
00753 #endif /* ACE_HAS_WINCE */
00754 }
00755 
00756 ACE_INLINE void
00757 ACE_OS::srand (u_int seed)
00758 {
00759   ACE_OS_TRACE ("ACE_OS::srand");
00760   ::srand (seed);
00761 }
00762 
00763 ACE_INLINE int
00764 ACE_OS::rand (void)
00765 {
00766   ACE_OS_TRACE ("ACE_OS::rand");
00767   ACE_OSCALL_RETURN (::rand (), int, -1);
00768 }
00769 
00770 ACE_INLINE int
00771 ACE_OS::unlink (const ACE_TCHAR *path)
00772 {
00773   ACE_OS_TRACE ("ACE_OS::unlink");
00774 # if defined (VXWORKS)
00775     ACE_OSCALL_RETURN (::unlink (ACE_const_cast (char *, path)), int, -1);
00776 # elif defined (ACE_PSOS) && ! defined (ACE_PSOS_LACKS_PHILE)
00777     ACE_OSCALL_RETURN (::remove_f ((char *) path), int , -1);
00778 # elif defined (ACE_PSOS) && defined (ACE_PSOS_HAS_C_LIBRARY)
00779     ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::remove ((char *) path),
00780                                                    ace_result_),
00781                        int, -1);
00782 # elif defined (ACE_HAS_WINCE)
00783   // @@ The problem is, DeleteFile is not actually equals to unlink. ;(
00784   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::DeleteFile (path), ace_result_),
00785                         int, -1);
00786 # elif defined (ACE_LACKS_UNLINK)
00787     ACE_UNUSED_ARG (path);
00788     ACE_NOTSUP_RETURN (-1);
00789 # elif defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
00790   ACE_OSCALL_RETURN (::_wunlink (path), int, -1);
00791 # else
00792   ACE_OSCALL_RETURN (::unlink (path), int, -1);
00793 # endif /* VXWORKS */
00794 }
00795 
00796 ACE_INLINE int
00797 ACE_OS::rename (const ACE_TCHAR *old_name,
00798                 const ACE_TCHAR *new_name,
00799                 int flags)
00800 {
00801 # if defined (ACE_LACKS_RENAME)
00802   ACE_UNUSED_ARG (old_name);
00803   ACE_UNUSED_ARG (new_name);
00804   ACE_UNUSED_ARG (flags);
00805   ACE_NOTSUP_RETURN (-1);
00806 # elif defined (ACE_HAS_WINCE)
00807   ACE_UNUSED_ARG (flags);
00808   if (MoveFile (old_name, new_name) != 0)
00809     ACE_FAIL_RETURN (-1);
00810   return 0;
00811 # elif defined (ACE_WIN32) && defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 == 1)
00812   // NT4 (and up) provides a way to rename/move a file with similar semantics
00813   // to what's usually done on UNIX - if there's an existing file with
00814   // <new_name> it is removed before the file is renamed/moved. The
00815   // MOVEFILE_COPY_ALLOWED is specified to allow such a rename across drives.
00816   if (flags == -1)
00817     flags = MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING;
00818   if (ACE_TEXT_MoveFileEx(old_name, new_name, flags) == 0)
00819     ACE_FAIL_RETURN (-1);
00820   return 0;
00821 # elif defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
00822   ACE_UNUSED_ARG (flags);
00823   ACE_OSCALL_RETURN (::_wrename (old_name, new_name), int, -1);
00824 # else /* ACE_LACKS_RENAME */
00825   ACE_UNUSED_ARG (flags);
00826   ACE_OSCALL_RETURN (::rename (old_name, new_name), int, -1);
00827 # endif /* ACE_LACKS_RENAME */
00828 }
00829 
00830 ACE_INLINE ACE_TCHAR *
00831 ACE_OS::tempnam (const ACE_TCHAR *dir, const ACE_TCHAR *pfx)
00832 {
00833   ACE_OS_TRACE ("ACE_OS::tempnam");
00834 #if defined (VXWORKS) || defined (ACE_HAS_WINCE) || defined (ACE_LACKS_TEMPNAM)
00835   ACE_UNUSED_ARG (dir);
00836   ACE_UNUSED_ARG (pfx);
00837   ACE_NOTSUP_RETURN (0);
00838 #elif defined (ACE_PSOS)
00839   // pSOS only considers the directory prefix
00840   ACE_UNUSED_ARG (pfx);
00841   ACE_OSCALL_RETURN (::tmpnam ((char *) dir), char *, 0);
00842 #elif (defined (ACE_WIN32) && ((defined (__BORLANDC__) && !defined(ACE_USES_WCHAR)) || defined (__IBMCPP__)))
00843   ACE_OSCALL_RETURN (::_tempnam ((char *) dir, (char *) pfx), char *, 0);
00844 #elif defined(ACE_WIN32) && defined (__BORLANDC__) && defined (ACE_USES_WCHAR)
00845   ACE_OSCALL_RETURN (::_wtempnam ((wchar_t*) dir, (wchar_t*) pfx), wchar_t *, 0);
00846 #elif defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
00847   ACE_OSCALL_RETURN (::_wtempnam (dir, pfx), wchar_t *, 0);
00848 #else /* VXWORKS */
00849   ACE_OSCALL_RETURN (::tempnam (dir, pfx), char *, 0);
00850 #endif /* VXWORKS */
00851 }
00852 
00853 ACE_INLINE ACE_HANDLE
00854 ACE_OS::shm_open (const ACE_TCHAR *filename,
00855                   int mode,
00856                   int perms,
00857                   LPSECURITY_ATTRIBUTES sa)
00858 {
00859   ACE_OS_TRACE ("ACE_OS::shm_open");
00860 # if defined (ACE_HAS_SHM_OPEN)
00861   ACE_UNUSED_ARG (sa);
00862   ACE_OSCALL_RETURN (::shm_open (filename, mode, perms), ACE_HANDLE, -1);
00863 # else  /* ! ACE_HAS_SHM_OPEN */
00864   // Just use ::open.
00865   return ACE_OS::open (filename, mode, perms, sa);
00866 # endif /* ACE_HAS_SHM_OPEN */
00867 }
00868 
00869 ACE_INLINE int
00870 ACE_OS::shm_unlink (const ACE_TCHAR *path)
00871 {
00872   ACE_OS_TRACE ("ACE_OS::shm_unlink");
00873 # if defined (ACE_HAS_SHM_OPEN)
00874   ACE_OSCALL_RETURN (::shm_unlink (path), int, -1);
00875 # else  /* ! ACE_HAS_SHM_OPEN */
00876   // Just use ::unlink.
00877   return ACE_OS::unlink (path);
00878 # endif /* ACE_HAS_SHM_OPEN */
00879 }
00880 
00881 #if !defined (ACE_LACKS_CUSERID)
00882 ACE_INLINE char *
00883 ACE_OS::cuserid (char *user, size_t maxlen)
00884 {
00885   ACE_OS_TRACE ("ACE_OS::cuserid");
00886 #if defined (VXWORKS)
00887   ACE_UNUSED_ARG (maxlen);
00888   if (user == 0)
00889     {
00890       // Require that the user field be non-null, i.e., don't
00891       // allocate or use static storage.
00892       ACE_NOTSUP_RETURN (0);
00893     }
00894   else
00895     {
00896       ::remCurIdGet (user, 0);
00897       return user;
00898     }
00899 #elif defined (CHORUS) || defined (ACE_PSOS) || defined (__QNXNTO__)
00900   ACE_UNUSED_ARG (user);
00901   ACE_UNUSED_ARG (maxlen);
00902   ACE_NOTSUP_RETURN (0);
00903 #elif defined (ACE_WIN32)
00904   BOOL result = GetUserNameA (user, (u_long *) &maxlen);
00905   if (result == FALSE)
00906     ACE_FAIL_RETURN (0);
00907   else
00908     return user;
00909 #elif defined (ACE_HAS_ALT_CUSERID)
00910 #  if defined (ACE_LACKS_PWD_FUNCTIONS)
00911 #    error Cannot use alternate cuserid() without POSIX password functions!
00912 #  endif  /* ACE_LACKS_PWD_FUNCTIONS */
00913 
00914   // POSIX.1 dropped the cuserid() function.
00915   // GNU GLIBC and other platforms correctly deprecate the cuserid()
00916   // function.
00917 
00918   if (maxlen == 0)
00919     {
00920       // It doesn't make sense to have a zero length user ID.
00921       errno = EINVAL;
00922       return 0;
00923     }
00924 
00925   struct passwd *pw = 0;
00926 
00927   // Make sure the file pointer is at the beginning of the password file
00928   ::setpwent ();
00929   // Should use ACE_OS::setpwent() but I didn't want to move this
00930   // method after it.
00931 
00932   // Use the effective user ID to determine the user name.
00933   pw = ::getpwuid (::geteuid ());
00934 
00935   // Make sure the password file is closed.
00936   ::endpwent ();
00937 
00938   size_t max_length = 0;
00939   char *userid = 0;
00940 
00941   if (user == 0)
00942     {
00943       // Not reentrant/thread-safe, but nothing else can be done if a
00944       // zero pointer was passed in as the destination.
00945 
00946 #if defined (_POSIX_SOURCE)
00947       const size_t ACE_L_cuserid = L_cuserid;
00948 #else
00949       const size_t ACE_L_cuserid = 9;  // 8 character user ID + NULL
00950 #endif  /* _POSIX_SOURCE */
00951 
00952       static ACE_TCHAR tmp[ACE_L_cuserid] = { '\0' };
00953       max_length = ACE_L_cuserid - 1; // Do not include NULL in length
00954 
00955       userid = tmp;
00956     }
00957   else
00958     {
00959       max_length = maxlen;
00960       userid = user;
00961     }
00962 
00963   // Extract the user name from the passwd structure.
00964   if (ACE_OS_String::strlen (pw->pw_name) <= max_length)
00965     {
00966       return ACE_OS_String::strcpy (userid, pw->pw_name);
00967     }
00968   else
00969     {
00970       errno = ENOSPC;  // Buffer is not large enough.
00971       return 0;
00972     }
00973 #else
00974   // Hackish because of missing buffer size!
00975   ACE_UNUSED_ARG (maxlen);
00976   ACE_OSCALL_RETURN (::ace_cuserid(user), char*, 0);
00977 #endif /* VXWORKS */
00978 }
00979 
00980 #if defined (ACE_HAS_WCHAR)
00981 ACE_INLINE wchar_t *
00982 ACE_OS::cuserid (wchar_t *user, size_t maxlen)
00983 {
00984 # if defined (ACE_WIN32)
00985   BOOL result = GetUserNameW (user, (u_long *) &maxlen);
00986   if (result == FALSE)
00987     ACE_FAIL_RETURN (0);
00988   else
00989     return user;
00990 # else /* ACE_WIN32 */
00991   char *char_user;
00992   wchar_t *result = 0;
00993 
00994   ACE_NEW_RETURN (char_user, char[maxlen + 1], 0);
00995 
00996   if (ACE_OS::cuserid (char_user, maxlen))
00997     {
00998       ACE_OS::strcpy (user, ACE_Ascii_To_Wide (char_user).wchar_rep ());
00999       result = user;
01000     }
01001 
01002   delete [] char_user;
01003 
01004   return result;
01005 # endif /* ACE_WIN32 */
01006 }
01007 #endif /* ACE_HAS_WCHAR  */
01008 #endif /* ACE_LACKS_CUSERID */
01009 
01010 ACE_INLINE int
01011 ACE_OS::atexit (ACE_EXIT_HOOK func)
01012 {
01013   return ACE_OS_Object_Manager::instance ()->at_exit (func);
01014 }
01015 
01016 // Doesn't need a macro since it *never* returns!
01017 
01018 ACE_INLINE void
01019 ACE_OS::_exit (int status)
01020 {
01021   ACE_OS_TRACE ("ACE_OS::_exit");
01022 #if defined (VXWORKS)
01023   ::exit (status);
01024 #elif defined (ACE_PSOSIM)
01025   ::u_exit (status);
01026 #elif defined (ACE_PSOS)
01027 # if defined (ACE_PSOS_LACKS_PREPC)  /* pSoS TM does not support exit. */
01028   ACE_UNUSED_ARG (status);
01029   return;
01030 # else
01031   ::exit (status);
01032 # endif /* defined (ACE_PSOS_LACKS_PREPC) */
01033 #elif !defined (ACE_HAS_WINCE)
01034   ::_exit (status);
01035 #else
01036   ::TerminateProcess (::GetCurrentProcess (),
01037                       status);
01038 #endif /* VXWORKS */
01039 }
01040 
01041 ACE_INLINE void
01042 ACE_OS::abort (void)
01043 {
01044 #if !defined (ACE_HAS_WINCE)
01045   ::abort ();
01046 #else
01047   // @@ CE doesn't support abort?
01048   exit (1);
01049 #endif /* !ACE_HAS_WINCE */
01050 }
01051 
01052 #if !defined (ACE_HAS_WINCE)
01053 ACE_INLINE int
01054 ACE_OS::vsprintf (char *buffer, const char *format, va_list argptr)
01055 {
01056   return ACE_SPRINTF_ADAPTER (::vsprintf (buffer, format, argptr));
01057 }
01058 #endif /* ACE_HAS_WINCE */
01059 
01060 #if defined (ACE_HAS_WCHAR)
01061 ACE_INLINE int
01062 ACE_OS::vsprintf (wchar_t *buffer, const wchar_t *format, va_list argptr)
01063 {
01064 # if defined (ACE_HAS_VSWPRINTF)
01065   return ::vswprintf (buffer, format, argptr);
01066 
01067 # else
01068   ACE_UNUSED_ARG (buffer);
01069   ACE_UNUSED_ARG (format);
01070   ACE_UNUSED_ARG (argptr);
01071   ACE_NOTSUP_RETURN (-1);
01072 
01073 # endif /* ACE_HAS_VSWPRINTF */
01074 }
01075 #endif /* ACE_HAS_WCHAR */
01076 
01077 
01078 ACE_INLINE long
01079 ACE_OS::sysconf (int name)
01080 {
01081   ACE_OS_TRACE ("ACE_OS::sysconf");
01082 #if defined (ACE_WIN32) || defined (VXWORKS) || defined (ACE_PSOS)
01083   ACE_UNUSED_ARG (name);
01084   ACE_NOTSUP_RETURN (-1);
01085 #else
01086   ACE_OSCALL_RETURN (::sysconf (name), long, -1);
01087 #endif /* ACE_WIN32 || VXWORKS || ACE_PSOS */
01088 }
01089 
01090 ACE_INLINE int
01091 ACE_OS::mutex_init (ACE_mutex_t *m,
01092                     int type,
01093                     const char *name,
01094                     ACE_mutexattr_t *attributes,
01095                     LPSECURITY_ATTRIBUTES sa)
01096 {
01097   // ACE_OS_TRACE ("ACE_OS::mutex_init");
01098 #if defined (ACE_HAS_THREADS)
01099 # if defined (ACE_HAS_PTHREADS)
01100   ACE_UNUSED_ARG (name);
01101   ACE_UNUSED_ARG (attributes);
01102   ACE_UNUSED_ARG (sa);
01103 
01104   pthread_mutexattr_t l_attributes;
01105   if (attributes == 0)
01106     attributes = &l_attributes;
01107   int result = 0;
01108   int attr_init = 0;  // have we initialized the local attributes.
01109 
01110   // Only do these initializations if the <attributes> parameter
01111   // wasn't originally set.
01112   if (attributes == &l_attributes)
01113     {
01114 #   if defined (ACE_HAS_PTHREADS_DRAFT4)
01115       if (::pthread_mutexattr_create (attributes) == 0)
01116 #   elif defined (ACE_HAS_PTHREADS_DRAFT7) || defined (ACE_HAS_PTHREADS_STD)
01117       if (ACE_ADAPT_RETVAL (::pthread_mutexattr_init (attributes), result) == 0)
01118 #   else /* draft 6 */
01119       if (::pthread_mutexattr_init (attributes) == 0)
01120 #   endif /* ACE_HAS_PTHREADS_DRAFT4 */
01121         {
01122           result = 0;
01123           attr_init = 1; // we have initialized these attributes
01124         }
01125       else
01126         result = -1;        // ACE_ADAPT_RETVAL used it for intermediate status
01127     }
01128 
01129   if (result == 0)
01130     {
01131 #   if defined (ACE_HAS_PTHREADS_DRAFT4)
01132       if (
01133 #     if defined (ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP)
01134           ::pthread_mutexattr_setkind_np (attributes, type) == 0 &&
01135 #     endif /* ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP */
01136           ::pthread_mutex_init (m, *attributes) == 0)
01137 #   elif defined (ACE_HAS_PTHREADS_DRAFT7) || defined (ACE_HAS_PTHREADS_STD)
01138       if (
01139 #     if defined (_POSIX_THREAD_PROCESS_SHARED) && !defined (ACE_LACKS_MUTEXATTR_PSHARED)
01140            ACE_ADAPT_RETVAL (::pthread_mutexattr_setpshared (attributes, type),
01141                              result) == 0 &&
01142 #     endif /* _POSIX_THREAD_PROCESS_SHARED && ! ACE_LACKS_MUTEXATTR_PSHARED */
01143            ACE_ADAPT_RETVAL (::pthread_mutex_init (m, attributes), result) == 0)
01144 #   else
01145         if (
01146 #     if !defined (ACE_LACKS_MUTEXATTR_PSHARED)
01147             ::pthread_mutexattr_setpshared (attributes, type) == 0 &&
01148 #     endif /* ACE_LACKS_MUTEXATTR_PSHARED */
01149 #     if defined (ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP)
01150             ::pthread_mutexattr_setkind_np (attributes, type) == 0 &&
01151 #     endif /* ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP */
01152             ::pthread_mutex_init (m, attributes) == 0)
01153 #   endif /* ACE_HAS_PTHREADS_DRAFT4 */
01154         result = 0;
01155       else
01156         result = -1;        // ACE_ADAPT_RETVAL used it for intermediate status
01157     }
01158 
01159 #   if (!defined (ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP) && !defined (_POSIX_THREAD_PROCESS_SHARED)  ||  defined (ACE_LACKS_MUTEXATTR_PSHARED)) \
01160        || ((defined (ACE_HAS_PTHREADS_DRAFT7) || defined (ACE_HAS_PTHREADS_STD)) && !defined (_POSIX_THREAD_PROCESS_SHARED))
01161   ACE_UNUSED_ARG (type);
01162 #   endif /* ! ACE_HAS_PTHREAD_MUTEXATTR_SETKIND_NP */
01163 
01164   // Only do the deletions if the <attributes> parameter wasn't
01165   // originally set.
01166   if (attributes == &l_attributes && attr_init)
01167 #   if defined (ACE_HAS_PTHREADS_DRAFT4)
01168     ::pthread_mutexattr_delete (&l_attributes);
01169 #   else
01170     ::pthread_mutexattr_destroy (&l_attributes);
01171 #   endif /* ACE_HAS_PTHREADS_DRAFT4 */
01172 
01173   return result;
01174 # elif defined (ACE_HAS_STHREADS)
01175   ACE_UNUSED_ARG (name);
01176   ACE_UNUSED_ARG (sa);
01177   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::mutex_init (m, type, attributes),
01178                                        ace_result_),
01179                      int, -1);
01180 # elif defined (ACE_HAS_WTHREADS)
01181   m->type_ = type;
01182 
01183   switch (type)
01184     {
01185     case USYNC_PROCESS:
01186 #   if defined (ACE_HAS_WINCE)
01187       // @@todo (brunsch) This idea should be moved into ACE_OS_Win32.
01188       m->proc_mutex_ = ::CreateMutexW (ACE_OS::default_win32_security_attributes (sa),
01189                                        FALSE,
01190                                        ACE_Ascii_To_Wide (name).wchar_rep ());
01191 #   else /* ACE_HAS_WINCE */
01192       m->proc_mutex_ = ::CreateMutexA (ACE_OS::default_win32_security_attributes (sa),
01193                                        FALSE,
01194                                        name);
01195 #   endif /* ACE_HAS_WINCE */
01196       if (m->proc_mutex_ == 0)
01197         ACE_FAIL_RETURN (-1);
01198       else
01199         {
01200           // Make sure to set errno to ERROR_ALREADY_EXISTS if necessary.
01201           ACE_OS::set_errno_to_last_error ();
01202           return 0;
01203         }
01204     case USYNC_THREAD:
01205       return ACE_OS::thread_mutex_init (&m->thr_mutex_,
01206                                         type,
01207                                         name,
01208                                         attributes);
01209     default:
01210       errno = EINVAL;
01211       return -1;
01212     }
01213   /* NOTREACHED */
01214 
01215 # elif defined (ACE_PSOS)
01216   ACE_UNUSED_ARG (type);
01217   ACE_UNUSED_ARG (attributes);
01218   ACE_UNUSED_ARG (sa);
01219 #   if defined (ACE_PSOS_HAS_MUTEX)
01220 
01221     u_long flags = MU_LOCAL;
01222     u_long ceiling = 0;
01223 
01224 #     if defined (ACE_HAS_RECURSIVE_MUTEXES)
01225     flags |= MU_RECURSIVE;
01226 #     else /* ! ACE_HAS_RECURSIVE_MUTEXES */
01227     flags |= MU_NONRECURSIVE;
01228 #     endif /* ACE_HAS_RECURSIVE_MUTEXES */
01229 
01230 #     if defined (ACE_PSOS_HAS_PRIO_MUTEX)
01231 
01232     flags |= MU_PRIOR;
01233 
01234 #       if defined (ACE_PSOS_HAS_PRIO_INHERIT_MUTEX)
01235     flags |= MU_PRIO_INHERIT;
01236 #       elif defined (ACE_PSOS_HAS_PRIO_PROTECT_MUTEX)
01237     ceiling =  PSOS_TASK_MAX_PRIORITY;
01238     flags |= MU_PRIO_PROTECT;
01239 #       else
01240     flags |= MU_PRIO_NONE;
01241 #       endif /* ACE_PSOS_HAS_PRIO_INHERIT_MUTEX */
01242 
01243 #     else /* ! ACE_PSOS_HAS_PRIO_MUTEX */
01244 
01245     flags |= MU_FIFO | MU_PRIO_NONE;
01246 
01247 #     endif
01248 
01249     // Fake a pSOS name - it can be any 4-byte value, not necessarily needing
01250     // to be ASCII. So use the mutex pointer passed in. That should identify
01251     // each one uniquely.
01252     union { ACE_mutex_t *p; char n[4]; } m_name;
01253     m_name.p = m;
01254 
01255     ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::mu_create (m_name.n,
01256                                                       flags,
01257                                                       ceiling,
01258                                                       m),
01259                                          ace_result_),
01260                        int, -1);
01261 
01262 #   else /* ! ACE_PSOS_HAS_MUTEX */
01263   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sm_create ((char *) name,
01264                                                     1,
01265                                                     SM_LOCAL | SM_PRIOR,
01266                                                     m),
01267                                        ace_result_),
01268                      int, -1);
01269 #   endif /* ACE_PSOS_HAS_MUTEX */
01270 # elif defined (VXWORKS)
01271   ACE_UNUSED_ARG (name);
01272   ACE_UNUSED_ARG (attributes);
01273   ACE_UNUSED_ARG (sa);
01274 
01275   return (*m = ::semMCreate (type)) == 0 ? -1 : 0;
01276 # endif /* ACE_HAS_PTHREADS */
01277 #else
01278   ACE_UNUSED_ARG (m);
01279   ACE_UNUSED_ARG (type);
01280   ACE_UNUSED_ARG (name);
01281   ACE_UNUSED_ARG (attributes);
01282   ACE_UNUSED_ARG (sa);
01283   ACE_NOTSUP_RETURN (-1);
01284 #endif /* ACE_HAS_THREADS */
01285 }
01286 
01287 #if defined (ACE_HAS_WCHAR)
01288 ACE_INLINE int
01289 ACE_OS::mutex_init (ACE_mutex_t *m,
01290                     int type,
01291                     const wchar_t *name,
01292                     ACE_mutexattr_t *attributes,
01293                     LPSECURITY_ATTRIBUTES sa)
01294 {
01295 #if defined (ACE_HAS_THREADS) && defined (ACE_HAS_WTHREADS)
01296   m->type_ = type;
01297 
01298   switch (type)
01299     {
01300     case USYNC_PROCESS:
01301       m->proc_mutex_ = ::CreateMutexW (ACE_OS::default_win32_security_attributes (sa),
01302                                        FALSE,
01303                                        name);
01304       if (m->proc_mutex_ == 0)
01305         ACE_FAIL_RETURN (-1);
01306       else
01307         return 0;
01308     case USYNC_THREAD:
01309       return ACE_OS::thread_mutex_init (&m->thr_mutex_,
01310                                         type,
01311                                         name,
01312                                         attributes);
01313     }
01314 
01315   errno = EINVAL;
01316   return -1;
01317 #else /* ACE_HAS_THREADS && ACE_HAS_WTHREADS */
01318   return ACE_OS::mutex_init (m,
01319                              type, ACE_Wide_To_Ascii (name).char_rep (),
01320                              attributes,
01321                              sa);
01322 #endif /* ACE_HAS_THREADS && ACE_HAS_WTHREADS */
01323 }
01324 #endif /* ACE_HAS_WCHAR */
01325 
01326 ACE_INLINE int
01327 ACE_OS::mutex_destroy (ACE_mutex_t *m)
01328 {
01329   ACE_OS_TRACE ("ACE_OS::mutex_destroy");
01330 #if defined (ACE_HAS_THREADS)
01331 # if defined (ACE_HAS_PTHREADS)
01332 #   if (defined (ACE_HAS_PTHREADS_DRAFT4) || defined (ACE_HAS_PTHREADS_DRAFT6))
01333   ACE_OSCALL_RETURN (::pthread_mutex_destroy (m), int, -1);
01334 #   else
01335   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_mutex_destroy (m),
01336                                        ace_result_), int, -1);
01337 #   endif /* ACE_HAS_PTHREADS_DRAFT4 || ACE_HAS_PTHREADS_DRAFT6*/
01338 # elif defined (ACE_HAS_STHREADS)
01339   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::mutex_destroy (m), ace_result_), int, -1);
01340 # elif defined (ACE_HAS_WTHREADS)
01341   switch (m->type_)
01342     {
01343     case USYNC_PROCESS:
01344       ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::CloseHandle (m->proc_mutex_),
01345                                               ace_result_),
01346                             int, -1);
01347     case USYNC_THREAD:
01348       return ACE_OS::thread_mutex_destroy (&m->thr_mutex_);
01349     default:
01350       errno = EINVAL;
01351       return -1;
01352     }
01353   /* NOTREACHED */
01354 # elif defined (ACE_PSOS)
01355 #   if defined (ACE_PSOS_HAS_MUTEX)
01356   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::mu_delete (*m), ace_result_),
01357                      int, -1);
01358 #   else /* ! ACE_PSOS_HAS_MUTEX */
01359   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sm_delete (*m), ace_result_),
01360                      int, -1);
01361 #   endif /* ACE_PSOS_HAS_MUTEX */
01362 # elif defined (VXWORKS)
01363   return ::semDelete (*m) == OK ? 0 : -1;
01364 # endif /* Threads variety case */
01365 #else
01366   ACE_UNUSED_ARG (m);
01367   ACE_NOTSUP_RETURN (-1);
01368 #endif /* ACE_HAS_THREADS */
01369 }
01370 
01371 ACE_INLINE int
01372 ACE_OS::mutex_lock (ACE_mutex_t *m)
01373 {
01374   // ACE_OS_TRACE ("ACE_OS::mutex_lock");
01375 #if defined (ACE_HAS_THREADS)
01376 # if defined (ACE_HAS_PTHREADS)
01377   // Note, don't use "::" here since the following call is often a macro.
01378 #   if (defined (ACE_HAS_PTHREADS_DRAFT4) || defined (ACE_HAS_PTHREADS_DRAFT6))
01379   ACE_OSCALL_RETURN (pthread_mutex_lock (m), int, -1);
01380 #   else
01381   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_mutex_lock (m), ace_result_),
01382                      int, -1);
01383 #   endif /* ACE_HAS_PTHREADS_DRAFT4 || ACE_HAS_PTHREADS_DRAFT6 */
01384 # elif defined (ACE_HAS_STHREADS)
01385   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::mutex_lock (m), ace_result_), int, -1);
01386 # elif defined (ACE_HAS_WTHREADS)
01387   switch (m->type_)
01388     {
01389     case USYNC_PROCESS:
01390       switch (::WaitForSingleObject (m->proc_mutex_, INFINITE))
01391         {
01392           //
01393           // Timeout can't occur, so don't bother checking...
01394           //
01395         case WAIT_OBJECT_0:
01396         case WAIT_ABANDONED:
01397           // We will ignore abandonments in this method
01398           // Note that we still hold the lock
01399           return 0;
01400         default:
01401           // This is a hack, we need to find an appropriate mapping...
01402           ACE_OS::set_errno_to_last_error ();
01403           return -1;
01404         }
01405     case USYNC_THREAD:
01406       return ACE_OS::thread_mutex_lock (&m->thr_mutex_);
01407     default:
01408       errno = EINVAL;
01409       return -1;
01410     }
01411   /* NOTREACHED */
01412 # elif defined (ACE_PSOS)
01413 #   if defined (ACE_PSOS_HAS_MUTEX)
01414   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::mu_lock (*m, MU_WAIT, 0),
01415                                        ace_result_),
01416                      int, -1);
01417 #   else /* ACE_PSOS_HAS_MUTEX */
01418   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sm_p (*m, SM_WAIT, 0),
01419                                        ace_result_),
01420                      int, -1);
01421 #   endif /* ACE_PSOS_HAS_MUTEX */
01422 # elif defined (VXWORKS)
01423   return ::semTake (*m, WAIT_FOREVER) == OK ? 0 : -1;
01424 # endif /* Threads variety case */
01425 #else
01426   ACE_UNUSED_ARG (m);
01427   ACE_NOTSUP_RETURN (-1);
01428 #endif /* ACE_HAS_THREADS */
01429 }
01430 
01431 ACE_INLINE int
01432 ACE_OS::mutex_lock (ACE_mutex_t *m,
01433                     int &abandoned)
01434 {
01435   ACE_OS_TRACE ("ACE_OS::mutex_lock");
01436 #if defined (ACE_HAS_THREADS) && defined (ACE_HAS_WTHREADS)
01437   abandoned = 0;
01438   switch (m->type_)
01439     {
01440     case USYNC_PROCESS:
01441       switch (::WaitForSingleObject (m->proc_mutex_, INFINITE))
01442         {
01443           //
01444           // Timeout can't occur, so don't bother checking...
01445           //
01446         case WAIT_OBJECT_0:
01447           return 0;
01448         case WAIT_ABANDONED:
01449           abandoned = 1;
01450           return 0;  // something goofed, but we hold the lock ...
01451         default:
01452           // This is a hack, we need to find an appropriate mapping...
01453           ACE_OS::set_errno_to_last_error ();
01454           return -1;
01455         }
01456     case USYNC_THREAD:
01457       return ACE_OS::thread_mutex_lock (&m->thr_mutex_);
01458     default:
01459       errno = EINVAL;
01460       return -1;
01461     }
01462   /* NOTREACHED */
01463 #else
01464   ACE_UNUSED_ARG (m);
01465   ACE_UNUSED_ARG (abandoned);
01466   ACE_NOTSUP_RETURN (-1);
01467 #endif /* ACE_HAS_THREADS and ACE_HAS_WTHREADS */
01468 }
01469 
01470 ACE_INLINE int
01471 ACE_OS::mutex_trylock (ACE_mutex_t *m)
01472 {
01473   ACE_OS_TRACE ("ACE_OS::mutex_trylock");
01474 #if defined (ACE_HAS_THREADS)
01475 # if defined (ACE_HAS_PTHREADS)
01476   // Note, don't use "::" here since the following call is often a macro.
01477 #   if (defined (ACE_HAS_PTHREADS_DRAFT4) || defined (ACE_HAS_PTHREADS_DRAFT6))
01478   int status = pthread_mutex_trylock (m);
01479   if (status == 1)
01480     status = 0;
01481   else if (status == 0) {
01482     status = -1;
01483     errno = EBUSY;
01484   }
01485   return status;
01486 #   else
01487   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_mutex_trylock (m), ace_result_),
01488                      int, -1);
01489 #   endif /* ACE_HAS_PTHREADS_DRAFT4 || ACE_HAS_PTHREADS_DRAFT6 */
01490 # elif defined (ACE_HAS_STHREADS)
01491   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::mutex_trylock (m), ace_result_), int, -1);
01492 # elif defined (ACE_HAS_WTHREADS)
01493   switch (m->type_)
01494     {
01495     case USYNC_PROCESS:
01496       {
01497         // Try for 0 milliseconds - i.e. nonblocking.
01498         switch (::WaitForSingleObject (m->proc_mutex_, 0))
01499           {
01500           case WAIT_OBJECT_0:
01501             return 0;
01502           case WAIT_ABANDONED:
01503             // We will ignore abandonments in this method.  Note that
01504             // we still hold the lock.
01505             return 0;
01506           case WAIT_TIMEOUT:
01507             errno = EBUSY;
01508             return -1;
01509           default:
01510             ACE_OS::set_errno_to_last_error ();
01511             return -1;
01512           }
01513       }
01514     case USYNC_THREAD:
01515       return ACE_OS::thread_mutex_trylock (&m->thr_mutex_);
01516     default:
01517       errno = EINVAL;
01518       return -1;
01519     }
01520   /* NOTREACHED */
01521 # elif defined (ACE_PSOS)
01522 #   if defined (ACE_PSOS_HAS_MUTEX)
01523    ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::mu_lock (*m, MU_NOWAIT, 0),
01524                                         ace_result_),
01525                       int, -1);
01526 #   else /* ! ACE_PSOS_HAS_MUTEX */
01527    switch (::sm_p (*m, SM_NOWAIT, 0))
01528    {
01529      case 0:
01530        return 0;
01531      case ERR_NOSEM:
01532        errno = EBUSY;
01533        // intentional fall through
01534      default:
01535        return -1;
01536    }
01537 #   endif /* ACE_PSOS_HAS_MUTEX */
01538 
01539 # elif defined (VXWORKS)
01540   if (::semTake (*m, NO_WAIT) == ERROR)
01541     if (errno == S_objLib_OBJ_UNAVAILABLE)
01542       {
01543         // couldn't get the semaphore
01544         errno = EBUSY;
01545         return -1;
01546       }
01547     else
01548       // error
01549       return -1;
01550   else
01551     // got the semaphore
01552     return 0;
01553 # endif /* Threads variety case */
01554 #else
01555   ACE_UNUSED_ARG (m);
01556   ACE_NOTSUP_RETURN (-1);
01557 #endif /* ACE_HAS_THREADS */
01558 }
01559 
01560 ACE_INLINE int
01561 ACE_OS::mutex_trylock (ACE_mutex_t *m, int &abandoned)
01562 {
01563 #if defined (ACE_HAS_THREADS) && defined (ACE_HAS_WTHREADS)
01564   abandoned = 0;
01565   switch (m->type_)
01566     {
01567     case USYNC_PROCESS:
01568       {
01569         // Try for 0 milliseconds - i.e. nonblocking.
01570         switch (::WaitForSingleObject (m->proc_mutex_, 0))
01571           {
01572           case WAIT_OBJECT_0:
01573             return 0;
01574           case WAIT_ABANDONED:
01575             abandoned = 1;
01576             return 0;  // something goofed, but we hold the lock ...
01577           case WAIT_TIMEOUT:
01578             errno = EBUSY;
01579             return -1;
01580           default:
01581             ACE_OS::set_errno_to_last_error ();
01582             return -1;
01583           }
01584       }
01585     case USYNC_THREAD:
01586       return ACE_OS::thread_mutex_trylock (&m->thr_mutex_);
01587     default:
01588       errno = EINVAL;
01589       return -1;
01590     }
01591   /* NOTREACHED */
01592 #else
01593   ACE_UNUSED_ARG (m);
01594   ACE_UNUSED_ARG (abandoned);
01595   ACE_NOTSUP_RETURN (-1);
01596 #endif /* ACE_HAS_THREADS and ACE_HAS_WTHREADS */
01597 }
01598 
01599 ACE_INLINE int
01600 ACE_OS::mutex_lock (ACE_mutex_t *m,
01601                     const ACE_Time_Value &timeout)
01602 {
01603 #if defined (ACE_HAS_THREADS) && defined (ACE_HAS_MUTEX_TIMEOUTS)
01604 
01605 #  if defined (ACE_HAS_PTHREADS)
01606   int result;
01607 
01608   // "timeout" should be an absolute time.
01609 
01610   timespec_t ts = timeout;  // Calls ACE_Time_Value::operator timespec_t().
01611 
01612   // Note that the mutex should not be a recursive one, i.e., it
01613   // should only be a standard mutex or an error checking mutex.
01614 
01615   ACE_OSCALL (ACE_ADAPT_RETVAL (::pthread_mutex_timedlock (m, &ts), result), int, -1, result);
01616 
01617   // We need to adjust this to make the errno values consistent.
01618   if (result == -1 && errno == ETIMEDOUT)
01619     errno = ETIME;
01620   return result;
01621 
01622 #  elif defined (ACE_HAS_WTHREADS)
01623   // Note that we must convert between absolute time (which is passed
01624   // as a parameter) and relative time (which is what the system call
01625   // expects).
01626   ACE_Time_Value relative_time (timeout - ACE_OS::gettimeofday ());
01627 
01628   switch (m->type_)
01629     {
01630     case USYNC_PROCESS:
01631       switch (::WaitForSingleObject (m->proc_mutex_,
01632                                      relative_time.msec ()))
01633         {
01634         case WAIT_OBJECT_0:
01635         case WAIT_ABANDONED:
01636           // We will ignore abandonments in this method
01637           // Note that we still hold the lock
01638           return 0;
01639         case WAIT_TIMEOUT:
01640           errno = ETIME;
01641           return -1;
01642         default:
01643           // This is a hack, we need to find an appropriate mapping...
01644           ACE_OS::set_errno_to_last_error ();
01645           return -1;
01646         }
01647     case USYNC_THREAD:
01648       ACE_NOTSUP_RETURN (-1);
01649     default:
01650       errno = EINVAL;
01651       return -1;
01652     }
01653   /* NOTREACHED */
01654 
01655 #  elif defined (ACE_PSOS)
01656 
01657   // Note that we must convert between absolute time (which is
01658   // passed as a parameter) and relative time (which is what
01659   // the system call expects).
01660   ACE_Time_Value relative_time (timeout - ACE_OS::gettimeofday ());
01661 
01662   u_long ticks = relative_time.sec() * KC_TICKS2SEC +
01663                  relative_time.usec () * KC_TICKS2SEC /
01664                    ACE_ONE_SECOND_IN_USECS;
01665   if (ticks == 0)
01666     ACE_OSCALL_RETURN (::sm_p (*m, SM_NOWAIT, 0), int, -1); // no timeout
01667   else
01668     ACE_OSCALL_RETURN (::sm_p (*m, SM_WAIT, ticks), int, -1);
01669 
01670 #  elif defined (VXWORKS)
01671 
01672   // Note that we must convert between absolute time (which is passed
01673   // as a parameter) and relative time (which is what the system call
01674   // expects).
01675   ACE_Time_Value relative_time (timeout - ACE_OS::gettimeofday ());
01676 
01677   int ticks_per_sec = ::sysClkRateGet ();
01678 
01679   int ticks = relative_time.sec() * ticks_per_sec +
01680               relative_time.usec () * ticks_per_sec / ACE_ONE_SECOND_IN_USECS;
01681   if (::semTake (*m, ticks) == ERROR)
01682     {
01683       if (errno == S_objLib_OBJ_TIMEOUT)
01684         // Convert the VxWorks errno to one that's common for to ACE
01685         // platforms.
01686         errno = ETIME;
01687       else if (errno == S_objLib_OBJ_UNAVAILABLE)
01688         errno = EBUSY;
01689       return -1;
01690     }
01691   else
01692     return 0;
01693 #  endif /* ACE_HAS_PTHREADS */
01694 
01695 #else
01696   ACE_UNUSED_ARG (m);
01697   ACE_UNUSED_ARG (timeout);
01698   ACE_NOTSUP_RETURN (-1);
01699 #endif /* ACE_HAS_THREADS && ACE_HAS_MUTEX_TIMEOUTS */
01700 }
01701 
01702 ACE_INLINE int
01703 ACE_OS::mutex_lock (ACE_mutex_t *m,
01704                     const ACE_Time_Value *timeout)
01705 {
01706   return timeout == 0 ? ACE_OS::mutex_lock (m) : ACE_OS::mutex_lock (m, *timeout);
01707 }
01708 
01709 ACE_INLINE int
01710 ACE_OS::mutex_unlock (ACE_mutex_t *m)
01711 {
01712   ACE_OS_TRACE ("ACE_OS::mutex_unlock");
01713 #if defined (ACE_HAS_THREADS)
01714 # if defined (ACE_HAS_PTHREADS)
01715   // Note, don't use "::" here since the following call is often a macro.
01716 #   if (defined (ACE_HAS_PTHREADS_DRAFT4) || defined (ACE_HAS_PTHREADS_DRAFT6))
01717   ACE_OSCALL_RETURN (pthread_mutex_unlock (m), int, -1);
01718 #   else
01719   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_mutex_unlock (m), ace_result_),
01720                      int, -1);
01721 #   endif /* ACE_HAS_PTHREADS_DRAFT4 || ACE_HAS_PTHREADS_DRAFT6 */
01722 # elif defined (ACE_HAS_STHREADS)
01723   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::mutex_unlock (m), ace_result_), int, -1);
01724 # elif defined (ACE_HAS_WTHREADS)
01725   switch (m->type_)
01726     {
01727     case USYNC_PROCESS:
01728       ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::ReleaseMutex (m->proc_mutex_),
01729                                               ace_result_),
01730                             int, -1);
01731     case USYNC_THREAD:
01732       return ACE_OS::thread_mutex_unlock (&m->thr_mutex_);
01733     default:
01734       errno = EINVAL;
01735       return -1;
01736     }
01737   /* NOTREACHED */
01738 # elif defined (ACE_PSOS)
01739 #   if defined (ACE_PSOS_HAS_MUTEX)
01740   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::mu_unlock (*m), ace_result_),
01741                      int, -1);
01742 #   else /* ! ACE_PSOS_HAS_MUTEX */
01743   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sm_v (*m), ace_result_),
01744                      int, -1);
01745 #   endif /* ACE_PSOS_HAS_MUTEX */
01746 # elif defined (VXWORKS)
01747   return ::semGive (*m) == OK ? 0 : -1;
01748 # endif /* Threads variety case */
01749 #else
01750   ACE_UNUSED_ARG (m);
01751   ACE_NOTSUP_RETURN (-1);
01752 #endif /* ACE_HAS_THREADS */
01753 }
01754 
01755 ACE_INLINE int
01756 ACE_OS::thread_mutex_init (ACE_thread_mutex_t *m,
01757                            int type,
01758                            const char *name,
01759                            ACE_mutexattr_t *arg)
01760 {
01761   // ACE_OS_TRACE ("ACE_OS::thread_mutex_init");
01762 #if defined (ACE_HAS_THREADS)
01763 # if defined (ACE_HAS_WTHREADS)
01764   ACE_UNUSED_ARG (type);
01765   ACE_UNUSED_ARG (name);
01766   ACE_UNUSED_ARG (arg);
01767   ::InitializeCriticalSection (m);
01768   return 0;
01769 
01770 # elif defined (ACE_HAS_STHREADS) || defined (ACE_HAS_PTHREADS)
01771   ACE_UNUSED_ARG (type);
01772   // Force the use of USYNC_THREAD!
01773   return ACE_OS::mutex_init (m, USYNC_THREAD, name, arg);
01774 
01775 # elif defined (VXWORKS) || defined (ACE_PSOS)
01776   return mutex_init (m, type, name, arg);
01777 
01778 # endif /* ACE_HAS_STHREADS || ACE_HAS_PTHREADS */
01779 
01780 #else
01781   ACE_UNUSED_ARG (m);
01782   ACE_UNUSED_ARG (type);
01783   ACE_UNUSED_ARG (name);
01784   ACE_UNUSED_ARG (arg);
01785   ACE_NOTSUP_RETURN (-1);
01786 
01787 #endif /* ACE_HAS_THREADS */
01788 }
01789 
01790 #if defined (ACE_HAS_WCHAR)
01791 ACE_INLINE int
01792 ACE_OS::thread_mutex_init (ACE_thread_mutex_t *m,
01793                            int type,
01794                            const wchar_t *name,
01795                            ACE_mutexattr_t *arg)
01796 {
01797   // ACE_OS_TRACE ("ACE_OS::thread_mutex_init");
01798 #if defined (ACE_HAS_THREADS)
01799 # if defined (ACE_HAS_WTHREADS)
01800   ACE_UNUSED_ARG (type);
01801   ACE_UNUSED_ARG (name);
01802   ACE_UNUSED_ARG (arg);
01803   ::InitializeCriticalSection (m);
01804   return 0;
01805 
01806 # elif defined (ACE_HAS_STHREADS) || defined (ACE_HAS_PTHREADS)
01807   ACE_UNUSED_ARG (type);
01808   // Force the use of USYNC_THREAD!
01809   return ACE_OS::mutex_init (m, USYNC_THREAD, name, arg);
01810 
01811 # elif defined (VXWORKS) || defined (ACE_PSOS)
01812   return mutex_init (m, type, name, arg);
01813 
01814 # endif /* ACE_HAS_STHREADS || ACE_HAS_PTHREADS */
01815 
01816 #else
01817   ACE_UNUSED_ARG (m);
01818   ACE_UNUSED_ARG (type);
01819   ACE_UNUSED_ARG (name);
01820   ACE_UNUSED_ARG (arg);
01821   ACE_NOTSUP_RETURN (-1);
01822 
01823 #endif /* ACE_HAS_THREADS */
01824 }
01825 #endif /* ACE_HAS_WCHAR */
01826 
01827 ACE_INLINE int
01828 ACE_OS::thread_mutex_destroy (ACE_thread_mutex_t *m)
01829 {
01830   ACE_OS_TRACE ("ACE_OS::thread_mutex_destroy");
01831 #if defined (ACE_HAS_THREADS)
01832 # if defined (ACE_HAS_WTHREADS)
01833   ::DeleteCriticalSection (m);
01834   return 0;
01835 
01836 # elif defined (ACE_HAS_STHREADS) || defined (ACE_HAS_PTHREADS)
01837   return ACE_OS::mutex_destroy (m);
01838 
01839 # elif defined (VXWORKS) || defined (ACE_PSOS)
01840   return mutex_destroy (m);
01841 
01842 # endif /* ACE_HAS_STHREADS || ACE_HAS_PTHREADS */
01843 
01844 #else
01845   ACE_UNUSED_ARG (m);
01846   ACE_NOTSUP_RETURN (-1);
01847 
01848 #endif /* ACE_HAS_THREADS */
01849 }
01850 
01851 ACE_INLINE int
01852 ACE_OS::thread_mutex_lock (ACE_thread_mutex_t *m)
01853 {
01854   // ACE_OS_TRACE ("ACE_OS::thread_mutex_lock");
01855 #if defined (ACE_HAS_THREADS)
01856 # if defined (ACE_HAS_WTHREADS)
01857   ::EnterCriticalSection (m);
01858   return 0;
01859 # elif defined (ACE_HAS_STHREADS) || defined (ACE_HAS_PTHREADS)
01860   return ACE_OS::mutex_lock (m);
01861 # elif defined (VXWORKS) || defined (ACE_PSOS)
01862   return mutex_lock (m);
01863 # endif /* ACE_HAS_STHREADS || ACE_HAS_PTHREADS */
01864 #else
01865   ACE_UNUSED_ARG (m);
01866   ACE_NOTSUP_RETURN (-1);
01867 #endif /* ACE_HAS_THREADS */
01868 }
01869 
01870 ACE_INLINE int
01871 ACE_OS::thread_mutex_lock (ACE_thread_mutex_t *m,
01872                            const ACE_Time_Value &timeout)
01873 {
01874   // ACE_OS_TRACE ("ACE_OS::thread_mutex_lock");
01875 
01876   // For all platforms, except MS Windows, this method is equivalent
01877   // to calling ACE_OS::mutex_lock() since ACE_thread_mutex_t and
01878   // ACE_mutex_t are the same type.  However, those typedefs evaluate
01879   // to different types on MS Windows.  The "thread mutex"
01880   // implementation in ACE for MS Windows cannot readily support
01881   // timeouts due to a lack of timeout features for this type of MS
01882   // Windows synchronization mechanism.
01883 
01884 #if defined (ACE_HAS_THREADS) && !defined (ACE_HAS_WTHREADS)
01885 # if defined (ACE_HAS_STHREADS) || defined (ACE_HAS_PTHREADS)
01886   return ACE_OS::mutex_lock (m, timeout);
01887 #elif defined (VXWORKS) || defined (ACE_PSOS)
01888   return mutex_lock (m, timeout);
01889 #endif /* ACE_HAS_STHREADS || ACE_HAS_PTHREADS */
01890 #else
01891   ACE_UNUSED_ARG (m);
01892   ACE_UNUSED_ARG (timeout);
01893   ACE_NOTSUP_RETURN (-1);
01894 #endif /* ACE_HAS_THREADS */
01895 }
01896 
01897 ACE_INLINE int
01898 ACE_OS::thread_mutex_lock (ACE_thread_mutex_t *m,
01899                            const ACE_Time_Value *timeout)
01900 {
01901   return timeout == 0
01902     ? ACE_OS::thread_mutex_lock (m)
01903     : ACE_OS::thread_mutex_lock (m, *timeout);
01904 }
01905 
01906 ACE_INLINE int
01907 ACE_OS::thread_mutex_trylock (ACE_thread_mutex_t *m)
01908 {
01909   ACE_OS_TRACE ("ACE_OS::thread_mutex_trylock");
01910 
01911 #if defined (ACE_HAS_THREADS)
01912 # if defined (ACE_HAS_WTHREADS)
01913 #   if defined (ACE_HAS_WIN32_TRYLOCK)
01914   BOOL result = ::TryEnterCriticalSection (m);
01915   if (result == TRUE)
01916     return 0;
01917   else
01918     {
01919       errno = EBUSY;
01920       return -1;
01921     }
01922 #   else
01923   ACE_UNUSED_ARG (m);
01924   ACE_NOTSUP_RETURN (-1);
01925 #   endif /* ACE_HAS_WIN32_TRYLOCK */
01926 # elif defined (ACE_HAS_STHREADS) || defined (ACE_HAS_PTHREADS)
01927   return ACE_OS::mutex_trylock (m);
01928 # elif defined (VXWORKS) || defined (ACE_PSOS)
01929   return ACE_OS::mutex_trylock (m);
01930 #endif /* Threads variety case */
01931 
01932 #else
01933   ACE_UNUSED_ARG (m);
01934   ACE_NOTSUP_RETURN (-1);
01935 #endif /* ACE_HAS_THREADS */
01936 }
01937 
01938 ACE_INLINE int
01939 ACE_OS::thread_mutex_unlock (ACE_thread_mutex_t *m)
01940 {
01941   ACE_OS_TRACE ("ACE_OS::thread_mutex_unlock");
01942 #if defined (ACE_HAS_THREADS)
01943 # if defined (ACE_HAS_WTHREADS)
01944   ::LeaveCriticalSection (m);
01945   return 0;
01946 # elif defined (ACE_HAS_STHREADS) || defined (ACE_HAS_PTHREADS)
01947   return ACE_OS::mutex_unlock (m);
01948 # elif defined (VXWORKS) || defined (ACE_PSOS)
01949   return ACE_OS::mutex_unlock (m);
01950 # endif /* Threads variety case */
01951 #else
01952   ACE_UNUSED_ARG (m);
01953   ACE_NOTSUP_RETURN (-1);
01954 #endif /* ACE_HAS_THREADS */
01955 }
01956 
01957 #if !defined (ACE_LACKS_COND_T)
01958 // NOTE: The ACE_OS::cond_* functions for Unix platforms are defined
01959 // here because the ACE_OS::sema_* functions below need them.
01960 // However, ACE_WIN32 and VXWORKS define the ACE_OS::cond_* functions
01961 // using the ACE_OS::sema_* functions.  So, they are defined in OS.cpp.
01962 
01963 ACE_INLINE int
01964 ACE_OS::cond_destroy (ACE_cond_t *cv)
01965 {
01966   ACE_OS_TRACE ("ACE_OS::cond_destroy");
01967 # if defined (ACE_HAS_THREADS)
01968 #   if defined (ACE_HAS_PTHREADS)
01969 #     if defined (ACE_HAS_PTHREADS_DRAFT4) || defined (ACE_HAS_PTHREADS_DRAFT6)
01970   ACE_OSCALL_RETURN (::pthread_cond_destroy (cv), int, -1);
01971 #     else
01972   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_cond_destroy (cv), ace_result_), int, -1);
01973 #     endif /* ACE_HAS_PTHREADS_DRAFT4 || ACE_HAS_PTHREADS_DRAFT6 */
01974 #   elif defined (ACE_HAS_STHREADS)
01975   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::cond_destroy (cv), ace_result_), int, -1);
01976 #   elif defined (ACE_PSOS) && defined (ACE_PSOS_HAS_COND_T)
01977   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::cv_delete (*cv), ace_result_),
01978                      int, -1);
01979 #   endif /* ACE_HAS_STHREADS */
01980 # else
01981   ACE_UNUSED_ARG (cv);
01982   ACE_NOTSUP_RETURN (-1);
01983 # endif /* ACE_HAS_THREADS */
01984 }
01985 
01986 ACE_INLINE int
01987 ACE_OS::condattr_init (ACE_condattr_t &attributes,
01988                        int type)
01989 {
01990   ACE_UNUSED_ARG (type);
01991 # if defined (ACE_HAS_THREADS)
01992 #   if defined (ACE_HAS_PTHREADS)
01993   int result = -1;
01994 
01995   if (
01996 #     if defined  (ACE_HAS_PTHREADS_DRAFT4)
01997       ::pthread_condattr_create (&attributes) == 0
01998 #     elif defined (ACE_HAS_PTHREADS_STD) || defined (ACE_HAS_PTHREADS_DRAFT7)
01999       ACE_ADAPT_RETVAL(::pthread_condattr_init (&attributes), result) == 0
02000 #       if defined (_POSIX_THREAD_PROCESS_SHARED) && !defined (ACE_LACKS_MUTEXATTR_PSHARED)
02001       && ACE_ADAPT_RETVAL(::pthread_condattr_setpshared(&attributes, type),
02002                           result) == 0
02003 #       endif /* _POSIX_THREAD_PROCESS_SHARED && ! ACE_LACKS_MUTEXATTR_PSHARED */
02004 #     else  /* this is draft 6 */
02005       ::pthread_condattr_init (&attributes) == 0
02006 #       if !defined (ACE_LACKS_CONDATTR_PSHARED)
02007       && ::pthread_condattr_setpshared (&attributes, type) == 0
02008 #       endif /* ACE_LACKS_CONDATTR_PSHARED */
02009 #       if defined (ACE_HAS_PTHREAD_CONDATTR_SETKIND_NP)
02010       && ::pthread_condattr_setkind_np (&attributes, type) == 0
02011 #       endif /* ACE_HAS_PTHREAD_CONDATTR_SETKIND_NP */
02012 #     endif /* ACE_HAS_PTHREADS_DRAFT4 */
02013       )
02014      result = 0;
02015   else
02016      result = -1;       // ACE_ADAPT_RETVAL used it for intermediate status
02017 
02018   return result;
02019 #   elif defined (ACE_HAS_STHREADS)
02020   attributes.type = type;
02021 
02022   return 0;
02023 
02024 #   elif defined (ACE_PSOS) && defined (ACE_PSOS_HAS_COND_T)
02025 #     if defined (ACE_PSOS_HAS_PRIO_MUTEX)
02026   attributes = CV_LOCAL | CV_PRIOR;
02027 #     else /* ACE_PSOS_HAS_PRIO_MUTEX */
02028   attributes = CV_LOCAL | CV_FIFO;
02029 #     endif /* ACE_PSOS_HAS_PRIO_MUTEX */
02030   return 0;
02031 
02032 #   else
02033   ACE_UNUSED_ARG (attributes);
02034   ACE_UNUSED_ARG (type);
02035   ACE_NOTSUP_RETURN (-1);
02036 
02037 #   endif /* ACE_HAS_PTHREADS vs. ACE_HAS_STHREADS vs. pSOS */
02038 
02039 # else
02040   ACE_UNUSED_ARG (attributes);
02041   ACE_UNUSED_ARG (type);
02042   ACE_NOTSUP_RETURN (-1);
02043 # endif /* ACE_HAS_THREADS */
02044 }
02045 
02046 ACE_INLINE int
02047 ACE_OS::condattr_destroy (ACE_condattr_t &attributes)
02048 {
02049 #if defined (ACE_HAS_THREADS)
02050 #   if defined (ACE_HAS_PTHREADS)
02051 
02052 #     if defined (ACE_HAS_PTHREADS_DRAFT4)
02053   ::pthread_condattr_delete (&attributes);
02054 #     else
02055   ::pthread_condattr_destroy (&attributes);
02056 #     endif /* ACE_HAS_PTHREADS_DRAFT4 */
02057 
02058 #   elif defined (ACE_HAS_STHREADS)
02059   attributes.type = 0;
02060 
02061 #   elif defined (ACE_PSOS) && defined (ACE_PSOS_HAS_COND_T)
02062   attributes = 0;
02063 
02064 #   endif /* ACE_HAS_PTHREADS vs. ACE_HAS_STHREADS vs. ACE_PSOS */
02065   return 0;
02066 # else
02067   ACE_UNUSED_ARG (attributes);
02068   return 0;
02069 # endif /* ACE_HAS_THREADS  */
02070 }
02071 
02072 ACE_INLINE int
02073 ACE_OS::cond_init (ACE_cond_t *cv,
02074                    ACE_condattr_t &attributes,
02075                    const char *name,
02076                    void *arg)
02077 {
02078   // ACE_OS_TRACE ("ACE_OS::cond_init");
02079   ACE_UNUSED_ARG (name);
02080   ACE_UNUSED_ARG (arg);
02081 # if defined (ACE_HAS_THREADS)
02082 #   if defined (ACE_HAS_PTHREADS)
02083   int result = -1;
02084 
02085   if (
02086 #     if defined  (ACE_HAS_PTHREADS_DRAFT4)
02087       ::pthread_cond_init (cv, attributes) == 0
02088 #     elif defined (ACE_HAS_PTHREADS_STD) || defined (ACE_HAS_PTHREADS_DRAFT7)
02089       ACE_ADAPT_RETVAL(::pthread_cond_init (cv, &attributes), result) == 0
02090 #     else  /* this is draft 6 */
02091       ::pthread_cond_init (cv, &attributes) == 0
02092 #     endif /* ACE_HAS_PTHREADS_DRAFT4 */
02093       )
02094      result = 0;
02095   else
02096      result = -1;       // ACE_ADAPT_RETVAL used it for intermediate status
02097 
02098   return result;
02099 #   elif defined (ACE_HAS_STHREADS)
02100   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::cond_init (cv,
02101                                                     attributes.type,
02102                                                     arg),
02103                                        ace_result_),
02104                      int, -1);
02105 #   elif defined (ACE_PSOS) && defined (ACE_PSOS_HAS_COND_T)
02106   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::cv_create (ACE_const_cast (char *, name),
02107                                                     attributes,
02108                                                     cv),
02109                                        ace_result_),
02110                      int, -1);
02111 #   endif /* ACE_HAS_PTHREADS vs. ACE_HAS_STHREADS vs. ACE_PSOS */
02112 # else
02113   ACE_UNUSED_ARG (cv);
02114   ACE_UNUSED_ARG (attributes);
02115   ACE_UNUSED_ARG (name);
02116   ACE_UNUSED_ARG (arg);
02117   ACE_NOTSUP_RETURN (-1);
02118 # endif /* ACE_HAS_THREADS */
02119 }
02120 
02121 #if defined (ACE_HAS_WCHAR)
02122 ACE_INLINE int
02123 ACE_OS::cond_init (ACE_cond_t *cv,
02124                    ACE_condattr_t &attributes,
02125                    const wchar_t *name,
02126                    void *arg)
02127 {
02128   return ACE_OS::cond_init (cv, attributes, ACE_Wide_To_Ascii (name).char_rep (), arg);
02129 }
02130 #endif /* ACE_HAS_WCHAR */
02131 
02132 ACE_INLINE int
02133 ACE_OS::cond_init (ACE_cond_t *cv, short type, const char *name, void *arg)
02134 {
02135   ACE_condattr_t attributes;
02136   if (ACE_OS::condattr_init (attributes, type) == 0
02137       && ACE_OS::cond_init (cv, attributes, name, arg) == 0)
02138     {
02139       (void) ACE_OS::condattr_destroy (attributes);
02140       return 0;
02141     }
02142   return -1;
02143 }
02144 
02145 #if defined (ACE_HAS_WCHAR)
02146 ACE_INLINE int
02147 ACE_OS::cond_init (ACE_cond_t *cv, short type, const wchar_t *name, void *arg)
02148 {
02149   return ACE_OS::cond_init (cv, type, ACE_Wide_To_Ascii (name).char_rep (), arg);
02150 }
02151 #endif /* ACE_HAS_WCHAR */
02152 
02153 ACE_INLINE int
02154 ACE_OS::cond_signal (ACE_cond_t *cv)
02155 {
02156   ACE_OS_TRACE ("ACE_OS::cond_signal");
02157 # if defined (ACE_HAS_THREADS)
02158 #   if defined (ACE_HAS_PTHREADS)
02159 #     if defined (ACE_HAS_PTHREADS_DRAFT4) || defined (ACE_HAS_PTHREADS_DRAFT6)
02160   ACE_OSCALL_RETURN (::pthread_cond_signal (cv), int, -1);
02161 #     else
02162   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_cond_signal (cv),ace_result_),
02163                      int, -1);
02164 #     endif /* ACE_HAS_PTHREADS_DRAFT4 || ACE_HAS_PTHREADS_DRAFT6 */
02165 #   elif defined (ACE_HAS_STHREADS)
02166   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::cond_signal (cv), ace_result_), int, -1);
02167 #   elif defined (ACE_PSOS) && defined (ACE_PSOS_HAS_COND_T)
02168   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::cv_signal (*cv), ace_result_),
02169                      int, -1);
02170 #   endif /* ACE_HAS_STHREADS */
02171 # else
02172   ACE_UNUSED_ARG (cv);
02173   ACE_NOTSUP_RETURN (-1);
02174 # endif /* ACE_HAS_THREADS */
02175 }
02176 
02177 ACE_INLINE int
02178 ACE_OS::cond_broadcast (ACE_cond_t *cv)
02179 {
02180   ACE_OS_TRACE ("ACE_OS::cond_broadcast");
02181 # if defined (ACE_HAS_THREADS)
02182 #   if defined (ACE_HAS_PTHREADS)
02183 #     if defined (ACE_HAS_PTHREADS_DRAFT4) || defined (ACE_HAS_PTHREADS_DRAFT6)
02184   ACE_OSCALL_RETURN (::pthread_cond_broadcast (cv), int, -1);
02185 #     else
02186   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_cond_broadcast (cv),
02187                                        ace_result_),
02188                      int, -1);
02189 #     endif /* ACE_HAS_PTHREADS_DRAFT4 || ACE_HAS_PTHREADS_DRAFT6 */
02190 #   elif defined (ACE_HAS_STHREADS)
02191   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::cond_broadcast (cv),
02192                                        ace_result_),
02193                      int, -1);
02194 #   elif defined (ACE_PSOS) && defined (ACE_PSOS_HAS_COND_T)
02195   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::cv_broadcast (*cv), ace_result_),
02196                      int, -1);
02197 #   endif /* ACE_HAS_STHREADS */
02198 # else
02199   ACE_UNUSED_ARG (cv);
02200   ACE_NOTSUP_RETURN (-1);
02201 # endif /* ACE_HAS_THREADS */
02202 }
02203 
02204 ACE_INLINE int
02205 ACE_OS::cond_wait (ACE_cond_t *cv,
02206                    ACE_mutex_t *external_mutex)
02207 {
02208   ACE_OS_TRACE ("ACE_OS::cond_wait");
02209 # if defined (ACE_HAS_THREADS)
02210 #   if defined (ACE_HAS_PTHREADS)
02211 #     if defined (ACE_HAS_PTHREADS_DRAFT4) || defined (ACE_HAS_PTHREADS_DRAFT6)
02212   ACE_OSCALL_RETURN (::pthread_cond_wait (cv, external_mutex), int, -1);
02213 #     else
02214   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_cond_wait (cv, external_mutex), ace_result_),
02215                      int, -1);
02216 #     endif /* ACE_HAS_PTHREADS_DRAFT4 || ACE_HAS_PTHREADS_DRAFT6 */
02217 #   elif defined (ACE_HAS_STHREADS)
02218   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::cond_wait (cv, external_mutex), ace_result_),
02219                      int, -1);
02220 #   elif defined (ACE_PSOS) && defined (ACE_PSOS_HAS_COND_T)
02221   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::cv_wait (*cv, *external_mutex, 0),
02222                                        ace_result_),
02223                      int, -1);
02224 #   endif /* ACE_HAS_PTHREADS */
02225 # else
02226   ACE_UNUSED_ARG (cv);
02227   ACE_UNUSED_ARG (external_mutex);
02228   ACE_NOTSUP_RETURN (-1);
02229 # endif /* ACE_HAS_THREADS */
02230 }
02231 
02232 ACE_INLINE int
02233 ACE_OS::cond_timedwait (ACE_cond_t *cv,
02234                         ACE_mutex_t *external_mutex,
02235                         ACE_Time_Value *timeout)
02236 {
02237   ACE_OS_TRACE ("ACE_OS::cond_timedwait");
02238 # if defined (ACE_HAS_THREADS)
02239   int result;
02240   timespec_t ts;
02241 
02242   if (timeout != 0)
02243     ts = *timeout; // Calls ACE_Time_Value::operator timespec_t().
02244 
02245 #   if defined (ACE_HAS_PTHREADS)
02246 
02247 #     if defined (ACE_HAS_PTHREADS_DRAFT4) || defined (ACE_HAS_PTHREADS_DRAFT6)
02248   if (timeout == 0)
02249     ACE_OSCALL (::pthread_cond_wait (cv, external_mutex),
02250                 int, -1, result);
02251   else
02252     {
02253 
02254 #     if defined (__Lynx__)
02255       // Note that we must convert between absolute time (which is
02256       // passed as a parameter) and relative time (which is what the
02257       // LynxOS pthread_cond_timedwait expects).  This differs from 1003.4a
02258       // draft 4.
02259 
02260       timespec_t relative_time = *timeout - ACE_OS::gettimeofday ();
02261 
02262       ACE_OSCALL (::pthread_cond_timedwait (cv, external_mutex,
02263                                             &relative_time),
02264                   int, -1, result);
02265 #     else
02266       ACE_OSCALL (::pthread_cond_timedwait (cv, external_mutex,
02267                                             (ACE_TIMESPEC_PTR) &ts),
02268                   int, -1, result);
02269 #     endif /* __Lynx__ */
02270     }
02271 
02272 #     else
02273   ACE_OSCALL (ACE_ADAPT_RETVAL (timeout == 0
02274                                 ? ::pthread_cond_wait (cv, external_mutex)
02275                                 : ::pthread_cond_timedwait (cv, external_mutex,
02276                                                             (ACE_TIMESPEC_PTR) &ts),
02277                                 result),
02278               int, -1, result);
02279 #     endif /* ACE_HAS_PTHREADS_DRAFT4 || ACE_HAS_PTHREADS_DRAFT6*/
02280   // We need to adjust this to make the POSIX and Solaris return
02281   // values consistent.  EAGAIN is from Pthreads DRAFT4 (HP-UX 10.20 and
02282   // down); EINTR is from LynxOS.
02283   if (result == -1 &&
02284       (errno == ETIMEDOUT || errno == EAGAIN || errno == EINTR))
02285     errno = ETIME;
02286 
02287 #   elif defined (ACE_HAS_STHREADS)
02288   ACE_OSCALL (ACE_ADAPT_RETVAL (timeout == 0
02289                                 ? ::cond_wait (cv, external_mutex)
02290                                 : ::cond_timedwait (cv,
02291                                                     external_mutex,
02292                                                     (timestruc_t*)&ts),
02293                                 result),
02294               int, -1, result);
02295 #   elif defined (ACE_PSOS) && defined (ACE_PSOS_HAS_COND_T)
02296   // pSOS condition value timeout is expressed in ticks. If the
02297   // cv_wait times out, the mutex is unlocked upon return.
02298   if (timeout == 0)
02299     {
02300       ACE_OSCALL (ACE_ADAPT_RETVAL (::cv_wait (*cv, *external_mutex, 0),
02301                                     result),
02302                   int, -1, result);
02303     }
02304   else
02305     {
02306       // Need to convert the passed absolute time to relative time
02307       // expressed in ticks.
02308       ACE_Time_Value relative_time (*timeout - ACE_OS::gettimeofday ());
02309       int ticks = (relative_time.sec () * KC_TICKS2SEC) +
02310                   (relative_time.usec () * KC_TICKS2SEC /
02311                    ACE_ONE_SECOND_IN_USECS);
02312       if (ticks <= 0)
02313         ticks = 1;    // Don't wait forever
02314       ACE_OSCALL (ACE_ADAPT_RETVAL (::cv_wait (*cv, *external_mutex, ticks),
02315                                     result),
02316                   int, -1, result);
02317       if (result == -1 && errno == 1)
02318         {
02319           // cv timed out and returned pSOS timeout error 0x01, which
02320           // ACE_ADAPT_RETVAL stored in errno.
02321           ::mu_lock (*external_mutex, MU_WAIT, 0);
02322           errno = ETIME;
02323         }
02324     }
02325 
02326   return result;
02327 
02328 #   endif /* ACE_HAS_STHREADS */
02329   if (timeout != 0)
02330     timeout->set (ts); // Update the time value before returning.
02331 
02332   return result;
02333 # else
02334   ACE_UNUSED_ARG (cv);
02335   ACE_UNUSED_ARG (external_mutex);
02336   ACE_UNUSED_ARG (timeout);
02337   ACE_NOTSUP_RETURN (-1);
02338 # endif /* ACE_HAS_THREADS */
02339 }
02340 #endif /* !ACE_LACKS_COND_T */
02341 
02342 ACE_INLINE int
02343 ACE_OS::thr_equal (ACE_thread_t t1, ACE_thread_t t2)
02344 {
02345 #if defined (ACE_HAS_PTHREADS)
02346 # if defined (pthread_equal)
02347   // If it's a macro we can't say "::pthread_equal"...
02348   return pthread_equal (t1, t2);
02349 # else
02350   return ::pthread_equal (t1, t2);
02351 # endif /* pthread_equal */
02352 #elif defined (VXWORKS)
02353   return ! ACE_OS::strcmp (t1, t2);
02354 #else /* For both STHREADS and WTHREADS... */
02355   // Hum, Do we need to treat WTHREAD differently?
02356   // levine 13 oct 98 % I don't think so, ACE_thread_t is a DWORD.
02357   return t1 == t2;
02358 #endif /* ACE_HAS_PTHREADS */
02359 }
02360 
02361 ACE_INLINE void
02362 ACE_OS::thr_self (ACE_hthread_t &self)
02363 {
02364   ACE_OS_TRACE ("ACE_OS::thr_self");
02365 #if defined (ACE_HAS_THREADS)
02366 # if defined (ACE_HAS_PTHREADS)
02367   // Note, don't use "::" here since the following call is often a macro.
02368   self = pthread_self ();
02369 # elif defined (ACE_HAS_THREAD_SELF)
02370   self = ::thread_self ();
02371 # elif defined (ACE_HAS_STHREADS)
02372   self = ::thr_self ();
02373 # elif defined (ACE_HAS_WTHREADS)
02374   self = ::GetCurrentThread ();
02375 # elif defined (ACE_PSOS)
02376   t_ident ((char *) 0, 0, &self);
02377 # elif defined (VXWORKS)
02378   self = ::taskIdSelf ();
02379 # endif /* ACE_HAS_STHREADS */
02380 #else
02381   self = 1; // Might as well make it the main thread ;-)
02382 #endif /* ACE_HAS_THREADS */
02383 }
02384 
02385 ACE_INLINE ACE_thread_t
02386 ACE_OS::thr_self (void)
02387 {
02388   // ACE_OS_TRACE ("ACE_OS::thr_self");
02389 #if defined (ACE_HAS_THREADS)
02390 # if defined (ACE_HAS_PTHREADS)
02391   // Note, don't use "::" here since the following call is often a macro.
02392   ACE_OSCALL_RETURN (pthread_self (), int, -1);
02393 # elif defined (ACE_HAS_STHREADS)
02394   ACE_OSCALL_RETURN (::thr_self (), int, -1);
02395 # elif defined (ACE_HAS_WTHREADS)
02396   return ::GetCurrentThreadId ();
02397 # elif defined (ACE_PSOS)
02398   // there does not appear to be a way to get
02399   // a task's name other than at creation
02400   return 0;
02401 # elif defined (VXWORKS)
02402   return ::taskName (::taskIdSelf ());
02403 # endif /* ACE_HAS_STHREADS */
02404 #else
02405   return 1; // Might as well make it the first thread ;-)
02406 #endif /* ACE_HAS_THREADS */
02407 }
02408 
02409 ACE_INLINE int
02410 ACE_OS::recursive_mutex_init (ACE_recursive_thread_mutex_t *m,
02411                               const ACE_TCHAR *name,
02412                               ACE_mutexattr_t *arg,
02413                               LPSECURITY_ATTRIBUTES sa)
02414 {
02415   ACE_UNUSED_ARG (sa);
02416 #if defined (ACE_HAS_THREADS)
02417 #if defined (ACE_HAS_RECURSIVE_MUTEXES)
02418   return ACE_OS::thread_mutex_init (m, 0, name, arg);
02419 #else
02420   if (ACE_OS::thread_mutex_init (&m->nesting_mutex_, 0, name, arg) == -1)
02421     return -1;
02422   else if (ACE_OS::cond_init (&m->lock_available_,
02423                               (short) USYNC_THREAD,
02424                               name,
02425                               0) == -1)
02426     return -1;
02427   else
02428     {
02429       m->nesting_level_ = 0;
02430       m->owner_id_ = ACE_OS::NULL_thread;
02431       return 0;
02432     }
02433 #endif /* ACE_HAS_RECURSIVE_MUTEXES */
02434 #else
02435   ACE_UNUSED_ARG (m);
02436   ACE_UNUSED_ARG (name);
02437   ACE_UNUSED_ARG (arg);
02438   ACE_NOTSUP_RETURN (-1);
02439 #endif /* ACE_HAS_THREADS */
02440 }
02441 
02442 ACE_INLINE int
02443 ACE_OS::recursive_mutex_destroy (ACE_recursive_thread_mutex_t *m)
02444 {
02445 #if defined (ACE_HAS_THREADS)
02446 #if defined (ACE_HAS_RECURSIVE_MUTEXES)
02447   return ACE_OS::thread_mutex_destroy (m);
02448 #else
02449   if (ACE_OS::thread_mutex_destroy (&m->nesting_mutex_) == -1)
02450     return -1;
02451   else if (ACE_OS::cond_destroy (&m->lock_available_) == -1)
02452     return -1;
02453   else
02454     return 0;
02455 #endif /* ACE_HAS_RECURSIVE_MUTEXES */
02456 #else
02457   ACE_UNUSED_ARG (m);
02458   ACE_NOTSUP_RETURN (-1);
02459 #endif /* ACE_HAS_THREADS */
02460 }
02461 
02462 ACE_INLINE int
02463 ACE_OS::recursive_mutex_lock (ACE_recursive_thread_mutex_t *m)
02464 {
02465 #if defined (ACE_HAS_THREADS)
02466 #if defined (ACE_HAS_RECURSIVE_MUTEXES)
02467   return ACE_OS::thread_mutex_lock (m);
02468 #else
02469   ACE_thread_t t_id = ACE_OS::thr_self ();
02470   int result = 0;
02471 
02472   // Acquire the guard.
02473   if (ACE_OS::thread_mutex_lock (&m->nesting_mutex_) == -1)
02474     result = -1;
02475   else
02476     {
02477       // If there's no contention, just grab the lock immediately
02478       // (since this is the common case we'll optimize for it).
02479       if (m->nesting_level_ == 0)
02480         m->owner_id_ = t_id;
02481       // If we already own the lock, then increment the nesting level
02482       // and return.
02483       else if (ACE_OS::thr_equal (t_id, m->owner_id_) == 0)
02484         {
02485           // Wait until the nesting level has dropped to zero, at
02486           // which point we can acquire the lock.
02487           while (m->nesting_level_ > 0)
02488             ACE_OS::cond_wait (&m->lock_available_,
02489                                &m->nesting_mutex_);
02490 
02491           // At this point the nesting_mutex_ is held...
02492           m->owner_id_ = t_id;
02493         }
02494 
02495       // At this point, we can safely increment the nesting_level_ no
02496       // matter how we got here!
02497       m->nesting_level_++;
02498     }
02499 
02500   {
02501     // Save/restore errno.
02502     ACE_Errno_Guard error (errno);
02503     ACE_OS::thread_mutex_unlock (&m->nesting_mutex_);
02504   }
02505   return result;
02506 #endif /* ACE_HAS_RECURSIVE_MUTEXES */
02507 #else
02508   ACE_UNUSED_ARG (m);
02509   ACE_NOTSUP_RETURN (-1);
02510 #endif /* ACE_HAS_THREADS */
02511 }
02512 
02513 ACE_INLINE int
02514 ACE_OS::recursive_mutex_trylock (ACE_recursive_thread_mutex_t *m)
02515 {
02516 #if defined (ACE_HAS_THREADS)
02517 #if defined (ACE_HAS_RECURSIVE_MUTEXES)
02518   return ACE_OS::thread_mutex_trylock (m);
02519 #else
02520   ACE_thread_t t_id = ACE_OS::thr_self ();
02521   int result = 0;
02522 
02523   // Acquire the guard.
02524   if (ACE_OS::thread_mutex_lock (&m->nesting_mutex_) == -1)
02525     result = -1;
02526   else
02527     {
02528       // If there's no contention, just grab the lock immediately.
02529       if (m->nesting_level_ == 0)
02530         {
02531           m->owner_id_ = t_id;
02532           m->nesting_level_ = 1;
02533         }
02534       // If we already own the lock, then increment the nesting level
02535       // and proceed.
02536       else if (ACE_OS::thr_equal (t_id, m->owner_id_))
02537         m->nesting_level_++;
02538       else
02539         {
02540           errno = EBUSY;
02541           result = -1;
02542         }
02543     }
02544 
02545   {
02546     // Save/restore errno.
02547     ACE_Errno_Guard error (errno);
02548     ACE_OS::thread_mutex_unlock (&m->nesting_mutex_);
02549   }
02550   return result;
02551 #endif /* ACE_HAS_RECURSIVE_MUTEXES */
02552 #else
02553   ACE_UNUSED_ARG (m);
02554   ACE_NOTSUP_RETURN (-1);
02555 #endif /* ACE_HAS_THREADS */
02556 }
02557 
02558 ACE_INLINE int
02559 ACE_OS::recursive_mutex_unlock (ACE_recursive_thread_mutex_t *m)
02560 {
02561 #if defined (ACE_HAS_THREADS)
02562 #  if defined (ACE_HAS_RECURSIVE_MUTEXES)
02563   return ACE_OS::thread_mutex_unlock (m);
02564 #  else
02565   ACE_OS_TRACE ("ACE_OS::recursive_mutex_unlock");
02566 #    if !defined (ACE_NDEBUG)
02567   ACE_thread_t t_id = ACE_OS::thr_self ();
02568 #    endif /* ACE_NDEBUG */
02569   int result = 0;
02570 
02571   if (ACE_OS::thread_mutex_lock (&m->nesting_mutex_) == -1)
02572     result = -1;
02573   else
02574     {
02575 #    if !defined (ACE_NDEBUG)
02576       if (m->nesting_level_ == 0
02577           || ACE_OS::thr_equal (t_id, m->owner_id_) == 0)
02578         {
02579           errno = EINVAL;
02580           result = -1;
02581         }
02582       else
02583 #    endif /* ACE_NDEBUG */
02584         {
02585           m->nesting_level_--;
02586           if (m->nesting_level_ == 0)
02587             {
02588               // This may not be strictly necessary, but it does put
02589               // the mutex into a known state...
02590               m->owner_id_ = ACE_OS::NULL_thread;
02591 
02592               // Inform a waiter that the lock is free.
02593               if (ACE_OS::cond_signal (&m->lock_available_) == -1)
02594                 result = -1;
02595             }
02596         }
02597     }
02598 
02599   {
02600     // Save/restore errno.
02601     ACE_Errno_Guard error (errno);
02602     ACE_OS::thread_mutex_unlock (&m->nesting_mutex_);
02603   }
02604   return result;
02605 #  endif /* ACE_HAS_RECURSIVE_MUTEXES */
02606 #else
02607   ACE_UNUSED_ARG (m);
02608   ACE_NOTSUP_RETURN (-1);
02609 #endif /* ACE_HAS_THREADS */
02610 }
02611 
02612 // This method is used to prepare the recursive mutex for releasing
02613 // when waiting on a condition variable. If the platform doesn't have
02614 // native recursive mutex and condition variable support, then ACE needs
02615 // to save the recursion state around the wait and also ensure that the
02616 // wait and lock release are atomic. recursive_mutex_cond_relock()
02617 // is the inverse of this method.
02618 ACE_INLINE int
02619 ACE_OS::recursive_mutex_cond_unlock (ACE_recursive_thread_mutex_t *m,
02620                                      ACE_recursive_mutex_state &state)
02621 {
02622 #if defined (ACE_HAS_THREADS)
02623   ACE_OS_TRACE ("ACE_OS::recursive_mutex_cond_unlock");
02624 #  if defined (ACE_HAS_RECURSIVE_MUTEXES)
02625   // Windows need special handling since it has recursive mutexes, but
02626   // does not integrate them into a condition variable.
02627 #    if defined (ACE_WIN32)
02628   // For Windows, the OS takes care of the mutex and its recursion. We just
02629   // need to release the lock one fewer times than this thread has acquired
02630   // it. Remember how many times, and reacquire it that many more times when
02631   // the condition is signaled.
02632   state.relock_count_ = 0;
02633   while (m->LockCount > 0
02634 #      if !defined (ACE_HAS_WINCE)    /* WinCE doesn't have RecursionCount */
02635          && m->RecursionCount > 1
02636 #      endif
02637          )
02638     {
02639       // This may fail if the current thread doesn't own the mutex. If it
02640       // does fail, it'll be on the first try, so don't worry about resetting
02641       // the state.
02642       if (ACE_OS::recursive_mutex_unlock (m) == -1)
02643         return -1;
02644       ++state.relock_count_;
02645     }
02646 #    else /* not ACE_WIN32 */
02647     // prevent warnings for unused variables
02648     ACE_UNUSED_ARG (state);
02649     ACE_UNUSED_ARG (m);
02650 #    endif /* ACE_WIN32 */
02651   return 0;
02652 #  else /* ACE_HAS_RECURSIVE_MUTEXES */
02653   // For platforms without recursive mutexes, we obtain the nesting mutex
02654   // to gain control over the mutex internals. Then set the internals to say
02655   // the mutex is available. If there are waiters, signal the condition
02656   // to notify them (this is mostly like the recursive_mutex_unlock() method).
02657   // Then, return with the nesting mutex still held. The condition wait
02658   // will release it atomically, allowing mutex waiters to continue.
02659   // Note that this arrangement relies on the fact that on return from
02660   // the condition wait, this thread will again own the nesting mutex
02661   // and can either set the mutex internals directly or get in line for
02662   // the mutex... this part is handled in recursive_mutex_cond_relock().
02663   if (ACE_OS::thread_mutex_lock (&m->nesting_mutex_) == -1)
02664     return -1;
02665 
02666 #    if !defined (ACE_NDEBUG)
02667   if (m->nesting_level_ == 0
02668       || ACE_OS::thr_equal (ACE_OS::thr_self (), m->owner_id_) == 0)
02669     {
02670       ACE_OS::thread_mutex_unlock (&m->nesting_mutex_);
02671       errno = EINVAL;
02672       return -1;
02673     }
02674 #    endif /* ACE_NDEBUG */
02675 
02676   // To make error recovery a bit easier, signal the condition now. Any
02677   // waiter won't regain control until the mutex is released, which won't
02678   // be until the caller returns and does the wait on the condition.
02679   if (ACE_OS::cond_signal (&m->lock_available_) == -1)
02680     {
02681       // Save/restore errno.
02682       ACE_Errno_Guard error (errno);
02683       ACE_OS::thread_mutex_unlock (&m->nesting_mutex_);
02684       return -1;
02685     }
02686 
02687   // Ok, the nesting_mutex_ lock is still held, the condition has been
02688   // signaled... reset the nesting info and return _WITH_ the lock
02689   // held. The lock will be released when the condition waits, in the
02690   // caller.
02691   state.nesting_level_ = m->nesting_level_;
02692   state.owner_id_ = m->owner_id_;
02693   m->nesting_level_ = 0;
02694   m->owner_id_ = ACE_OS::NULL_thread;
02695   return 0;
02696 #  endif /* ACE_HAS_RECURSIVE_MUTEXES */
02697 #else
02698   ACE_UNUSED_ARG (m);
02699   ACE_UNUSED_ARG (state);
02700   ACE_NOTSUP_RETURN (-1);
02701 #endif /* ACE_HAS_THREADS */
02702 }
02703 
02704 
02705 // This method is called after waiting on a condition variable when a
02706 // recursive mutex must be reacquired. If the platform doesn't natively
02707 // integrate recursive mutexes and condition variables, it's taken care
02708 // of here (inverse of ACE_OS::recursive_mutex_cond_unlock).
02709 ACE_INLINE void
02710 ACE_OS::recursive_mutex_cond_relock (ACE_recursive_thread_mutex_t *m,
02711                                      ACE_recursive_mutex_state &state)
02712 {
02713 #if defined (ACE_HAS_THREADS)
02714   ACE_OS_TRACE ("ACE_OS::recursive_mutex_cond_relock");
02715 #  if defined (ACE_HAS_RECURSIVE_MUTEXES)
02716   // Windows need special handling since it has recursive mutexes, but
02717   // does not integrate them into a condition variable.
02718   // On entry, the OS has already reacquired the lock for us. Just
02719   // reacquire it the proper number of times so the recursion is the same as
02720   // before waiting on the condition.
02721 #    if defined (ACE_WIN32)
02722   while (state.relock_count_ > 0)
02723     {
02724       ACE_OS::recursive_mutex_lock (m);
02725       --state.relock_count_;
02726     }
02727   return;
02728 #    else /* not ACE_WIN32 */
02729     // prevent warnings for unused variables
02730     ACE_UNUSED_ARG (state);
02731     ACE_UNUSED_ARG (m);
02732 
02733 #    endif /* ACE_WIN32 */
02734 #  else
02735   // Without recursive mutex support, it's somewhat trickier. On entry,
02736   // the current thread holds the nesting_mutex_, but another thread may
02737   // still be holding the ACE_recursive_mutex_t. If so, mimic the code
02738   // in ACE_OS::recursive_mutex_lock that waits to acquire the mutex.
02739   // After acquiring it, restore the nesting counts and release the
02740   // nesting mutex. This will restore the conditions to what they were
02741   // before calling ACE_OS::recursive_mutex_cond_unlock().
02742   while (m->nesting_level_ > 0)
02743     ACE_OS::cond_wait (&m->lock_available_, &m->nesting_mutex_);
02744 
02745   // At this point, we still have nesting_mutex_ and the mutex is free.
02746   m->nesting_level_ = state.nesting_level_;
02747   m->owner_id_ = state.owner_id_;
02748   ACE_OS::thread_mutex_unlock (&m->nesting_mutex_);
02749   return;
02750 #  endif /* ACE_HAS_RECURSIVE_MUTEXES */
02751 #else
02752   ACE_UNUSED_ARG (m);
02753   ACE_UNUSED_ARG (state);
02754   return;
02755 #endif /* ACE_HAS_THREADS */
02756 }
02757 
02758 
02759 ACE_INLINE int
02760 ACE_OS::sema_destroy (ACE_sema_t *s)
02761 {
02762   ACE_OS_TRACE ("ACE_OS::sema_destroy");
02763 # if defined (ACE_HAS_POSIX_SEM)
02764   int result;
02765 #   if defined (ACE_LACKS_NAMED_POSIX_SEM)
02766   if (s->name_)
02767     {
02768       // Only destroy the semaphore if we're the ones who
02769       // initialized it.
02770       ACE_OSCALL (::sem_destroy (s->sema_),int, -1, result);
02771       ACE_OS::shm_unlink (s->name_);
02772       delete s->name_;
02773       return result;
02774     }
02775 #   else
02776   if (s->name_)
02777     {
02778       ACE_OSCALL (::sem_unlink (s->name_), int, -1, result);
02779       ACE_OS::free ((void *) s->name_);
02780       ACE_OSCALL_RETURN (::sem_close (s->sema_), int, -1);
02781     }
02782 #   endif /*  ACE_LACKS_NAMED_POSIX_SEM */
02783   else
02784     {
02785       ACE_OSCALL (::sem_destroy (s->sema_), int, -1, result);
02786 #   if defined (ACE_LACKS_NAMED_POSIX_SEM)
02787       if (s->new_sema_ != 0)
02788 #   endif /* ACE_LACKS_NAMED_POSIX_SEM */
02789         delete s->sema_;
02790       s->sema_ = 0;
02791       return result;
02792     }
02793 # elif defined (ACE_HAS_THREADS)
02794 #   if defined (ACE_HAS_STHREADS)
02795   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sema_destroy (s), ace_result_), int, -1);
02796 #   elif defined (ACE_HAS_PTHREADS)
02797   int r1 = ACE_OS::mutex_destroy (&s->lock_);
02798   int r2 = ACE_OS::cond_destroy (&s->count_nonzero_);
02799   return r1 != 0 || r2 != 0 ? -1 : 0;
02800 #   elif defined (ACE_HAS_WTHREADS)
02801 #     if !defined (ACE_USES_WINCE_SEMA_SIMULATION)
02802   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::CloseHandle (*s), ace_result_), int, -1);
02803 #     else /* ACE_USES_WINCE_SEMA_SIMULATION */
02804   // Free up underlying objects of the simulated semaphore.
02805   int r1 = ACE_OS::thread_mutex_destroy (&s->lock_);
02806   int r2 = ACE_OS::event_destroy (&s->count_nonzero_);
02807   return r1 != 0 || r2 != 0 ? -1 : 0;
02808 #     endif /* ACE_USES_WINCE_SEMA_SIMULATION */
02809 #   elif defined (ACE_PSOS)
02810   int result;
02811   ACE_OSCALL (ACE_ADAPT_RETVAL (::sm_delete (s->sema_), result), int, -1, result);
02812   s->sema_ = 0;
02813   return result;
02814 #   elif defined (VXWORKS)
02815   int result;
02816   ACE_OSCALL (::semDelete (s->sema_), int, -1, result);
02817   s->sema_ = 0;
02818   return result;
02819 #   endif /* ACE_HAS_STHREADS */
02820 # else
02821   ACE_UNUSED_ARG (s);
02822   ACE_NOTSUP_RETURN (-1);
02823 # endif /* ACE_HAS_POSIX_SEM */
02824 }
02825 
02826 // NOTE: The following four function definitions must appear before
02827 // ACE_OS::sema_init ().
02828 
02829 ACE_INLINE int
02830 ACE_OS::close (ACE_HANDLE handle)
02831 {
02832   ACE_OS_TRACE ("ACE_OS::close");
02833 #if defined (ACE_WIN32)
02834   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::CloseHandle (handle), ace_result_), int, -1);
02835 #elif defined (ACE_PSOS) && ! defined (ACE_PSOS_LACKS_PHILE)
02836   u_long result = ::close_f (handle);
02837   if (result != 0)
02838     {
02839       errno = result;
02840       return ACE_static_cast (int, -1);
02841     }
02842   return ACE_static_cast (int, 0);
02843 #else
02844   ACE_OSCALL_RETURN (::close (handle), int, -1);
02845 #endif /* ACE_WIN32 */
02846 }
02847 
02848 // This function returns the number of bytes in the file referenced by
02849 // FD.
02850 
02851 ACE_INLINE long
02852 ACE_OS::filesize (ACE_HANDLE handle)
02853 {
02854   ACE_OS_TRACE ("ACE_OS::filesize");
02855 #if defined (ACE_WIN32)
02856   ACE_WIN32CALL_RETURN (::GetFileSize (handle, 0), long, -1);
02857 #else /* !ACE_WIN32 */
02858   struct stat sb;
02859   return ACE_OS::fstat (handle, &sb) == -1 ? -1 : (long) sb.st_size;
02860 #endif /* ACE_WIN32 */
02861 }
02862 
02863 ACE_INLINE int
02864 ACE_OS::ftruncate (ACE_HANDLE handle, off_t offset)
02865 {
02866   ACE_OS_TRACE ("ACE_OS::ftruncate");
02867 #if defined (ACE_WIN32)
02868   if (::SetFilePointer (handle, offset, 0, FILE_BEGIN) != (unsigned) -1)
02869     ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::SetEndOfFile (handle), ace_result_), int, -1);
02870   else
02871     ACE_FAIL_RETURN (-1);
02872   /* NOTREACHED */
02873 #elif defined (ACE_PSOS_LACKS_PHILE)
02874   ACE_UNUSED_ARG (handle);
02875   ACE_UNUSED_ARG (offset);
02876   ACE_NOTSUP_RETURN (-1);
02877 #elif defined (ACE_PSOS)
02878   ACE_OSCALL_RETURN (::ftruncate_f (handle, offset), int, -1);
02879 #else
02880   ACE_OSCALL_RETURN (::ftruncate (handle, offset), int, -1);
02881 #endif /* ACE_WIN32 */
02882 }
02883 
02884 ACE_INLINE void *
02885 ACE_OS::mmap (void *addr,
02886               size_t len,
02887               int prot,
02888               int flags,
02889               ACE_HANDLE file_handle,
02890               off_t off,
02891               ACE_HANDLE *file_mapping,
02892               LPSECURITY_ATTRIBUTES sa,
02893               const ACE_TCHAR *file_mapping_name)
02894 {
02895   ACE_OS_TRACE ("ACE_OS::mmap");
02896 #if !defined (ACE_WIN32) || defined (ACE_HAS_PHARLAP)
02897   ACE_UNUSED_ARG (file_mapping_name);
02898 #endif /* !defined (ACE_WIN32) || defined (ACE_HAS_PHARLAP) */
02899 
02900 #if defined (ACE_WIN32) && !defined (ACE_HAS_PHARLAP)
02901 
02902 #  if defined(ACE_HAS_WINCE)
02903   ACE_UNUSED_ARG (addr);
02904   if (ACE_BIT_ENABLED (flags, MAP_FIXED))     // not supported
02905   {
02906     errno = EINVAL;
02907     return MAP_FAILED;
02908   }
02909 #  else
02910   if (!ACE_BIT_ENABLED (flags, MAP_FIXED))
02911     addr = 0;
02912   else if (addr == 0)   // can not map to address 0
02913   {
02914     errno = EINVAL;
02915     return MAP_FAILED;
02916   }
02917 #  endif
02918 
02919   int nt_flags = 0;
02920   ACE_HANDLE local_handle = ACE_INVALID_HANDLE;
02921 
02922   // Ensure that file_mapping is non-zero.
02923   if (file_mapping == 0)
02924     file_mapping = &local_handle;
02925 
02926   if (ACE_BIT_ENABLED (flags, MAP_PRIVATE))
02927     {
02928 #  if !defined(ACE_HAS_WINCE)
02929       prot = PAGE_WRITECOPY;
02930 #  endif  // ACE_HAS_WINCE
02931       nt_flags = FILE_MAP_COPY;
02932     }
02933   else if (ACE_BIT_ENABLED (flags, MAP_SHARED))
02934     {
02935       if (ACE_BIT_ENABLED (prot, PAGE_READONLY))
02936         nt_flags = FILE_MAP_READ;
02937       if (ACE_BIT_ENABLED (prot, PAGE_READWRITE))
02938         nt_flags = FILE_MAP_WRITE;
02939     }
02940 
02941   // Only create a new handle if we didn't have a valid one passed in.
02942   if (*file_mapping == ACE_INVALID_HANDLE)
02943     {
02944 #  if !defined(ACE_HAS_WINCE) && (!defined (ACE_HAS_WINNT4) || (ACE_HAS_WINNT4 == 0))
02945       int try_create = 1;
02946       if ((file_mapping_name != 0) && (*file_mapping_name != 0))
02947         {
02948           // On Win9x, we first try to OpenFileMapping to
02949           // file_mapping_name. Only if there is no mapping object
02950           // with that name, and the desired name is valid, do we try
02951           // CreateFileMapping.
02952 
02953           *file_mapping = ACE_TEXT_OpenFileMapping (nt_flags,
02954                                                     0,
02955                                                     file_mapping_name);
02956           if (*file_mapping != 0
02957               || (::GetLastError () == ERROR_INVALID_NAME
02958                   && ::GetLastError () == ERROR_FILE_NOT_FOUND))
02959             try_create = 0;
02960         }
02961 
02962       if (try_create)
02963 #  endif /* !ACE_HAS_WINCE && (ACE_HAS_WINNT4 || ACE_HAS_WINNT4 == 0) */
02964         {
02965           const LPSECURITY_ATTRIBUTES attr =
02966             ACE_OS::default_win32_security_attributes (sa);
02967 
02968           *file_mapping = ACE_TEXT_CreateFileMapping (file_handle,
02969                                                       attr,
02970                                                       prot,
02971                                                       0,
02972                                                       0,
02973                                                       file_mapping_name);
02974         }
02975     }
02976 
02977   if (*file_mapping == 0)
02978     ACE_FAIL_RETURN (MAP_FAILED);
02979 
02980 #  if defined (ACE_OS_EXTRA_MMAP_FLAGS)
02981   nt_flags |= ACE_OS_EXTRA_MMAP_FLAGS;
02982 #  endif /* ACE_OS_EXTRA_MMAP_FLAGS */
02983 
02984 #  if !defined (ACE_HAS_WINCE)
02985   void *addr_mapping = ::MapViewOfFileEx (*file_mapping,
02986                                           nt_flags,
02987                                           0,
02988                                           off,
02989                                           len,
02990                                           addr);
02991 #  else
02992   void *addr_mapping = ::MapViewOfFile (*file_mapping,
02993                                         nt_flags,
02994                                         0,
02995                                         off,
02996                                         len);
02997 #  endif /* ! ACE_HAS_WINCE */
02998 
02999   // Only close this down if we used the temporary.
03000   if (file_mapping == &local_handle)
03001     ::CloseHandle (*file_mapping);
03002 
03003   if (addr_mapping == 0)
03004     ACE_FAIL_RETURN (MAP_FAILED);
03005   else
03006     return addr_mapping;
03007 #elif defined (__Lynx__)
03008   // The LynxOS 2.5.0 mmap doesn't allow operations on plain
03009   // file descriptors.  So, create a shm object and use that.
03010   ACE_UNUSED_ARG (sa);
03011 
03012   char name [128];
03013   sprintf (name, "%d", file_handle);
03014 
03015   // Assumes that this was called by ACE_Mem_Map, so &file_mapping !=
03016   // 0.  Otherwise, we don't support the incomplete LynxOS mmap
03017   // implementation.  We do support it by creating a hidden shared
03018   // memory object, and using that for the mapping.
03019   int shm_handle;
03020   if (! file_mapping)
03021     file_mapping = &shm_handle;
03022   if ((*file_mapping = ::shm_open (name,
03023                                    O_RDWR | O_CREAT | O_TRUNC,
03024                                    ACE_DEFAULT_FILE_PERMS)) == -1)
03025     return MAP_FAILED;
03026   else
03027     {
03028       // The size of the shared memory object must be explicitly set on LynxOS.
03029       const off_t filesize = ACE_OS::filesize (file_handle);
03030       if (::ftruncate (*file_mapping, filesize) == -1)
03031         return MAP_FAILED;
03032       else
03033         {
03034 #  if defined (ACE_OS_EXTRA_MMAP_FLAGS)
03035           flags |= ACE_OS_EXTRA_MMAP_FLAGS;
03036 #  endif /* ACE_OS_EXTRA_MMAP_FLAGS */
03037           char *map = (char *) ::mmap ((ACE_MMAP_TYPE) addr,
03038                                        len,
03039                                        prot,
03040                                        flags,
03041                                        *file_mapping,
03042                                        off);
03043           if (map == MAP_FAILED)
03044             return MAP_FAILED;
03045           else
03046             // Finally, copy the file contents to the shared memory object.
03047             return ::read (file_handle, map, (int) filesize) == filesize
03048               ? map
03049               : MAP_FAILED;
03050         }
03051     }
03052 #elif !defined (ACE_LACKS_MMAP)
03053   ACE_UNUSED_ARG (sa);
03054 
03055 #  if defined (ACE_OS_EXTRA_MMAP_FLAGS)
03056   flags |= ACE_OS_EXTRA_MMAP_FLAGS;
03057 #  endif /* ACE_OS_EXTRA_MMAP_FLAGS */
03058   ACE_UNUSED_ARG (file_mapping);
03059   ACE_OSCALL_RETURN ((void *) ::mmap ((ACE_MMAP_TYPE) addr,
03060                                       len,
03061                                       prot,
03062                                       flags,
03063                                       file_handle,
03064                                       off),
03065                      void *, MAP_FAILED);
03066 #else
03067   ACE_UNUSED_ARG (addr);
03068   ACE_UNUSED_ARG (len);
03069   ACE_UNUSED_ARG (prot);
03070   ACE_UNUSED_ARG (flags);
03071   ACE_UNUSED_ARG (file_handle);
03072   ACE_UNUSED_ARG (off);
03073   ACE_UNUSED_ARG (file_mapping);
03074   ACE_UNUSED_ARG (sa);
03075   ACE_NOTSUP_RETURN (MAP_FAILED);
03076 #endif /* ACE_WIN32 && !ACE_HAS_PHARLAP */
03077 }
03078 
03079 // NOTE: The previous four function definitions must appear before
03080 // ACE_OS::sema_init ().
03081 
03082 ACE_INLINE int
03083 ACE_OS::sema_init (ACE_sema_t *s,
03084                    u_int count,
03085                    int type,
03086                    const char *name,
03087                    void *arg,
03088                    int max,
03089                    LPSECURITY_ATTRIBUTES sa)
03090 {
03091   ACE_OS_TRACE ("ACE_OS::sema_init");
03092 #if defined (ACE_HAS_POSIX_SEM)
03093   ACE_UNUSED_ARG (arg);
03094   ACE_UNUSED_ARG (max);
03095   ACE_UNUSED_ARG (sa);
03096 
03097   s->name_ = 0;
03098 
03099 #  if defined (ACE_LACKS_NAMED_POSIX_SEM)
03100   s->new_sema_ = 0;
03101   if (type == USYNC_PROCESS)
03102     {
03103       // Let's see if it already exists.
03104       ACE_HANDLE fd = ACE_OS::shm_open (name,
03105                                         O_RDWR | O_CREAT | O_EXCL,
03106                                         ACE_DEFAULT_FILE_PERMS);
03107       if (fd == ACE_INVALID_HANDLE)
03108         {
03109           if (errno == EEXIST)
03110             fd = ACE_OS::shm_open (name,
03111                                    O_RDWR | O_CREAT,
03112                                    ACE_DEFAULT_FILE_PERMS);
03113           else
03114             return -1;
03115         }
03116       else
03117         {
03118           // We own this shared memory object!  Let's set its
03119           // size.
03120           if (ACE_OS::ftruncate (fd,
03121                                  sizeof (ACE_sema_t)) == -1)
03122             return -1;
03123           s->name_ = ACE_OS::strdup (name);
03124           if (s->name_ == 0)
03125             return -1;
03126         }
03127       if (fd == -1)
03128         return -1;
03129 
03130       s->sema_ = (sem_t *)
03131         ACE_OS::mmap (0,
03132                       sizeof (ACE_sema_t),
03133                       PROT_RDWR,
03134                       MAP_SHARED,
03135                       fd,
03136                       0);
03137       ACE_OS::close (fd);
03138       if (s->sema_ == (sem_t *) MAP_FAILED)
03139         return -1;
03140       if (s->name_
03141           // @@ According UNIX Network Programming V2 by Stevens,
03142           //    sem_init() is currently not required to return zero on
03143           //    success, but it *does* return -1 upon failure.  For
03144           //    this reason, check for failure by comparing to -1,
03145           //    instead of checking for success by comparing to zero.
03146           //        -Ossama
03147           // Only initialize it if we're the one who created it.
03148           && ::sem_init (s->sema_, type == USYNC_PROCESS, count) == -1)
03149         return -1;
03150       return 0;
03151     }
03152 #  else
03153   if (name)
03154     {
03155 #    if defined (sun) || defined (HPUX)
03156       // Solaris and HP-UX require the name to start with a slash. Solaris
03157       // further requires that there be no other slashes than the first.
03158       const char *last_slash = ACE_OS::strrchr (name, '/');
03159       char name2[MAXPATHLEN];
03160       if (0 == last_slash)
03161         {
03162           ACE_OS::strcpy (name2, "/");
03163           ACE_OS::strcat (name2, name);
03164           name = name2;
03165         }
03166 #      if defined (sun)
03167       else
03168         name = last_slash;         // Chop off chars preceding last slash
03169 #      endif /* sun */
03170 #    endif /* sun || HPUX */
03171 
03172       ACE_ALLOCATOR_RETURN (s->name_,
03173                             ACE_OS::strdup (name),
03174                             -1);
03175       s->sema_ = ::sem_open (s->name_,
03176                              O_CREAT,
03177                              ACE_DEFAULT_FILE_PERMS,
03178                              count);
03179       if (s->sema_ == (sem_t *) SEM_FAILED)
03180         return -1;
03181       else
03182         return 0;
03183     }
03184 #  endif /* ACE_LACKS_NAMED_POSIX_SEM */
03185   else
03186     {
03187       ACE_NEW_RETURN (s->sema_,
03188                       sem_t,
03189                       -1);
03190 #  if defined (ACE_LACKS_NAMED_POSIX_SEM)
03191       s->new_sema_ = 1;
03192 #  endif /* ACE_LACKS_NAMED_POSIX_SEM */
03193       ACE_OSCALL_RETURN (::sem_init (s->sema_,
03194                                      type != USYNC_THREAD,
03195                                      count), int, -1);
03196     }
03197 #elif defined (ACE_HAS_THREADS)
03198 #  if defined (ACE_HAS_STHREADS)
03199   ACE_UNUSED_ARG (name);
03200   ACE_UNUSED_ARG (max);
03201   ACE_UNUSED_ARG (sa);
03202   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sema_init (s, count, type, arg), ace_result_),
03203                      int, -1);
03204 #  elif defined (ACE_HAS_PTHREADS)
03205   ACE_UNUSED_ARG (max);
03206   ACE_UNUSED_ARG (sa);
03207   int result = -1;
03208 
03209   if (ACE_OS::mutex_init (&s->lock_, type, name,
03210                           (ACE_mutexattr_t *) arg) == 0
03211       && ACE_OS::cond_init (&s->count_nonzero_, type, name, arg) == 0
03212       && ACE_OS::mutex_lock (&s->lock_) == 0)
03213     {
03214       s->count_ = count;
03215       s->waiters_ = 0;
03216 
03217       if (ACE_OS::mutex_unlock (&s->lock_) == 0)
03218         result = 0;
03219     }
03220 
03221   if (result == -1)
03222     {
03223       ACE_OS::mutex_destroy (&s->lock_);
03224       ACE_OS::cond_destroy (&s->count_nonzero_);
03225     }
03226   return result;
03227 #  elif defined (ACE_HAS_WTHREADS)
03228 #    if ! defined (ACE_USES_WINCE_SEMA_SIMULATION)
03229   ACE_UNUSED_ARG (type);
03230   ACE_UNUSED_ARG (arg);
03231   // Create the semaphore with its value initialized to <count> and
03232   // its maximum value initialized to <max>.
03233   *s =
03234     ::CreateSemaphoreA (ACE_OS::default_win32_security_attributes (sa),
03235                         count,
03236                         max,
03237                         name);
03238 
03239   if (*s == 0)
03240     ACE_FAIL_RETURN (-1);
03241   /* NOTREACHED */
03242   else
03243     return 0;
03244 #    else /* ACE_USES_WINCE_SEMA_SIMULATION */
03245   int result = -1;
03246 
03247   // Initialize internal object for semaphore simulation.
03248   // Grab the lock as soon as possible when we initializing
03249   // the semaphore count.  Notice that we initialize the
03250   // event object as "manually reset" so we can amortize the
03251   // cost for singling/reseting the event.
03252   // @@ I changed the mutex type to thread_mutex.  Notice that this
03253   // is basically a CriticalSection object and doesn't not has
03254   // any security attribute whatsoever.  However, since this
03255   // semaphore implementation only works within a process, there
03256   // shouldn't any security issue at all.
03257   if (ACE_OS::thread_mutex_init (&s->lock_, type, name, (ACE_mutexattr_t *)arg) == 0
03258       && ACE_OS::event_init (&s->count_nonzero_, 1,
03259                              count > 0, type, name, arg, sa) == 0
03260       && ACE_OS::thread_mutex_lock (&s->lock_) == 0)
03261     {
03262       s->count_ = count;
03263 
03264       if (ACE_OS::thread_mutex_unlock (&s->lock_) == 0)
03265         result = 0;
03266     }
03267 
03268   // Destroy the internal objects if we didn't initialize
03269   // either of them successfully.  Don't bother to check
03270   // for errors.
03271   if (result == -1)
03272     {
03273       ACE_OS::thread_mutex_destroy (&s->lock_);
03274       ACE_OS::event_destroy (&s->count_nonzero_);
03275     }
03276   return result;
03277 #    endif /* ACE_USES_WINCE_SEMA_SIMULATION */
03278 #  elif defined (ACE_PSOS)
03279   u_long result;
03280   ACE_OS::memcpy (s->name_, name, sizeof (s->name_));
03281   // default semaphore creation flags to priority based, global across nodes
03282   u_long flags = 0;
03283   flags |= (type & SM_LOCAL) ? SM_LOCAL : SM_GLOBAL;
03284   flags |= (type & SM_FIFO) ? SM_FIFO : SM_PRIOR;
03285   result = ::sm_create (s->name_, count, flags, &(s->sema_));
03286   return (result == 0) ? 0 : -1;
03287 #  elif defined (VXWORKS)
03288   ACE_UNUSED_ARG (name);
03289   ACE_UNUSED_ARG (arg);
03290   ACE_UNUSED_ARG (max);
03291   ACE_UNUSED_ARG (sa);
03292   s->name_ = 0;
03293   s->sema_ = ::semCCreate (type, count);
03294   return s->sema_ ? 0 : -1;
03295 #  endif /* ACE_HAS_STHREADS */
03296 #else
03297   ACE_UNUSED_ARG (s);
03298   ACE_UNUSED_ARG (count);
03299   ACE_UNUSED_ARG (type);
03300   ACE_UNUSED_ARG (name);
03301   ACE_UNUSED_ARG (arg);
03302   ACE_UNUSED_ARG (max);
03303   ACE_UNUSED_ARG (sa);
03304   ACE_NOTSUP_RETURN (-1);
03305 #endif /* ACE_HAS_POSIX_SEM */
03306 }
03307 
03308 #if defined (ACE_HAS_WCHAR)
03309 ACE_INLINE int
03310 ACE_OS::sema_init (ACE_sema_t *s,
03311                    u_int count,
03312                    int type,
03313                    const wchar_t *name,
03314                    void *arg,
03315                    int max,
03316                    LPSECURITY_ATTRIBUTES sa)
03317 {
03318 # if defined (ACE_HAS_WTHREADS)
03319 #   if ! defined (ACE_USES_WINCE_SEMA_SIMULATION)
03320   ACE_UNUSED_ARG (type);
03321   ACE_UNUSED_ARG (arg);
03322   // Create the semaphore with its value initialized to <count> and
03323   // its maximum value initialized to <max>.
03324   *s =
03325     ::CreateSemaphoreW (ACE_OS::default_win32_security_attributes (sa),
03326                         count,
03327                         max,
03328                         name);
03329 
03330   if (*s == 0)
03331     ACE_FAIL_RETURN (-1);
03332   /* NOTREACHED */
03333   else
03334     return 0;
03335 #   else /* ACE_USES_WINCE_SEMA_SIMULATION */
03336   int result = -1;
03337 
03338   // Initialize internal object for semaphore simulation.
03339   // Grab the lock as soon as possible when we initializing
03340   // the semaphore count.  Notice that we initialize the
03341   // event object as "manually reset" so we can amortize the
03342   // cost for singling/reseting the event.
03343   // @@ I changed the mutex type to thread_mutex.  Notice that this
03344   // is basically a CriticalSection object and doesn't not has
03345   // any security attribute whatsoever.  However, since this
03346   // semaphore implementation only works within a process, there
03347   // shouldn't any security issue at all.
03348   if (ACE_OS::thread_mutex_init (&s->lock_, type, name, (ACE_mutexattr_t *)arg) == 0
03349       && ACE_OS::event_init (&s->count_nonzero_, 1,
03350                              count > 0, type, name, arg, sa) == 0
03351       && ACE_OS::thread_mutex_lock (&s->lock_) == 0)
03352     {
03353       s->count_ = count;
03354 
03355       if (ACE_OS::thread_mutex_unlock (&s->lock_) == 0)
03356         result = 0;
03357     }
03358 
03359   // Destroy the internal objects if we didn't initialize
03360   // either of them successfully.  Don't bother to check
03361   // for errors.
03362   if (result == -1)
03363     {
03364       ACE_OS::thread_mutex_destroy (&s->lock_);
03365       ACE_OS::event_destroy (&s->count_nonzero_);
03366     }
03367   return result;
03368 #   endif /* ACE_USES_WINCE_SEMA_SIMULATION */
03369 # else /* ACE_HAS_WTHREADS */
03370   // Just call the normal char version.
03371   return ACE_OS::sema_init (s, count, type, ACE_Wide_To_Ascii (name).char_rep (), arg, max, sa);
03372 # endif /* ACE_HAS_WTHREADS */
03373 }
03374 #endif /* ACE_HAS_WCHAR */
03375 
03376 ACE_INLINE int
03377 ACE_OS::sema_post (ACE_sema_t *s)
03378 {
03379   ACE_OS_TRACE ("ACE_OS::sema_post");
03380 # if defined (ACE_HAS_POSIX_SEM)
03381   ACE_OSCALL_RETURN (::sem_post (s->sema_), int, -1);
03382 # elif defined (ACE_HAS_THREADS)
03383 #   if defined (ACE_HAS_STHREADS)
03384   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sema_post (s), ace_result_), int, -1);
03385 #   elif defined (ACE_HAS_PTHREADS)
03386   int result = -1;
03387 
03388   if (ACE_OS::mutex_lock (&s->lock_) == 0)
03389     {
03390       // Always allow a waiter to continue if there is one.
03391       if (s->waiters_ > 0)
03392         result = ACE_OS::cond_signal (&s->count_nonzero_);
03393       else
03394         result = 0;
03395 
03396       s->count_++;
03397       ACE_OS::mutex_unlock (&s->lock_);
03398     }
03399   return result;
03400 #   elif defined (ACE_HAS_WTHREADS)
03401 #     if !defined (ACE_USES_WINCE_SEMA_SIMULATION)
03402   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::ReleaseSemaphore (*s, 1, 0),
03403                                           ace_result_),
03404                         int, -1);
03405 #     else /* ACE_USES_WINCE_SEMA_SIMULATION */
03406   int result = -1;
03407 
03408   // Since we are simulating semaphores, we need to update semaphore
03409   // count manually.  Grab the lock to prevent race condition first.
03410   if (ACE_OS::thread_mutex_lock (&s->lock_) == 0)
03411     {
03412       // Check the original state of event object.  Single the event
03413       // object in transition from semaphore not available to
03414       // semaphore available.
03415       if (s->count_++ <= 0)
03416         result = ACE_OS::event_signal (&s->count_nonzero_);
03417       else
03418         result = 0;
03419 
03420       ACE_OS::thread_mutex_unlock (&s->lock_);
03421     }
03422   return result;
03423 #     endif /* ACE_USES_WINCE_SEMA_SIMULATION */
03424 #   elif defined (ACE_PSOS)
03425   int result;
03426   ACE_OSCALL (ACE_ADAPT_RETVAL (::sm_v (s->sema_), result), int, -1, result);
03427   return result;
03428 #   elif defined (VXWORKS)
03429   ACE_OSCALL_RETURN (::semGive (s->sema_), int, -1);
03430 #   endif /* ACE_HAS_STHREADS */
03431 # else
03432   ACE_UNUSED_ARG (s);
03433   ACE_NOTSUP_RETURN (-1);
03434 # endif /* ACE_HAS_POSIX_SEM */
03435 }
03436 
03437 ACE_INLINE int
03438 ACE_OS::sema_post (ACE_sema_t *s, u_int release_count)
03439 {
03440 #if defined (ACE_WIN32) && !defined (ACE_USES_WINCE_SEMA_SIMULATION)
03441   // Win32 supports this natively.
03442   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::ReleaseSemaphore (*s, release_count, 0),
03443                                           ace_result_), int, -1);
03444 #else
03445   // On POSIX platforms we need to emulate this ourselves.
03446   // @@ We can optimize on this implementation.  However,
03447   // the semaphore promitive on Win32 doesn't allow one
03448   // to increase a semaphore to more than the count it was
03449   // first initialized.  Posix and solaris don't seem to have
03450   // this restriction.  Should we impose the restriction in
03451   // our semaphore simulation?
03452   for (size_t i = 0; i < release_count; i++)
03453     if (ACE_OS::sema_post (s) == -1)
03454       return -1;
03455 
03456   return 0;
03457 #endif /* ACE_WIN32 */
03458 }
03459 
03460 ACE_INLINE int
03461 ACE_OS::sema_trywait (ACE_sema_t *s)
03462 {
03463   ACE_OS_TRACE ("ACE_OS::sema_trywait");
03464 # if defined (ACE_HAS_POSIX_SEM)
03465   // POSIX semaphores set errno to EAGAIN if trywait fails
03466   ACE_OSCALL_RETURN (::sem_trywait (s->sema_), int, -1);
03467 # elif defined (ACE_HAS_THREADS)
03468 #   if defined (ACE_HAS_STHREADS)
03469   // STHREADS semaphores set errno to EBUSY if trywait fails.
03470   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sema_trywait (s),
03471                                        ace_result_),
03472                      int, -1);
03473 #   elif defined (ACE_HAS_PTHREADS)
03474 
03475   int result = -1;
03476 
03477   if (ACE_OS::mutex_lock (&s->lock_) == 0)
03478     {
03479       if (s->count_ > 0)
03480         {
03481           --s->count_;
03482           result = 0;
03483         }
03484       else
03485         errno = EBUSY;
03486 
03487       ACE_OS::mutex_unlock (&s->lock_);
03488     }
03489   return result;
03490 #   elif defined (ACE_HAS_WTHREADS)
03491 #     if !defined (ACE_USES_WINCE_SEMA_SIMULATION)
03492   int result = ::WaitForSingleObject (*s, 0);
03493 
03494   if (result == WAIT_OBJECT_0)
03495     return 0;
03496   else
03497     {
03498       if (result == WAIT_TIMEOUT)
03499         errno = EBUSY;
03500       else
03501         ACE_OS::set_errno_to_last_error ();
03502       // This is a hack, we need to find an appropriate mapping...
03503       return -1;
03504     }
03505 #     else /* ACE_USES_WINCE_SEMA_SIMULATION */
03506   // Check the status of semaphore first.  Return immediately
03507   // if the semaphore is not available and avoid grabing the
03508   // lock.
03509   int result = ::WaitForSingleObject (s->count_nonzero_, 0);
03510 
03511   if (result == WAIT_OBJECT_0)  // Proceed when it is available.
03512     {
03513       ACE_OS::thread_mutex_lock (&s->lock_);
03514 
03515       // Need to double check if the semaphore is still available.
03516       // The double checking scheme will slightly affect the
03517       // efficiency if most of the time semaphores are not blocked.
03518       result = ::WaitForSingleObject (s->count_nonzero_, 0);
03519       if (result == WAIT_OBJECT_0)
03520         {
03521           // Adjust the semaphore count.  Only update the event
03522           // object status when the state changed.
03523           s->count_--;
03524           if (s->count_ <= 0)
03525             ACE_OS::event_reset (&s->count_nonzero_);
03526           result = 0;
03527         }
03528 
03529       ACE_OS::thread_mutex_unlock (&s->lock_);
03530     }
03531 
03532   // Translate error message to errno used by ACE.
03533   if (result == WAIT_TIMEOUT)
03534     errno = EBUSY;
03535   else
03536     ACE_OS::set_errno_to_last_error ();
03537   // This is taken from the hack above. ;)
03538   return -1;
03539 #     endif /* ACE_USES_WINCE_SEMA_SIMULATION */
03540 #   elif defined (ACE_PSOS)
03541    switch (::sm_p (s->sema_, SM_NOWAIT, 0))
03542    {
03543      case 0:
03544        return 0;
03545      case ERR_NOSEM:
03546        errno = EBUSY;
03547        // intentional fall through
03548      default:
03549        return -1;
03550    }
03551 #   elif defined (VXWORKS)
03552   if (::semTake (s->sema_, NO_WAIT) == ERROR)
03553     if (errno == S_objLib_OBJ_UNAVAILABLE)
03554       {
03555         // couldn't get the semaphore
03556         errno = EBUSY;
03557         return -1;
03558       }
03559     else
03560       // error
03561       return -1;
03562   else
03563     // got the semaphore
03564     return 0;
03565 #   endif /* ACE_HAS_STHREADS */
03566 # else
03567   ACE_UNUSED_ARG (s);
03568   ACE_NOTSUP_RETURN (-1);
03569 # endif /* ACE_HAS_POSIX_SEM */
03570 }
03571 
03572 ACE_INLINE int
03573 ACE_OS::sema_wait (ACE_sema_t *s)
03574 {
03575   ACE_OS_TRACE ("ACE_OS::sema_wait");
03576 # if defined (ACE_HAS_POSIX_SEM)
03577   ACE_OSCALL_RETURN (::sem_wait (s->sema_), int, -1);
03578 # elif defined (ACE_HAS_THREADS)
03579 #   if defined (ACE_HAS_STHREADS)
03580   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sema_wait (s), ace_result_), int, -1);
03581 #   elif defined (ACE_HAS_PTHREADS)
03582   int result = 0;
03583 
03584   ACE_PTHREAD_CLEANUP_PUSH (&s->lock_);
03585 
03586   if (ACE_OS::mutex_lock (&s->lock_) != 0)
03587     result = -1;
03588   else
03589     {
03590       // Keep track of the number of waiters so that we can signal
03591       // them properly in <ACE_OS::sema_post>.
03592       s->waiters_++;
03593 
03594       // Wait until the semaphore count is > 0.
03595       while (s->count_ == 0)
03596         if (ACE_OS::cond_wait (&s->count_nonzero_,
03597                                &s->lock_) == -1)
03598           {
03599             result = -2; // -2 means that we need to release the mutex.
03600             break;
03601           }
03602 
03603       --s->waiters_;
03604     }
03605 
03606   if (result == 0)
03607     --s->count_;
03608 
03609   if (result != -1)
03610     ACE_OS::mutex_unlock (&s->lock_);
03611   ACE_PTHREAD_CLEANUP_POP (0);
03612   return result < 0 ? -1 : result;
03613 
03614 #   elif defined (ACE_HAS_WTHREADS)
03615 #     if !defined (ACE_USES_WINCE_SEMA_SIMULATION)
03616   switch (::WaitForSingleObject (*s, INFINITE))
03617     {
03618     case WAIT_OBJECT_0:
03619       return 0;
03620     default:
03621       // This is a hack, we need to find an appropriate mapping...
03622       ACE_OS::set_errno_to_last_error ();
03623       return -1;
03624     }
03625   /* NOTREACHED */
03626 #     else /* ACE_USES_WINCE_SEMA_SIMULATION */
03627   // Timed wait.
03628   int result = -1;
03629   for (;;)
03630     // Check if the semaphore is avialable or not and wait forever.
03631     // Don't bother to grab the lock if it is not available (to avoid
03632     // deadlock.)
03633     switch (::WaitForSingleObject (s->count_nonzero_, INFINITE))
03634       {
03635       case WAIT_OBJECT_0:
03636         ACE_OS::thread_mutex_lock (&s->lock_);
03637 
03638         // Need to double check if the semaphore is still available.
03639         // This time, we shouldn't wait at all.
03640         if (::WaitForSingleObject (s->count_nonzero_, 0) == WAIT_OBJECT_0)
03641           {
03642             // Decrease the internal counter.  Only update the event
03643             // object's status when the state changed.
03644             s->count_--;
03645             if (s->count_ <= 0)
03646               ACE_OS::event_reset (&s->count_nonzero_);
03647             result = 0;
03648           }
03649 
03650         ACE_OS::thread_mutex_unlock (&s->lock_);
03651         // if we didn't get a hold on the semaphore, the result won't
03652         // be 0 and thus, we'll start from the beginning again.
03653         if (result == 0)
03654           return 0;
03655         break;
03656 
03657       default:
03658         // Since we wait indefinitely, anything other than
03659         // WAIT_OBJECT_O indicates an error.
03660         ACE_OS::set_errno_to_last_error ();
03661         // This is taken from the hack above. ;)
03662         return -1;
03663       }
03664   /* NOTREACHED */
03665 #     endif /* ACE_USES_WINCE_SEMA_SIMULATION */
03666 #   elif defined (ACE_PSOS)
03667   int result;
03668   ACE_OSCALL (ACE_ADAPT_RETVAL (::sm_p (s->sema_, SM_WAIT, 0), result),
03669                                 int, -1, result);
03670   return result;
03671 #   elif defined (VXWORKS)
03672   ACE_OSCALL_RETURN (::semTake (s->sema_, WAIT_FOREVER), int, -1);
03673 #   endif /* ACE_HAS_STHREADS */
03674 # else
03675   ACE_UNUSED_ARG (s);
03676   ACE_NOTSUP_RETURN (-1);
03677 # endif /* ACE_HAS_POSIX_SEM */
03678 }
03679 
03680 ACE_INLINE int
03681 ACE_OS::sema_wait (ACE_sema_t *s, ACE_Time_Value &tv)
03682 {
03683   ACE_OS_TRACE ("ACE_OS::sema_wait");
03684 # if defined (ACE_HAS_POSIX_SEM)
03685   ACE_UNUSED_ARG (s);
03686   ACE_UNUSED_ARG (tv);
03687   ACE_NOTSUP_RETURN (-1);
03688 # elif defined (ACE_HAS_THREADS)
03689 #   if defined (ACE_HAS_STHREADS)
03690   ACE_UNUSED_ARG (s);
03691   ACE_UNUSED_ARG (tv);
03692   ACE_NOTSUP_RETURN (-1);
03693 #   elif defined (ACE_HAS_PTHREADS)
03694   int result = 0;
03695   ACE_Errno_Guard error (errno);
03696 
03697   ACE_PTHREAD_CLEANUP_PUSH (&s->lock_);
03698 
03699   if (ACE_OS::mutex_lock (&s->lock_) != 0)
03700     result = -1;
03701   else
03702     {
03703       // Keep track of the number of waiters so that we can signal
03704       // them properly in <ACE_OS::sema_post>.
03705       s->waiters_++;
03706 
03707       // Wait until the semaphore count is > 0 or until we time out.
03708       while (s->count_ == 0)
03709         if (ACE_OS::cond_timedwait (&s->count_nonzero_,
03710                                     &s->lock_,
03711                                     &tv) == -1)
03712           {
03713             error = errno;
03714             result = -2; // -2 means that we need to release the mutex.
03715             break;
03716           }
03717 
03718       --s->waiters_;
03719     }
03720 
03721   if (result == 0)
03722     {
03723 #     if defined (ACE_LACKS_COND_TIMEDWAIT_RESET)
03724       tv = ACE_OS::gettimeofday ();
03725 #     endif /* ACE_LACKS_COND_TIMEDWAIT_RESET */
03726       --s->count_;
03727     }
03728 
03729   if (result != -1)
03730     ACE_OS::mutex_unlock (&s->lock_);
03731   ACE_PTHREAD_CLEANUP_POP (0);
03732   return result < 0 ? -1 : result;
03733 #   elif defined (ACE_HAS_WTHREADS)
03734 #     if !defined (ACE_USES_WINCE_SEMA_SIMULATION)
03735   int msec_timeout;
03736 
03737   if (tv.sec () == 0 && tv.usec () == 0)
03738     msec_timeout = 0; // Do a "poll."
03739   else
03740     {
03741       // Note that we must convert between absolute time (which is
03742       // passed as a parameter) and relative time (which is what
03743       // <WaitForSingleObjects> expects).
03744       ACE_Time_Value relative_time (tv - ACE_OS::gettimeofday ());
03745 
03746       // Watchout for situations where a context switch has caused the
03747       // current time to be > the timeout.
03748       if (relative_time < ACE_Time_Value::zero)
03749         msec_timeout = 0;
03750       else
03751         msec_timeout = relative_time.msec ();
03752     }
03753 
03754   switch (::WaitForSingleObject (*s, msec_timeout))
03755     {
03756     case WAIT_OBJECT_0:
03757       tv = ACE_OS::gettimeofday ();     // Update time to when acquired
03758       return 0;
03759     case WAIT_TIMEOUT:
03760       errno = ETIME;
03761       return -1;
03762     default:
03763       // This is a hack, we need to find an appropriate mapping...
03764       ACE_OS::set_errno_to_last_error ();
03765       return -1;
03766     }
03767   /* NOTREACHED */
03768 #     else /* ACE_USES_WINCE_SEMA_SIMULATION */
03769   // Note that in this mode, the acquire is done in two steps, and
03770   // we may get signaled but cannot grab the semaphore before
03771   // timeout.  In that case, we'll need to restart the process with
03772   // updated timeout value.
03773 
03774   // <tv> is an absolute time
03775   ACE_Time_Value relative_time = tv - ACE_OS::gettimeofday ();
03776   int result = -1;
03777 
03778   // While we are not timeout yet.
03779   while (relative_time > ACE_Time_Value::zero)
03780     {
03781       // Wait for our turn to get the object.
03782       switch (::WaitForSingleObject (s->count_nonzero_, relative_time.msec ()))
03783         {
03784         case WAIT_OBJECT_0:
03785           ACE_OS::thread_mutex_lock (&s->lock_);
03786 
03787           // Need to double check if the semaphore is still available.
03788           // We can only do a "try lock" styled wait here to avoid
03789           // blocking threads that want to signal the semaphore.
03790           if (::WaitForSingleObject (s->count_nonzero_, 0) == WAIT_OBJECT_0)
03791             {
03792               // As before, only reset the object when the semaphore
03793               // is no longer available.
03794               s->count_--;
03795               if (s->count_ <= 0)
03796                 ACE_OS::event_reset (&s->count_nonzero_);
03797               result = 0;
03798             }
03799 
03800           ACE_OS::thread_mutex_unlock (&s->lock_);
03801 
03802           // Only return when we successfully get the semaphore.
03803           if (result == 0)
03804             {
03805               tv = ACE_OS::gettimeofday ();     // Update to time acquired
03806               return 0;
03807             }
03808           break;
03809 
03810           // We have timed out.
03811         case WAIT_TIMEOUT:
03812           errno = ETIME;
03813           return -1;
03814 
03815           // What?
03816         default:
03817           ACE_OS::set_errno_to_last_error ();
03818           // This is taken from the hack above. ;)
03819           return -1;
03820         };
03821 
03822       // Haven't been able to get the semaphore yet, update the
03823       // timeout value to reflect the remaining time we want to wait.
03824       relative_time = tv - ACE_OS::gettimeofday ();
03825     }
03826 
03827   // We have timed out.
03828   errno = ETIME;
03829   return -1;
03830 #     endif /* ACE_USES_WINCE_SEMA_SIMULATION */
03831 #   elif defined (ACE_PSOS)
03832   // Note that we must convert between absolute time (which is
03833   // passed as a parameter) and relative time (which is what
03834   // the system call expects).
03835   ACE_Time_Value relative_time (tv - ACE_OS::gettimeofday ());
03836 
03837   u_long ticks = relative_time.sec() * KC_TICKS2SEC +
03838                  relative_time.usec () * KC_TICKS2SEC /
03839                    ACE_ONE_SECOND_IN_USECS;
03840   if(ticks == 0)
03841     ACE_OSCALL_RETURN (::sm_p (s->sema_, SM_NOWAIT, 0), int, -1); //no timeout
03842   else
03843     ACE_OSCALL_RETURN (::sm_p (s->sema_, SM_WAIT, ticks), int, -1);
03844 #   elif defined (VXWORKS)
03845   // Note that we must convert between absolute time (which is
03846   // passed as a parameter) and relative time (which is what
03847   // the system call expects).
03848   ACE_Time_Value relative_time (tv - ACE_OS::gettimeofday ());
03849 
03850   int ticks_per_sec = ::sysClkRateGet ();
03851 
03852   int ticks = relative_time.sec() * ticks_per_sec +
03853               relative_time.usec () * ticks_per_sec / ACE_ONE_SECOND_IN_USECS;
03854   if (::semTake (s->sema_, ticks) == ERROR)
03855     {
03856       if (errno == S_objLib_OBJ_TIMEOUT)
03857         // Convert the VxWorks errno to one that's common for to ACE
03858         // platforms.
03859         errno = ETIME;
03860       else if (errno == S_objLib_OBJ_UNAVAILABLE)
03861         errno = EBUSY;
03862       return -1;
03863     }
03864   else
03865     {
03866       tv = ACE_OS::gettimeofday ();  // Update to time acquired
03867       return 0;
03868     }
03869 #   endif /* ACE_HAS_STHREADS */
03870 # else
03871   ACE_UNUSED_ARG (s);
03872   ACE_UNUSED_ARG (tv);
03873   ACE_NOTSUP_RETURN (-1);
03874 # endif /* ACE_HAS_POSIX_SEM */
03875 }
03876 
03877 ACE_INLINE int
03878 ACE_OS::sema_wait (ACE_sema_t *s, ACE_Time_Value *tv)
03879 {
03880   return tv == 0 ? ACE_OS::sema_wait (s) : ACE_OS::sema_wait (s, *tv);
03881 }
03882 
03883 ACE_INLINE int
03884 ACE_OS::rw_tryrdlock (ACE_rwlock_t *rw)
03885 {
03886   ACE_OS_TRACE ("ACE_OS::rw_tryrdlock");
03887 #if defined (ACE_HAS_THREADS)
03888 # if !defined (ACE_LACKS_RWLOCK_T) || defined (ACE_HAS_PTHREADS_UNIX98_EXT)
03889 #  if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
03890   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_rwlock_tryrdlock (rw),
03891                                        ace_result_),
03892                      int, -1);
03893 #  else /* Solaris */
03894   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::rw_tryrdlock (rw), ace_result_), int, -1);
03895 #  endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
03896 # else /* NT, POSIX, and VxWorks don't support this natively. */
03897   int result = -1;
03898 
03899   if (ACE_OS::mutex_lock (&rw->lock_) != -1)
03900     {
03901       ACE_Errno_Guard error (errno);
03902 
03903       if (rw->ref_count_ == -1 || rw->num_waiting_writers_ > 0)
03904         {
03905           error = EBUSY;
03906           result = -1;
03907         }
03908       else
03909         {
03910           rw->ref_count_++;
03911           result = 0;
03912         }
03913 
03914       ACE_OS::mutex_unlock (&rw->lock_);
03915     }
03916   return result;
03917 # endif /* ! ACE_LACKS_RWLOCK_T */
03918 #else
03919   ACE_UNUSED_ARG (rw);
03920   ACE_NOTSUP_RETURN (-1);
03921 #endif /* ACE_HAS_THREADS */
03922 }
03923 
03924 ACE_INLINE int
03925 ACE_OS::rw_trywrlock (ACE_rwlock_t *rw)
03926 {
03927   ACE_OS_TRACE ("ACE_OS::rw_trywrlock");
03928 #if defined (ACE_HAS_THREADS)
03929 # if !defined (ACE_LACKS_RWLOCK_T) || defined (ACE_HAS_PTHREADS_UNIX98_EXT)
03930 #  if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
03931   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_rwlock_trywrlock (rw),
03932                                        ace_result_),
03933                      int, -1);
03934 #  else /* Solaris */
03935   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::rw_trywrlock (rw), ace_result_), int, -1);
03936 #  endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
03937 # else /* NT, POSIX, and VxWorks don't support this natively. */
03938   int result = -1;
03939 
03940   if (ACE_OS::mutex_lock (&rw->lock_) != -1)
03941     {
03942       ACE_Errno_Guard error (errno);
03943 
03944       if (rw->ref_count_ != 0)
03945         {
03946           error = EBUSY;
03947           result = -1;
03948         }
03949       else
03950         {
03951           rw->ref_count_ = -1;
03952           result = 0;
03953         }
03954 
03955       ACE_OS::mutex_unlock (&rw->lock_);
03956     }
03957   return result;
03958 # endif /* ! ACE_LACKS_RWLOCK_T */
03959 #else
03960   ACE_UNUSED_ARG (rw);
03961   ACE_NOTSUP_RETURN (-1);
03962 #endif /* ACE_HAS_THREADS */
03963 }
03964 
03965 ACE_INLINE int
03966 ACE_OS::rw_rdlock (ACE_rwlock_t *rw)
03967 {
03968   ACE_OS_TRACE ("ACE_OS::rw_rdlock");
03969 #if defined (ACE_HAS_THREADS)
03970 # if !defined (ACE_LACKS_RWLOCK_T) || defined (ACE_HAS_PTHREADS_UNIX98_EXT)
03971 #  if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
03972   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_rwlock_rdlock (rw),
03973                                        ace_result_),
03974                      int, -1);
03975 #  else /* Solaris */
03976   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::rw_rdlock (rw), ace_result_), int, -1);
03977 #  endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
03978 # else /* NT, POSIX, and VxWorks don't support this natively. */
03979 #   if defined (ACE_HAS_PTHREADS)
03980   ACE_PTHREAD_CLEANUP_PUSH (&rw->lock_);
03981 #   endif /* ACE_HAS_PTHREADS */
03982   int result = 0;
03983   if (ACE_OS::mutex_lock (&rw->lock_) == -1)
03984     result = -1; // -1 means didn't get the mutex.
03985   else
03986     {
03987       // Give preference to writers who are waiting.
03988       while (rw->ref_count_ < 0 || rw->num_waiting_writers_ > 0)
03989         {
03990           rw->num_waiting_readers_++;
03991           if (ACE_OS::cond_wait (&rw->waiting_readers_, &rw->lock_) == -1)
03992             {
03993               result = -2; // -2 means that we need to release the mutex.
03994               break;
03995             }
03996           rw->num_waiting_readers_--;
03997         }
03998     }
03999   if (result == 0)
04000     rw->ref_count_++;
04001   if (result != -1)
04002     ACE_OS::mutex_unlock (&rw->lock_);
04003 #   if defined (ACE_HAS_PTHREADS)
04004   ACE_PTHREAD_CLEANUP_POP (0);
04005 #   endif /* defined (ACE_HAS_PTHREADS) */
04006   return 0;
04007 # endif /* ! ACE_LACKS_RWLOCK_T */
04008 #else
04009   ACE_UNUSED_ARG (rw);
04010   ACE_NOTSUP_RETURN (-1);
04011 #endif /* ACE_HAS_THREADS */
04012 }
04013 
04014 ACE_INLINE int
04015 ACE_OS::rw_wrlock (ACE_rwlock_t *rw)
04016 {
04017   ACE_OS_TRACE ("ACE_OS::rw_wrlock");
04018 #if defined (ACE_HAS_THREADS)
04019 # if !defined (ACE_LACKS_RWLOCK_T) || defined (ACE_HAS_PTHREADS_UNIX98_EXT)
04020 #  if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
04021   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_rwlock_wrlock (rw),
04022                                        ace_result_),
04023                      int, -1);
04024 #  else /* Solaris */
04025   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::rw_wrlock (rw), ace_result_), int, -1);
04026 #  endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
04027 # else /* NT, POSIX, and VxWorks don't support this natively. */
04028 #   if defined (ACE_HAS_PTHREADS)
04029   ACE_PTHREAD_CLEANUP_PUSH (&rw->lock_);
04030 #   endif /* defined (ACE_HAS_PTHREADS) */
04031   int result = 0;
04032 
04033   if (ACE_OS::mutex_lock (&rw->lock_) == -1)
04034     result = -1; // -1 means didn't get the mutex.
04035   else
04036     {
04037       while (rw->ref_count_ != 0)
04038         {
04039           rw->num_waiting_writers_++;
04040 
04041           if (ACE_OS::cond_wait (&rw->waiting_writers_, &rw->lock_) == -1)
04042             {
04043               result = -2; // -2 means we need to release the mutex.
04044               break;
04045             }
04046 
04047           rw->num_waiting_writers_--;
04048         }
04049     }
04050   if (result == 0)
04051     rw->ref_count_ = -1;
04052   if (result != -1)
04053     ACE_OS::mutex_unlock (&rw->lock_);
04054 #   if defined (ACE_HAS_PTHREADS)
04055   ACE_PTHREAD_CLEANUP_POP (0);
04056 #   endif /* defined (ACE_HAS_PTHREADS) */
04057   return 0;
04058 # endif /* ! ACE_LACKS_RWLOCK_T */
04059 #else
04060   ACE_UNUSED_ARG (rw);
04061   ACE_NOTSUP_RETURN (-1);
04062 #endif /* ACE_HAS_THREADS */
04063 }
04064 
04065 ACE_INLINE int
04066 ACE_OS::rw_unlock (ACE_rwlock_t *rw)
04067 {
04068   ACE_OS_TRACE ("ACE_OS::rw_unlock");
04069 #if defined (ACE_HAS_THREADS)
04070 # if !defined (ACE_LACKS_RWLOCK_T) || defined (ACE_HAS_PTHREADS_UNIX98_EXT)
04071 #  if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
04072   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_rwlock_unlock (rw),
04073                                        ace_result_),
04074                      int, -1);
04075 #  else /* Solaris */
04076   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::rw_unlock (rw), ace_result_), int, -1);
04077 #  endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
04078 # else /* NT, POSIX, and VxWorks don't support this natively. */
04079   if (ACE_OS::mutex_lock (&rw->lock_) == -1)
04080     return -1;
04081 
04082   if (rw->ref_count_ > 0) // Releasing a reader.
04083     rw->ref_count_--;
04084   else if (rw->ref_count_ == -1) // Releasing a writer.
04085     rw->ref_count_ = 0;
04086   else
04087     return -1; // @@ ACE_ASSERT (!"count should not be 0!\n");
04088 
04089 
04090   int result = 0;
04091   ACE_Errno_Guard error (errno);
04092 
04093   if (rw->important_writer_ && rw->ref_count_ == 1)
04094     // only the reader requesting to upgrade its lock is left over.
04095     {
04096       result = ACE_OS::cond_signal (&rw->waiting_important_writer_);
04097       error = errno;
04098     }
04099   else if (rw->num_waiting_writers_ > 0 && rw->ref_count_ == 0)
04100     // give preference to writers over readers...
04101     {
04102       result = ACE_OS::cond_signal (&rw->waiting_writers_);
04103       error =  errno;
04104     }
04105   else if (rw->num_waiting_readers_ > 0 && rw->num_waiting_writers_ == 0)
04106     {
04107       result = ACE_OS::cond_broadcast (&rw->waiting_readers_);
04108       error = errno;
04109     }
04110 
04111   ACE_OS::mutex_unlock (&rw->lock_);
04112   return result;
04113 # endif /* ! ace_lacks_rwlock_t */
04114 #else
04115   ACE_UNUSED_ARG (rw);
04116   ACE_NOTSUP_RETURN (-1);
04117 #endif /* ace_has_threads */
04118 }
04119 
04120 // Note that the caller of this method *must* already possess this
04121 // lock as a read lock.
04122 // return {-1 and no errno set means: error,
04123 //         -1 and errno==EBUSY set means: could not upgrade,
04124 //         0 means: upgraded successfully}
04125 
04126 ACE_INLINE int
04127 ACE_OS::rw_trywrlock_upgrade (ACE_rwlock_t *rw)
04128 {
04129   ACE_OS_TRACE ("ACE_OS::rw_trywrlock_upgrade");
04130 #if defined (ACE_HAS_THREADS)
04131 # if !defined (ACE_LACKS_RWLOCK_T)
04132   // Some native rwlocks, such as those on Solaris and HP-UX 11, don't
04133   // support the upgrade feature . . .
04134   ACE_UNUSED_ARG (rw);
04135   ACE_NOTSUP_RETURN (-1);
04136 # else /* NT, POSIX, and VxWorks don't support this natively. */
04137   // The ACE rwlock emulation does support upgrade . . .
04138   int result = 0;
04139 
04140 #   if defined (ACE_HAS_PTHREADS)
04141   ACE_PTHREAD_CLEANUP_PUSH (&rw->lock_);
04142 #   endif /* defined (ACE_HAS_PTHREADS) */
04143 
04144   if (ACE_OS::mutex_lock (&rw->lock_) == -1)
04145     return -1;
04146     // -1 means didn't get the mutex, error
04147   else if (rw->important_writer_)
04148     // an other reader upgrades already
04149     {
04150       result = -1;
04151       errno = EBUSY;
04152     }
04153   else
04154     {
04155       while (rw->ref_count_ > 1) // wait until only I am left
04156         {
04157           rw->num_waiting_writers_++; // prohibit any more readers
04158           rw->important_writer_ = 1;
04159 
04160           if (ACE_OS::cond_wait (&rw->waiting_important_writer_, &rw->lock_) == -1)
04161             {
04162               result = -1;
04163               // we know that we have the lock again, we have this guarantee,
04164               // but something went wrong
04165             }
04166           rw->important_writer_ = 0;
04167           rw->num_waiting_writers_--;
04168         }
04169       if (result == 0)
04170         {
04171           // nothing bad happend
04172           rw->ref_count_ = -1;
04173           // now I am a writer
04174           // everything is O.K.
04175         }
04176     }
04177 
04178   ACE_OS::mutex_unlock (&rw->lock_);
04179 
04180 #   if defined (ACE_HAS_PTHREADS)
04181   ACE_PTHREAD_CLEANUP_POP (0);
04182 #   endif /* defined (ACE_HAS_PTHREADS) */
04183 
04184   return result;
04185 
04186 # endif /* ! ACE_LACKS_RWLOCK_T */
04187 #else
04188   ACE_UNUSED_ARG (rw);
04189   ACE_NOTSUP_RETURN (-1);
04190 #endif /* ACE_HAS_THREADS */
04191 }
04192 
04193 #if defined (ACE_HAS_THREADS) && (!defined (ACE_LACKS_RWLOCK_T) || \
04194                                    defined (ACE_HAS_PTHREADS_UNIX98_EXT))
04195 ACE_INLINE int
04196 ACE_OS::rwlock_init (ACE_rwlock_t *rw,
04197                      int type,
04198                      const ACE_TCHAR *name,
04199                      void *arg)
04200 {
04201   // ACE_OS_TRACE ("ACE_OS::rwlock_init");
04202 #  if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
04203   ACE_UNUSED_ARG (name);
04204   ACE_UNUSED_ARG (arg);
04205 
04206   int status;
04207   pthread_rwlockattr_t attr;
04208   pthread_rwlockattr_init (&attr);
04209   pthread_rwlockattr_setpshared (&attr, (type == USYNC_THREAD ?
04210                                          PTHREAD_PROCESS_PRIVATE :
04211                                          PTHREAD_PROCESS_SHARED));
04212   status = ACE_ADAPT_RETVAL (pthread_rwlock_init (rw, &attr), status);
04213   pthread_rwlockattr_destroy (&attr);
04214 
04215   return status;
04216 
04217 #  else
04218   type = type;
04219   name = name;
04220   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::rwlock_init (rw, type, arg), ace_result_), int, -1);
04221 #  endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
04222 }
04223 #endif /* ACE_HAS THREADS && !defined (ACE_LACKS_RWLOCK_T) */
04224 
04225 ACE_INLINE int
04226 ACE_OS::rwlock_destroy (ACE_rwlock_t *rw)
04227 {
04228   ACE_OS_TRACE ("ACE_OS::rwlock_destroy");
04229 #if defined (ACE_HAS_THREADS)
04230 # if !defined (ACE_LACKS_RWLOCK_T) || defined (ACE_HAS_PTHREADS_UNIX98_EXT)
04231 #  if defined (ACE_HAS_PTHREADS_UNIX98_EXT)
04232   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_rwlock_destroy (rw),
04233                                        ace_result_),
04234                      int, -1);
04235 #  else /* Solaris */
04236   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::rwlock_destroy (rw), ace_result_), int, -1);
04237 #  endif /* ACE_HAS_PTHREADS_UNIX98_EXT */
04238 # else /* NT, POSIX, and VxWorks don't support this natively. */
04239   ACE_OS::mutex_destroy (&rw->lock_);
04240   ACE_OS::cond_destroy (&rw->waiting_readers_);
04241   ACE_OS::cond_destroy (&rw->waiting_important_writer_);
04242   return ACE_OS::cond_destroy (&rw->waiting_writers_);
04243 # endif /* ACE_HAS_STHREADS && !defined (ACE_LACKS_RWLOCK_T) */
04244 #else
04245   ACE_UNUSED_ARG (rw);
04246   ACE_NOTSUP_RETURN (-1);
04247 #endif /* ACE_HAS_THREADS */
04248 }
04249 
04250 ACE_INLINE int
04251 ACE_OS::event_init (ACE_event_t *event,
04252                     int manual_reset,
04253                     int initial_state,
04254                     int type,
04255                     const char *name,
04256                     void *arg,
04257                     LPSECURITY_ATTRIBUTES sa)
04258 {
04259 #if defined (ACE_WIN32)
04260   ACE_UNUSED_ARG (type);
04261   ACE_UNUSED_ARG (arg);
04262 # if defined (ACE_HAS_WINCE)
04263   // @@todo (brunsch) This idea should be moved into ACE_OS_Win32.
04264   *event = ::CreateEventW (ACE_OS::default_win32_security_attributes(sa),
04265                            manual_reset,
04266                            initial_state,
04267                            ACE_Ascii_To_Wide (name).wchar_rep ());
04268 # else /* ACE_HAS_WINCE */
04269   *event = ::CreateEventA (ACE_OS::default_win32_security_attributes(sa),
04270                            manual_reset,
04271                            initial_state,
04272                            name);
04273 # endif /* ACE_HAS_WINCE */
04274   if (*event == 0)
04275     ACE_FAIL_RETURN (-1);
04276   else
04277     return 0;
04278 #elif defined (ACE_HAS_THREADS)
04279   ACE_UNUSED_ARG (sa);
04280   event->manual_reset_ = manual_reset;
04281   event->is_signaled_ = initial_state;
04282   event->waiting_threads_ = 0;
04283 
04284   int result = ACE_OS::cond_init (&event->condition_,
04285                                   ACE_static_cast (short, type),
04286                                   name,
04287                                   arg);
04288   if (result == 0)
04289     result = ACE_OS::mutex_init (&event->lock_,
04290                                  type,
04291                                  name,
04292                                  (ACE_mutexattr_t *) arg);
04293   return result;
04294 #else
04295   ACE_UNUSED_ARG (event);
04296   ACE_UNUSED_ARG (manual_reset);
04297   ACE_UNUSED_ARG (initial_state);
04298   ACE_UNUSED_ARG (type);
04299   ACE_UNUSED_ARG (name);
04300   ACE_UNUSED_ARG (arg);
04301   ACE_UNUSED_ARG (sa);
04302   ACE_NOTSUP_RETURN (-1);
04303 #endif /* ACE_WIN32 */
04304 }
04305 
04306 #if defined (ACE_HAS_WCHAR)
04307 ACE_INLINE int
04308 ACE_OS::event_init (ACE_event_t *event,
04309                     int manual_reset,
04310                     int initial_state,
04311                     int type,
04312                     const wchar_t *name,
04313                     void *arg,
04314                     LPSECURITY_ATTRIBUTES sa)
04315 {
04316 #if defined (ACE_WIN32)
04317   ACE_UNUSED_ARG (type);
04318   ACE_UNUSED_ARG (arg);
04319   *event = ::CreateEventW (ACE_OS::default_win32_security_attributes(sa),
04320                            manual_reset,
04321                            initial_state,
04322                            name);
04323   if (*event == 0)
04324     ACE_FAIL_RETURN (-1);
04325 
04326   return 0;
04327 #else  /* ACE_WIN32 */
04328   return ACE_OS::event_init (event,
04329                              manual_reset,
04330                              initial_state,
04331                              type,
04332                              ACE_Wide_To_Ascii (name).char_rep (),
04333                              arg,
04334                              sa);
04335 #endif /* ACE_WIN32 */
04336 }
04337 #endif /* ACE_HAS_WCHAR */
04338 
04339 ACE_INLINE int
04340 ACE_OS::event_destroy (ACE_event_t *event)
04341 {
04342 #if defined (ACE_WIN32)
04343   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::CloseHandle (*event), ace_result_), int, -1);
04344 #elif defined (ACE_HAS_THREADS)
04345   int r1 = ACE_OS::mutex_destroy (&event->lock_);
04346   int r2 = ACE_OS::cond_destroy (&event->condition_);
04347   return r1 != 0 || r2 != 0 ? -1 : 0;
04348 #else
04349   ACE_UNUSED_ARG (event);
04350   ACE_NOTSUP_RETURN (-1);
04351 #endif /* ACE_WIN32 */
04352 }
04353 
04354 ACE_INLINE int
04355 ACE_OS::event_wait (ACE_event_t *event)
04356 {
04357 #if defined (ACE_WIN32)
04358   switch (::WaitForSingleObject (*event, INFINITE))
04359     {
04360     case WAIT_OBJECT_0:
04361       return 0;
04362     default:
04363       ACE_OS::set_errno_to_last_error ();
04364       return -1;
04365     }
04366 #elif defined (ACE_HAS_THREADS)
04367   int result = 0;
04368   int error = 0;
04369 
04370   // grab the lock first
04371   if (ACE_OS::mutex_lock (&event->lock_) == 0)
04372     {
04373       if (event->is_signaled_ == 1)
04374         // Event is currently signaled.
04375         {
04376           if (event->manual_reset_ == 0)
04377             // AUTO: reset state
04378             event->is_signaled_ = 0;
04379         }
04380       else
04381         // event is currently not signaled
04382         {
04383           event->waiting_threads_++;
04384 
04385           if (ACE_OS::cond_wait (&event->condition_,
04386                                  &event->lock_) != 0)
04387             {
04388               result = -1;
04389               error = errno;
04390               // Something went wrong...
04391             }
04392 
04393           event->waiting_threads_--;
04394         }
04395 
04396       // Now we can let go of the lock.
04397       ACE_OS::mutex_unlock (&event->lock_);
04398 
04399       if (result == -1)
04400         // Reset errno in case mutex_unlock() also fails...
04401         errno = error;
04402     }
04403   else
04404     result = -1;
04405   return result;
04406 #else
04407   ACE_UNUSED_ARG (event);
04408   ACE_NOTSUP_RETURN (-1);
04409 #endif /* ACE_WIN32 */
04410 }
04411 
04412 ACE_INLINE int
04413 ACE_OS::event_timedwait (ACE_event_t *event,
04414                          ACE_Time_Value *timeout,
04415                          int use_absolute_time)
04416 {
04417 #if defined (ACE_WIN32)
04418   DWORD result;
04419 
04420   if (timeout == 0)
04421     // Wait forever
04422     result = ::WaitForSingleObject (*event, INFINITE);
04423   else if (timeout->sec () == 0 && timeout->usec () == 0)
04424     // Do a "poll".
04425     result = ::WaitForSingleObject (*event, 0);
04426   else
04427     {
04428       // Wait for upto <relative_time> number of milliseconds.  Note
04429       // that we must convert between absolute time (which is passed
04430       // as a parameter) and relative time (which is what
04431       // WaitForSingleObjects() expects).
04432       // <timeout> parameter is given in absolute or relative value
04433       // depending on parameter <use_absolute_time>.
04434       int msec_timeout;
04435       if (use_absolute_time)
04436         {
04437           // Time is given in absolute time, we should use
04438           // gettimeofday() to calculate relative time
04439           ACE_Time_Value relative_time (*timeout - ACE_OS::gettimeofday ());
04440 
04441           // Watchout for situations where a context switch has caused
04442           // the current time to be > the timeout.  Thanks to Norbert
04443           // Rapp <NRapp@nexus-informatics.de> for pointing this.
04444           if (relative_time < ACE_Time_Value::zero)
04445             msec_timeout = 0;
04446           else
04447             msec_timeout = relative_time.msec ();
04448         }
04449        else
04450          // time is given in relative time, just convert it into
04451          // milliseconds and use it
04452          msec_timeout = timeout->msec ();
04453       result = ::WaitForSingleObject (*event, msec_timeout);
04454     }
04455 
04456   switch (result)
04457     {
04458     case WAIT_OBJECT_0:
04459       return 0;
04460     case WAIT_TIMEOUT:
04461       errno = ETIME;
04462       return -1;
04463     default:
04464       // This is a hack, we need to find an appropriate mapping...
04465       ACE_OS::set_errno_to_last_error ();
04466       return -1;
04467     }
04468 #elif defined (ACE_HAS_THREADS)
04469   int result = 0;
04470   int error = 0;
04471 
04472   // grab the lock first
04473   if (ACE_OS::mutex_lock (&event->lock_) == 0)
04474     {
04475       if (event->is_signaled_ == 1)
04476         // event is currently signaled
04477         {
04478           if (event->manual_reset_ == 0)
04479             // AUTO: reset state
04480             event->is_signaled_ = 0;
04481         }
04482       else
04483         // event is currently not signaled
04484         {
04485           event->waiting_threads_++;
04486 
04487           // cond_timewait() expects absolute time, check
04488           // <use_absolute_time> flag.
04489           if (use_absolute_time == 0 && timeout != 0)
04490             *timeout += ACE_OS::gettimeofday ();
04491 
04492           if (ACE_OS::cond_timedwait (&event->condition_,
04493                                       &event->lock_,
04494                                       timeout) != 0)
04495             {
04496               result = -1;
04497               error = errno;
04498             }
04499 
04500           event->waiting_threads_--;
04501         }
04502 
04503       // Now we can let go of the lock.
04504       ACE_OS::mutex_unlock (&event->lock_);
04505 
04506       if (result == -1)
04507         // Reset errno in case mutex_unlock() also fails...
04508         errno = error;
04509     }
04510   else
04511     result = -1;
04512   return result;
04513 #else
04514   ACE_UNUSED_ARG (event);
04515   ACE_UNUSED_ARG (timeout);
04516   ACE_UNUSED_ARG (use_absolute_time);
04517   ACE_NOTSUP_RETURN (-1);
04518 #endif /* ACE_WIN32 */
04519 }
04520 
04521 ACE_INLINE int
04522 ACE_OS::event_signal (ACE_event_t *event)
04523 {
04524 #if defined (ACE_WIN32)
04525   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::SetEvent (*event), ace_result_), int, -1);
04526 #elif defined (ACE_HAS_THREADS)
04527   int result = 0;
04528   int error = 0;
04529 
04530   // grab the lock first
04531   if (ACE_OS::mutex_lock (&event->lock_) == 0)
04532     {
04533       // Manual-reset event.
04534       if (event->manual_reset_ == 1)
04535         {
04536           // signal event
04537           event->is_signaled_ = 1;
04538           // wakeup all
04539           if (ACE_OS::cond_broadcast (&event->condition_) != 0)
04540             {
04541               result = -1;
04542               error = errno;
04543             }
04544         }
04545       // Auto-reset event
04546       else
04547         {
04548           if (event->waiting_threads_ == 0)
04549             // No waiters: signal event.
04550             event->is_signaled_ = 1;
04551 
04552           // Waiters: wakeup one waiter.
04553           else if (ACE_OS::cond_signal (&event->condition_) != 0)
04554             {
04555               result = -1;
04556               error = errno;
04557             }
04558         }
04559 
04560       // Now we can let go of the lock.
04561       ACE_OS::mutex_unlock (&event->lock_);
04562 
04563       if (result == -1)
04564         // Reset errno in case mutex_unlock() also fails...
04565         errno = error;
04566     }
04567   else
04568     result = -1;
04569   return result;
04570 #else
04571   ACE_UNUSED_ARG (event);
04572   ACE_NOTSUP_RETURN (-1);
04573 #endif /* ACE_WIN32 */
04574 }
04575 
04576 ACE_INLINE int
04577 ACE_OS::event_pulse (ACE_event_t *event)
04578 {
04579 #if defined (ACE_WIN32)
04580   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::PulseEvent (*event), ace_result_), int, -1);
04581 #elif defined (ACE_HAS_THREADS)
04582   int result = 0;
04583   int error = 0;
04584 
04585   // grab the lock first
04586   if (ACE_OS::mutex_lock (&event->lock_) == 0)
04587     {
04588       // Manual-reset event.
04589       if (event->manual_reset_ == 1)
04590         {
04591           // Wakeup all waiters.
04592           if (ACE_OS::cond_broadcast (&event->condition_) != 0)
04593             {
04594               result = -1;
04595               error = errno;
04596             }
04597         }
04598       // Auto-reset event: wakeup one waiter.
04599       else if (ACE_OS::cond_signal (&event->condition_) != 0)
04600         {
04601           result = -1;
04602           error = errno;
04603         }
04604 
04605       // Reset event.
04606       event->is_signaled_ = 0;
04607 
04608       // Now we can let go of the lock.
04609       ACE_OS::mutex_unlock (&event->lock_);
04610 
04611       if (result == -1)
04612         // Reset errno in case mutex_unlock() also fails...
04613         errno = error;
04614     }
04615   else
04616     result = -1;
04617   return result;
04618 #else
04619   ACE_UNUSED_ARG (event);
04620   ACE_NOTSUP_RETURN (-1);
04621 #endif /* ACE_WIN32 */
04622 }
04623 
04624 ACE_INLINE int
04625 ACE_OS::event_reset (ACE_event_t *event)
04626 {
04627 #if defined (ACE_WIN32)
04628   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::ResetEvent (*event), ace_result_), int, -1);
04629 #elif defined (ACE_HAS_THREADS)
04630   int result = 0;
04631 
04632   // Grab the lock first.
04633   if (ACE_OS::mutex_lock (&event->lock_) == 0)
04634     {
04635       // Reset event.
04636       event->is_signaled_ = 0;
04637 
04638       // Now we can let go of the lock.
04639       ACE_OS::mutex_unlock (&event->lock_);
04640     }
04641   else
04642     result = -1;
04643   return result;
04644 #else
04645   ACE_UNUSED_ARG (event);
04646   ACE_NOTSUP_RETURN (-1);
04647 #endif /* ACE_WIN32 */
04648 }
04649 
04650 #if defined (ACE_WIN32)
04651 # define ACE_SOCKCALL_RETURN(OP,TYPE,FAILVALUE) \
04652   do { TYPE ace_result_ = (TYPE) OP; \
04653       if (ace_result_ == FAILVALUE) { int ___ = ::WSAGetLastError (); errno = ___; return (TYPE) FAILVALUE; } else return ace_result_; \
04654   } while (0)
04655 #else
04656 # define ACE_SOCKCALL_RETURN(OP,TYPE,FAILVALUE) ACE_OSCALL_RETURN(OP,TYPE,FAILVALUE)
04657 #endif /* ACE_WIN32 */
04658 
04659 #if defined (ACE_LACKS_NETDB_REENTRANT_FUNCTIONS)
04660 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
04661 #   define ACE_NETDBCALL_RETURN(OP,TYPE,FAILVALUE,TARGET,SIZE) \
04662   do \
04663   { \
04664     if (ACE_OS::netdb_acquire ())  \
04665       return FAILVALUE; \
04666     else \
04667       { \
04668         TYPE ace_result_; \
04669         ACE_OSCALL (OP, TYPE, FAILVALUE, ace_result_); \
04670         if (ace_result_ != FAILVALUE) \
04671           ::memcpy (TARGET, \
04672                     ace_result_, \
04673                     SIZE < sizeof (TYPE) ? SIZE : sizeof (TYPE)); \
04674         ACE_OS::netdb_release (); \
04675         return ace_result_; \
04676       } \
04677   } while(0)
04678 # else /* ! (ACE_MT_SAFE && ACE_MT_SAFE != 0) */
04679 #   define ACE_NETDBCALL_RETURN(OP,TYPE,FAILVALUE,TARGET,SIZE) \
04680   do \
04681   { \
04682         TYPE ace_result_; \
04683         ACE_OSCALL(OP,TYPE,FAILVALUE,ace_result_); \
04684         if (ace_result_ != FAILVALUE) \
04685           ::memcpy (TARGET, \
04686                     ace_result_, \
04687                     SIZE < sizeof (TYPE) ? SIZE : sizeof (TYPE)); \
04688         return ace_result_; \
04689   } while(0)
04690 # endif /* ACE_MT_SAFE && ACE_MT_SAFE != 0 */
04691 #endif /* ACE_LACKS_NETDB_REENTRANT_FUNCTIONS */
04692 
04693 ACE_INLINE ACE_HANDLE
04694 ACE_OS::accept (ACE_HANDLE handle,
04695                 struct sockaddr *addr,
04696                 int *addrlen)
04697 {
04698   ACE_OS_TRACE ("ACE_OS::accept");
04699 #if defined (ACE_PSOS)
04700 #  if !defined (ACE_PSOS_DIAB_PPC)
04701   ACE_SOCKCALL_RETURN (::accept ((ACE_SOCKET) handle,
04702                                  (struct sockaddr_in *) addr,
04703                                  (ACE_SOCKET_LEN *) addrlen),
04704                        ACE_HANDLE,
04705                        ACE_INVALID_HANDLE);
04706 #  else
04707 ACE_SOCKCALL_RETURN (::accept ((ACE_SOCKET) handle,
04708                                (struct sockaddr *) addr,
04709                                (ACE_SOCKET_LEN *) addrlen),
04710                      ACE_HANDLE,
04711                      ACE_INVALID_HANDLE);
04712 #  endif /* defined ACE_PSOS_DIAB_PPC */
04713 #else
04714   // On a non-blocking socket with no connections to accept, this
04715   // system call will return EWOULDBLOCK or EAGAIN, depending on the
04716   // platform.  UNIX 98 allows either errno, and they may be the same
04717   // numeric value.  So to make life easier for upper ACE layers as
04718   // well as application programmers, always change EAGAIN to
04719   // EWOULDBLOCK.  Rather than hack the ACE_OSCALL_RETURN macro, it's
04720   // handled explicitly here.  If the ACE_OSCALL macro ever changes,
04721   // this function needs to be reviewed.  On Win32, the regular macros
04722   // can be used, as this is not an issue.
04723 
04724 #  if defined (ACE_WIN32)
04725   ACE_SOCKCALL_RETURN (::accept ((ACE_SOCKET) handle,
04726                                  addr,
04727                                  (ACE_SOCKET_LEN *) addrlen),
04728                        ACE_HANDLE,
04729                        ACE_INVALID_HANDLE);
04730 #  else
04731 #    if defined (ACE_HAS_BROKEN_ACCEPT_ADDR)
04732   // Apparently some platforms like VxWorks can't correctly deal with
04733   // a NULL addr.
04734 
04735    sockaddr_in fake_addr;
04736    int fake_addrlen;
04737 
04738    if (addrlen == 0)
04739      addrlen = &fake_addrlen;
04740 
04741    if (addr == 0)
04742      {
04743        addr = (sockaddr *) &fake_addr;
04744        *addrlen = sizeof fake_addr;
04745      }
04746 #    endif /* VXWORKS */
04747   ACE_HANDLE ace_result = ::accept ((ACE_SOCKET) handle,
04748                                     addr,
04749                                     (ACE_SOCKET_LEN *) addrlen) ;
04750   if (ace_result == ACE_INVALID_HANDLE && errno == EAGAIN)
04751     errno = EWOULDBLOCK;
04752   return ace_result;
04753 
04754 #  endif /* defined (ACE_WIN32) */
04755 #endif /* defined (ACE_PSOS) */
04756 }
04757 
04758 ACE_INLINE int
04759 ACE_OS::enum_protocols (int *protocols,
04760                         ACE_Protocol_Info *protocol_buffer,
04761                         u_long *buffer_length)
04762 {
04763 #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
04764 
04765   ACE_SOCKCALL_RETURN (::WSAEnumProtocols (protocols,
04766                                            protocol_buffer,
04767                                            buffer_length),
04768                        int,
04769                        SOCKET_ERROR);
04770 
04771 #else
04772   ACE_UNUSED_ARG (protocols);
04773   ACE_UNUSED_ARG (protocol_buffer);
04774   ACE_UNUSED_ARG (buffer_length);
04775   ACE_NOTSUP_RETURN (-1);
04776 #endif /* ACE_HAS_WINSOCK2 */
04777 }
04778 
04779 
04780 ACE_INLINE int
04781 ACE_OS::bind (ACE_HANDLE handle, struct sockaddr *addr, int addrlen)
04782 {
04783   ACE_OS_TRACE ("ACE_OS::bind");
04784 #if defined (ACE_PSOS) && !defined (ACE_PSOS_DIAB_PPC)
04785   ACE_SOCKCALL_RETURN (::bind ((ACE_SOCKET) handle,
04786                                (struct sockaddr_in *) addr,
04787                                (ACE_SOCKET_LEN) addrlen),
04788                        int, -1);
04789 #else /* !defined (ACE_PSOS) || defined (ACE_PSOS_DIAB_PPC) */
04790   ACE_SOCKCALL_RETURN (::bind ((ACE_SOCKET) handle,
04791                                addr,
04792                                (ACE_SOCKET_LEN) addrlen), int, -1);
04793 #endif /* defined (ACE_PSOS) && !defined (ACE_PSOS_DIAB_PPC) */
04794 }
04795 
04796 ACE_INLINE int
04797 ACE_OS::connect (ACE_HANDLE handle,
04798                  struct sockaddr *addr,
04799                  int addrlen)
04800 {
04801   ACE_OS_TRACE ("ACE_OS::connect");
04802 #if defined (ACE_PSOS) && !defined (ACE_PSOS_DIAB_PPC)
04803   ACE_SOCKCALL_RETURN (::connect ((ACE_SOCKET) handle,
04804                                   (struct sockaddr_in *) addr,
04805                                   (ACE_SOCKET_LEN) addrlen),
04806                        int, -1);
04807 #else  /* !defined (ACE_PSOS) || defined (ACE_PSOS_DIAB_PPC) */
04808   ACE_SOCKCALL_RETURN (::connect ((ACE_SOCKET) handle,
04809                                   addr,
04810                                   (ACE_SOCKET_LEN) addrlen), int, -1);
04811 #endif /* defined (ACE_PSOS)  && !defined (ACE_PSOS_DIAB_PPC) */
04812 }
04813 
04814 #if !defined (VXWORKS)
04815 ACE_INLINE struct hostent *
04816 ACE_OS::gethostbyname (const char *name)
04817 {
04818   ACE_OS_TRACE ("ACE_OS::gethostbyname");
04819 # if defined (ACE_PSOS)
04820   ACE_UNUSED_ARG (name);
04821   ACE_NOTSUP_RETURN (0);
04822 # elif defined (ACE_HAS_NONCONST_GETBY)
04823   ACE_SOCKCALL_RETURN (::gethostbyname (ACE_const_cast (char *, name)),
04824                        struct hostent *,
04825                        0);
04826 # else
04827   ACE_SOCKCALL_RETURN (::gethostbyname (name),
04828                        struct hostent *,
04829                        0);
04830 # endif /* ACE_HAS_NONCONST_GETBY */
04831 }
04832 
04833 
04834 ACE_INLINE struct hostent *
04835 ACE_OS::gethostbyaddr (const char *addr, int length, int type)
04836 {
04837   ACE_OS_TRACE ("ACE_OS::gethostbyaddr");
04838 # if defined (ACE_PSOS)
04839   ACE_UNUSED_ARG (addr);
04840   ACE_UNUSED_ARG (length);
04841   ACE_UNUSED_ARG (type);
04842   ACE_NOTSUP_RETURN (0);
04843 # elif defined (ACE_HAS_NONCONST_GETBY)
04844   ACE_SOCKCALL_RETURN (::gethostbyaddr (ACE_const_cast (char *, addr),
04845                                         (ACE_SOCKET_LEN) length,
04846                                         type),
04847                        struct hostent *,
04848                        0);
04849 # else
04850   ACE_SOCKCALL_RETURN (::gethostbyaddr (addr,
04851                                         (ACE_SOCKET_LEN) length,
04852                                         type),
04853                        struct hostent *,
04854                        0);
04855 # endif /* ACE_HAS_NONCONST_GETBY */
04856 }
04857 
04858 
04859 ACE_INLINE struct hostent *
04860 ACE_OS::getipnodebyname (const char *name, int family, int flags)
04861 {
04862   ACE_OS_TRACE ("ACE_OS::getipnodebyname");
04863 # if defined (ACE_PSOS)
04864   ACE_UNUSED_ARG (name);
04865   ACE_UNUSED_ARG (family);
04866   ACE_UNUSED_ARG (flags);
04867   ACE_NOTSUP_RETURN (0);
04868 # elif defined (ACE_HAS_IPV6)
04869 #   if defined (__GLIBC__)
04870   ACE_UNUSED_ARG (flags);
04871 #     if defined (ACE_HAS_NONCONST_GETBY)
04872   ACE_SOCKCALL_RETURN (::gethostbyname2 (ACE_const_cast (char *, name),
04873                                          family),
04874                        struct hostent *, 0);
04875 #     else
04876   ACE_SOCKCALL_RETURN (::gethostbyname2 (name, family),
04877                        struct hostent *, 0);
04878 #     endif /* ACE_HAS_NONCONST_GETBY */
04879 #   else
04880   struct hostent *hptr;
04881   int errnum;
04882   if ((hptr = ::getipnodebyname (name, family, flags, &errnum)) == 0)
04883     {
04884       errno = errnum;
04885     }
04886   return hptr;
04887 #   endif /* __GLIBC__ */
04888 # else
04889   // IPv4-only implementation
04890   ACE_UNUSED_ARG (flags);
04891   if (family == AF_INET)
04892     return ACE_OS::gethostbyname (name);
04893 
04894   ACE_NOTSUP_RETURN (0);
04895 # endif /* ACE_PSOS */
04896 }
04897 
04898 
04899 ACE_INLINE struct hostent *
04900 ACE_OS::getipnodebyaddr (const void *src, size_t len, int family)
04901 {
04902 #if defined (ACE_HAS_IPV6)
04903 #  if defined (__GLIBC__)
04904   ACE_UNUSED_ARG (src);
04905   ACE_UNUSED_ARG (len);
04906   ACE_UNUSED_ARG (family);
04907   ACE_NOTSUP_RETURN (0);
04908 #  else
04909   struct hostent *hptr;
04910   int errnum;
04911   if ((hptr = ::getipnodebyaddr (src, len, family, &errnum)) == 0)
04912     {
04913       errno = errnum;
04914     }
04915   return hptr;
04916 #  endif /* whatever_doesnt_have_getipnodebyname */
04917 #else
04918   // IPv4-only implementation
04919   if (family == AF_INET)
04920     return ACE_OS::gethostbyaddr (ACE_static_cast (const char *, src),
04921                                   ACE_static_cast (int, len),
04922                                   family);
04923 
04924   ACE_NOTSUP_RETURN (0);
04925 # endif /* ACE_PSOS */
04926 }
04927 #endif /* ! VXWORKS */
04928 
04929 // It would be really cool to add another version of select that would
04930 // function like the one we're defending against below!
04931 ACE_INLINE int
04932 ACE_OS::select (int width,
04933                 fd_set *rfds, fd_set *wfds, fd_set *efds,
04934                 const ACE_Time_Value *timeout)
04935 {
04936   ACE_OS_TRACE ("ACE_OS::select");
04937 #if defined (ACE_HAS_NONCONST_SELECT_TIMEVAL)
04938   // We must defend against non-conformity!
04939   timeval copy;
04940   timeval *timep;
04941 
04942   if (timeout != 0)
04943     {
04944       copy = *timeout;
04945       timep = &copy;
04946     }
04947   else
04948     timep = 0;
04949 #else
04950   const timeval *timep = (timeout == 0 ? (const timeval *)0 : *timeout);
04951 #endif /* ACE_HAS_NONCONST_SELECT_TIMEVAL */
04952   ACE_SOCKCALL_RETURN (::select (width,
04953                                  (ACE_FD_SET_TYPE *) rfds,
04954                                  (ACE_FD_SET_TYPE *) wfds,
04955                                  (ACE_FD_SET_TYPE *) efds,
04956                                  timep),
04957                        int, -1);
04958 }
04959 
04960 ACE_INLINE int
04961 ACE_OS::select (int width,
04962                 fd_set *rfds, fd_set *wfds, fd_set *efds,
04963                 const ACE_Time_Value &timeout)
04964 {
04965   ACE_OS_TRACE ("ACE_OS::select");
04966 #if defined (ACE_HAS_NONCONST_SELECT_TIMEVAL)
04967 # define ___ACE_TIMEOUT &copy
04968   timeval copy = timeout;
04969 #else
04970 # define ___ACE_TIMEOUT timep
04971   const timeval *timep = timeout;
04972 #endif /* ACE_HAS_NONCONST_SELECT_TIMEVAL */
04973   ACE_SOCKCALL_RETURN (::select (width,
04974                                  (ACE_FD_SET_TYPE *) rfds,
04975                                  (ACE_FD_SET_TYPE *) wfds,
04976                                  (ACE_FD_SET_TYPE *) efds,
04977                                  ___ACE_TIMEOUT),
04978                        int, -1);
04979 #undef ___ACE_TIMEOUT
04980 }
04981 
04982 ACE_INLINE int
04983 ACE_OS::recv (ACE_HANDLE handle, char *buf, size_t len, int flags)
04984 {
04985   ACE_OS_TRACE ("ACE_OS::recv");
04986 
04987   // On UNIX, a non-blocking socket with no data to receive, this
04988   // system call will return EWOULDBLOCK or EAGAIN, depending on the
04989   // platform.  UNIX 98 allows either errno, and they may be the same
04990   // numeric value.  So to make life easier for upper ACE layers as
04991   // well as application programmers, always change EAGAIN to
04992   // EWOULDBLOCK.  Rather than hack the ACE_OSCALL_RETURN macro, it's
04993   // handled explicitly here.  If the ACE_OSCALL macro ever changes,
04994   // this function needs to be reviewed.  On Win32, the regular macros
04995   // can be used, as this is not an issue.
04996 #if defined (ACE_WIN32)
04997   ACE_SOCKCALL_RETURN (::recv ((ACE_SOCKET) handle, buf,
04998                                ACE_static_cast (int, len), flags), int, -1);
04999 #else
05000   int ace_result_;
05001   ace_result_ = ::recv ((ACE_SOCKET) handle, buf, len, flags);
05002   if (ace_result_ == -1 && errno == EAGAIN)
05003     errno = EWOULDBLOCK;
05004   return ace_result_;
05005 #endif /* defined (ACE_WIN32) */
05006 }
05007 
05008 ACE_INLINE int
05009 ACE_OS::recvfrom (ACE_HANDLE handle,
05010                   char *buf,
05011                   size_t len,
05012                   int flags,
05013                   struct sockaddr *addr,
05014                   int *addrlen)
05015 {
05016   ACE_OS_TRACE ("ACE_OS::recvfrom");
05017 #if defined (ACE_PSOS)
05018 #  if !defined ACE_PSOS_DIAB_PPC
05019   ACE_SOCKCALL_RETURN (::recvfrom ((ACE_SOCKET) handle, buf, len, flags,
05020                                    (struct sockaddr_in *) addr, (ACE_SOCKET_LEN *) addrlen),
05021                        int, -1);
05022 #  else
05023   ACE_SOCKCALL_RETURN (::recvfrom ((ACE_SOCKET) handle, buf, len, flags,
05024                                    (struct sockaddr *) addr, (ACE_SOCKET_LEN *) addrlen),
05025                        int, -1);
05026 #  endif /* defined ACE_PSOS_DIAB_PPC */
05027 #elif defined (ACE_WIN32)
05028   int shortened_len = ACE_static_cast (int, len);
05029   int result = ::recvfrom ((ACE_SOCKET) handle,
05030                            buf,
05031                            shortened_len,
05032                            flags,
05033                            addr,
05034                            (ACE_SOCKET_LEN *) addrlen);
05035   if (result == SOCKET_ERROR)
05036     {
05037       ACE_OS::set_errno_to_wsa_last_error ();
05038       if (errno == WSAEMSGSIZE &&
05039           ACE_BIT_ENABLED (flags, MSG_PEEK))
05040         return shortened_len;
05041       else
05042         return -1;
05043     }
05044   else
05045     return result;
05046 #else /* non Win32 and non PSOS */
05047   ACE_SOCKCALL_RETURN (::recvfrom ((ACE_SOCKET) handle, buf, len, flags,
05048                                    addr, (ACE_SOCKET_LEN *) addrlen),
05049                        int, -1);
05050 #endif /* defined (ACE_PSOS) */
05051 }
05052 
05053 ACE_INLINE int
05054 ACE_OS::send (ACE_HANDLE handle, const char *buf, size_t len, int flags)
05055 {
05056   ACE_OS_TRACE ("ACE_OS::send");
05057 
05058   // On UNIX, a non-blocking socket with no data to receive, this
05059   // system call will return EWOULDBLOCK or EAGAIN, depending on the
05060   // platform.  UNIX 98 allows either errno, and they may be the same
05061   // numeric value.  So to make life easier for upper ACE layers as
05062   // well as application programmers, always change EAGAIN to
05063   // EWOULDBLOCK.  Rather than hack the ACE_OSCALL_RETURN macro, it's
05064   // handled explicitly here.  If the ACE_OSCALL macro ever changes,
05065   // this function needs to be reviewed.  On Win32, the regular macros
05066   // can be used, as this is not an issue.
05067 #if defined (ACE_WIN32)
05068   ACE_SOCKCALL_RETURN (::send ((ACE_SOCKET) handle,
05069                                buf,
05070                                ACE_static_cast (int, len),
05071                                flags), int, -1);
05072 #else
05073   int ace_result_;
05074 #  if defined (VXWORKS) || defined (HPUX) || defined (ACE_PSOS)
05075   ace_result_ = ::send ((ACE_SOCKET) handle, (char *) buf, len, flags);
05076 #  else
05077   ace_result_ = ::send ((ACE_SOCKET) handle, buf, len, flags);
05078 #  endif /* VXWORKS */
05079   if (ace_result_ == -1 && errno == EAGAIN)
05080     errno = EWOULDBLOCK;
05081   return ace_result_;
05082 #endif /* defined (ACE_WIN32) */
05083 }
05084 
05085 ACE_INLINE int
05086 ACE_OS::recvfrom (ACE_HANDLE handle,
05087                   iovec *buffers,
05088                   int buffer_count,
05089                   size_t &number_of_bytes_recvd,
05090                   int &flags,
05091                   struct sockaddr *addr,
05092                   int *addrlen,
05093                   ACE_OVERLAPPED *overlapped,
05094                   ACE_OVERLAPPED_COMPLETION_FUNC func)
05095 {
05096   ACE_OS_TRACE ("ACE_OS::recvfrom");
05097 
05098 #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
05099   DWORD bytes_recvd;
05100   DWORD the_flags = flags;
05101   int result = ::WSARecvFrom ((SOCKET) handle,
05102                               (WSABUF*)buffers,
05103                               buffer_count,
05104                               &bytes_recvd,
05105                               &the_flags,
05106                               addr,
05107                               addrlen,
05108                               overlapped,
05109                               func);
05110   if (result != 0) {
05111     ACE_OS::set_errno_to_last_error ();
05112   }
05113   flags = the_flags;
05114   number_of_bytes_recvd = ACE_static_cast (size_t, bytes_recvd);
05115   return result;
05116 #else
05117   ACE_UNUSED_ARG (handle);
05118   ACE_UNUSED_ARG (buffers);
05119   ACE_UNUSED_ARG (buffer_count);
05120   ACE_UNUSED_ARG (number_of_bytes_recvd);
05121   ACE_UNUSED_ARG (flags);
05122   ACE_UNUSED_ARG (addr);
05123   ACE_UNUSED_ARG (addrlen);
05124   ACE_UNUSED_ARG (overlapped);
05125   ACE_UNUSED_ARG (func);
05126   ACE_NOTSUP_RETURN (-1);
05127 #endif /* defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0) */
05128 }
05129 
05130 ACE_INLINE int
05131 ACE_OS::sendto (ACE_HANDLE handle,
05132                 const char *buf,
05133                 size_t len,
05134                 int flags,
05135                 const struct sockaddr *addr,
05136                 int addrlen)
05137 {
05138   ACE_OS_TRACE ("ACE_OS::sendto");
05139 #if defined (VXWORKS)
05140   ACE_SOCKCALL_RETURN (::sendto ((ACE_SOCKET) handle, (char *) buf, len, flags,
05141                                  ACE_const_cast (struct sockaddr *, addr), addrlen),
05142                        int, -1);
05143 #elif defined (ACE_PSOS)
05144 #  if !defined (ACE_PSOS_DIAB_PPC)
05145   ACE_SOCKCALL_RETURN (::sendto ((ACE_SOCKET) handle, (char *) buf, len, flags,
05146                                  (struct sockaddr_in *) addr, addrlen),
05147                        int, -1);
05148 #  else
05149   ACE_SOCKCALL_RETURN (::sendto ((ACE_SOCKET) handle, (char *) buf, len, flags,
05150                                  (struct sockaddr *) addr, addrlen),
05151                        int, -1);
05152 #  endif /*defined ACE_PSOS_DIAB_PPC */
05153 #else
05154 #  if defined (ACE_WIN32)
05155   ACE_SOCKCALL_RETURN (::sendto ((ACE_SOCKET) handle, buf,
05156                                  ACE_static_cast (int, len), flags,
05157                                  ACE_const_cast (struct sockaddr *, addr), addrlen),
05158                        int, -1);
05159 #  else
05160   ACE_SOCKCALL_RETURN (::sendto ((ACE_SOCKET) handle, buf, len, flags,
05161                                  ACE_const_cast (struct sockaddr *, addr), addrlen),
05162                        int, -1);
05163 #  endif /* ACE_WIN32 */
05164 #endif /* VXWORKS */
05165 }
05166 
05167 ACE_INLINE int
05168 ACE_OS::sendto (ACE_HANDLE handle,
05169                 const iovec *buffers,
05170                 int buffer_count,
05171                 size_t &number_of_bytes_sent,
05172                 int flags,
05173                 const struct sockaddr *addr,
05174                 int addrlen,
05175                 ACE_OVERLAPPED *overlapped,
05176                 ACE_OVERLAPPED_COMPLETION_FUNC func)
05177 {
05178   ACE_OS_TRACE ("ACE_OS::sendto");
05179 #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
05180   DWORD bytes_sent;
05181   int result = ::WSASendTo ((SOCKET) handle,
05182                             (WSABUF*)buffers,
05183                             buffer_count,
05184                             &bytes_sent,
05185                             flags,
05186                             addr,
05187                             addrlen,
05188                             overlapped,
05189                             func);
05190   if (result != 0) {
05191     ACE_OS::set_errno_to_last_error ();
05192   }
05193   number_of_bytes_sent = ACE_static_cast (size_t, bytes_sent);
05194   return result;
05195 #else
05196   ACE_UNUSED_ARG (overlapped);
05197   ACE_UNUSED_ARG (func);
05198 
05199   number_of_bytes_sent = 0;
05200 
05201   int result = 0;
05202 
05203   for (int i = 0; i < buffer_count; i++)
05204     {
05205        result = ACE_OS::sendto (handle,
05206                                 ACE_reinterpret_cast (char *ACE_CAST_CONST,
05207                                                       buffers[i].iov_base),
05208                                 buffers[i].iov_len,
05209                                 flags,
05210                                 addr,
05211                                 addrlen);
05212        if (result == -1)
05213          break;
05214        number_of_bytes_sent += result;
05215     }
05216 
05217   return result;
05218 #endif /* defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0) */
05219 }
05220 
05221 ACE_INLINE int
05222 ACE_OS::getpeername (ACE_HANDLE handle, struct sockaddr *addr,
05223                      int *addrlen)
05224 {
05225   ACE_OS_TRACE ("ACE_OS::getpeername");
05226 #if defined (ACE_PSOS) && !defined ACE_PSOS_DIAB_PPC
05227   ACE_SOCKCALL_RETURN (::getpeername ((ACE_SOCKET) handle,
05228                                       (struct sockaddr_in *) addr,
05229                                       (ACE_SOCKET_LEN *) addrlen),
05230                        int, -1);
05231 #else
05232   ACE_SOCKCALL_RETURN (::getpeername ((ACE_SOCKET) handle,
05233                                       addr,
05234                                       (ACE_SOCKET_LEN *) addrlen),
05235                        int, -1);
05236 #endif /* defined (ACE_PSOS) */
05237 }
05238 
05239 ACE_INLINE struct protoent *
05240 ACE_OS::getprotobyname (const char *name)
05241 {
05242 #if defined (VXWORKS) || defined (ACE_HAS_WINCE) || (defined (ghs) && defined (__Chorus)) || defined (ACE_PSOS)
05243   ACE_UNUSED_ARG (name);
05244   ACE_NOTSUP_RETURN (0);
05245 #elif defined (ACE_HAS_NONCONST_GETBY)
05246   ACE_SOCKCALL_RETURN (::getprotobyname (ACE_const_cast (char *, name)),
05247                        struct protoent *,
05248                        0);
05249 #else
05250   ACE_SOCKCALL_RETURN (::getprotobyname (name),
05251                        struct protoent *,
05252                        0);
05253 #endif /* VXWORKS */
05254 }
05255 
05256 ACE_INLINE struct protoent *
05257 ACE_OS::getprotobyname_r (const char *name,
05258                           struct protoent *result,
05259                           ACE_PROTOENT_DATA buffer)
05260 {
05261 #if defined (VXWORKS) || defined (ACE_HAS_WINCE) || (defined (ghs) && defined (__Chorus)) || defined (ACE_PSOS)
05262   ACE_UNUSED_ARG (name);
05263   ACE_UNUSED_ARG (result);
05264   ACE_UNUSED_ARG (buffer);
05265   ACE_NOTSUP_RETURN (0);
05266 #elif defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (UNIXWARE)
05267 # if defined (AIX) || defined (DIGITAL_UNIX) || defined (HPUX_10)
05268   if (::getprotobyname_r (name, result, (struct protoent_data *) buffer) == 0)
05269     return result;
05270   else
05271     return 0;
05272 # elif defined (__GLIBC__)
05273   // GNU C library has a different signature
05274   if (::getprotobyname_r (name,
05275                           result,
05276                           buffer,
05277                           sizeof (ACE_PROTOENT_DATA),
05278                           &result) == 0)
05279     return result;
05280   else
05281     return 0;
05282 # else
05283 #   if defined(ACE_LACKS_NETDB_REENTRANT_FUNCTIONS)
05284   ACE_UNUSED_ARG (result);
05285   ACE_NETDBCALL_RETURN (::getprotobyname (name),
05286                         struct protoent *, 0,
05287                         buffer, sizeof (ACE_PROTOENT_DATA));
05288 #   else
05289     ACE_SOCKCALL_RETURN (::getprotobyname_r (name,
05290                                              result,
05291                                              buffer,
05292                                              sizeof (ACE_PROTOENT_DATA)),
05293                        struct protoent *, 0);
05294 #   endif /* ACE_LACKS_NETDB_REENTRANT_FUNCTIONS */
05295 # endif /* defined (AIX) || defined (DIGITAL_UNIX) */
05296 #elif defined (ACE_HAS_NONCONST_GETBY)
05297   ACE_UNUSED_ARG (result);
05298   ACE_UNUSED_ARG (buffer);
05299   ACE_SOCKCALL_RETURN (::getprotobyname (ACE_const_cast (char *, name)),
05300                        struct protoent *, 0);
05301 #else
05302   ACE_UNUSED_ARG (buffer);
05303   ACE_UNUSED_ARG (result);
05304 
05305   ACE_SOCKCALL_RETURN (::getprotobyname (name),
05306                        struct protoent *,
05307                        0);
05308 #endif /* defined (ACE_HAS_REENTRANT_FUNCTIONS) !defined (UNIXWARE) */
05309 }
05310 
05311 ACE_INLINE struct protoent *
05312 ACE_OS::getprotobynumber (int proto)
05313 {
05314 #if defined (VXWORKS) || defined (ACE_HAS_WINCE) || (defined (ghs) && defined (__Chorus)) || defined (ACE_PSOS)
05315   ACE_UNUSED_ARG (proto);
05316   ACE_NOTSUP_RETURN (0);
05317 #else
05318   ACE_SOCKCALL_RETURN (::getprotobynumber (proto),
05319                        struct protoent *, 0);
05320 #endif /* VXWORKS */
05321 }
05322 
05323 ACE_INLINE struct protoent *
05324 ACE_OS::getprotobynumber_r (int proto,
05325                             struct protoent *result,
05326                             ACE_PROTOENT_DATA buffer)
05327 {
05328 #if defined (VXWORKS) || defined (ACE_HAS_WINCE) || (defined (ghs) && defined (__Chorus)) || defined (ACE_PSOS)
05329   ACE_UNUSED_ARG (proto);
05330   ACE_UNUSED_ARG (result);
05331   ACE_UNUSED_ARG (buffer);
05332   ACE_NOTSUP_RETURN (0);
05333 #elif defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (UNIXWARE)
05334 # if defined (AIX) || defined (DIGITAL_UNIX) || defined (HPUX_10)
05335   if (::getprotobynumber_r (proto, result, (struct protoent_data *) buffer) == 0)
05336     return result;
05337   else
05338     return 0;
05339 # elif defined (__GLIBC__)
05340   // GNU C library has a different signature
05341   if (::getprotobynumber_r (proto,
05342                             result,
05343                             buffer,
05344                             sizeof (ACE_PROTOENT_DATA),
05345                             &result) == 0)
05346     return result;
05347   else
05348     return 0;
05349 # else
05350 #   if defined(ACE_LACKS_NETDB_REENTRANT_FUNCTIONS)
05351   ACE_UNUSED_ARG (result);
05352   ACE_NETDBCALL_RETURN (::getprotobynumber (proto),
05353                         struct protoent *, 0,
05354                         buffer, sizeof (ACE_PROTOENT_DATA));
05355 #   else
05356   ACE_SOCKCALL_RETURN (::getprotobynumber_r (proto, result, buffer, sizeof (ACE_PROTOENT_DATA)),
05357                        struct protoent *, 0);
05358 #   endif /* ACE_LACKS_NETDB_REENTRANT_FUNCTIONS */
05359 # endif /* defined (AIX) || defined (DIGITAL_UNIX) */
05360 #else
05361   ACE_UNUSED_ARG (buffer);
05362   ACE_UNUSED_ARG (result);
05363 
05364   ACE_SOCKCALL_RETURN (::getprotobynumber (proto),
05365                        struct protoent *, 0);
05366 #endif /* defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (UNIXWARE) */
05367 }
05368 
05369 ACE_INLINE struct servent *
05370 ACE_OS::getservbyname (const char *svc, const char *proto)
05371 {
05372   ACE_OS_TRACE ("ACE_OS::getservbyname");
05373 #if defined (ACE_LACKS_GETSERVBYNAME)
05374   ACE_UNUSED_ARG (svc);
05375   ACE_UNUSED_ARG (proto);
05376   ACE_NOTSUP_RETURN (0);
05377 #elif defined (ACE_HAS_NONCONST_GETBY)
05378   ACE_SOCKCALL_RETURN (::getservbyname (ACE_const_cast (char *, svc),
05379                                         ACE_const_cast (char *, proto)),
05380                        struct servent *,
05381                        0);
05382 #else
05383   ACE_SOCKCALL_RETURN (::getservbyname (svc,
05384                                         proto),
05385                        struct servent *,
05386                        0);
05387 #endif /* ACE_HAS_NONCONST_GETBY */
05388 }
05389 
05390 ACE_INLINE int
05391 ACE_OS::getsockname (ACE_HANDLE handle,
05392                      struct sockaddr *addr,
05393                      int *addrlen)
05394 {
05395   ACE_OS_TRACE ("ACE_OS::getsockname");
05396 #if defined (ACE_PSOS) && !defined (ACE_PSOS_DIAB_PPC)
05397   ACE_SOCKCALL_RETURN (::getsockname ((ACE_SOCKET) handle,
05398                                       (struct sockaddr_in *) addr,
05399                                       (ACE_SOCKET_LEN *) addrlen),
05400                        int, -1);
05401 #else
05402   ACE_SOCKCALL_RETURN (::getsockname ((ACE_SOCKET) handle,
05403                                       addr,
05404                                       (ACE_SOCKET_LEN *) addrlen),
05405                        int, -1);
05406 #endif /* defined (ACE_PSOS) */
05407 }
05408 
05409 ACE_INLINE int
05410 ACE_OS::getsockopt (ACE_HANDLE handle,
05411                     int level,
05412                     int optname,
05413                     char *optval,
05414                     int *optlen)
05415 {
05416   ACE_OS_TRACE ("ACE_OS::getsockopt");
05417   ACE_SOCKCALL_RETURN (::getsockopt ((ACE_SOCKET) handle,
05418                                      level,
05419                                      optname,
05420                                      optval,
05421                                      (ACE_SOCKET_LEN *) optlen),
05422                        int,
05423                        -1);
05424 }
05425 
05426 ACE_INLINE int
05427 ACE_OS::listen (ACE_HANDLE handle, int backlog)
05428 {
05429   ACE_OS_TRACE ("ACE_OS::listen");
05430   ACE_SOCKCALL_RETURN (::listen ((ACE_SOCKET) handle, backlog), int, -1);
05431 }
05432 
05433 ACE_INLINE int
05434 ACE_OS::setsockopt (ACE_HANDLE handle,
05435                     int level,
05436                     int optname,
05437                     const char *optval,
05438                     int optlen)
05439 {
05440   ACE_OS_TRACE ("ACE_OS::setsockopt");
05441 
05442   #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0) && defined(SO_REUSEPORT)
05443   // To work around an inconsistency with Microsofts implementation of
05444   // sockets, we will check for SO_REUSEADDR, and ignore it. Winsock
05445   // always behaves as if SO_REUSEADDR=1. Some implementations have the
05446   // same behaviour as Winsock, but use a new name for it. SO_REUSEPORT.
05447   // If you want the normal behaviour for SO_REUSEADDR=0, then NT 4 sp4 and later
05448   // supports SO_EXCLUSIVEADDRUSE. This also requires using an updated Platform SDK
05449   // so it was decided to ignore the option for now. (Especially since ACE always
05450   // sets SO_REUSEADDR=1, which we can mimic by doing nothing.)
05451   if (level == SOL_SOCKET) {
05452     if (optname == SO_REUSEADDR) {
05453       return 0; // Not supported by Winsock
05454     }
05455     if (optname == SO_REUSEPORT) {
05456       optname = SO_REUSEADDR;
05457     }
05458   }
05459   #endif /*ACE_HAS_WINSOCK2*/
05460 
05461   ACE_SOCKCALL_RETURN (::setsockopt ((ACE_SOCKET) handle,
05462                                      level,
05463                                      optname,
05464                                      (ACE_SOCKOPT_TYPE1) optval,
05465                                      optlen),
05466                        int,
05467                        -1);
05468 }
05469 
05470 ACE_INLINE int
05471 ACE_OS::shutdown (ACE_HANDLE handle, int how)
05472 {
05473   ACE_OS_TRACE ("ACE_OS::shutdown");
05474   ACE_SOCKCALL_RETURN (::shutdown ((ACE_SOCKET) handle, how), int, -1);
05475 }
05476 
05477 ACE_INLINE ACE_HANDLE
05478 ACE_OS::socket (int domain,
05479                 int type,
05480                 int proto)
05481 {
05482   ACE_OS_TRACE ("ACE_OS::socket");
05483   ACE_SOCKCALL_RETURN (::socket (domain,
05484                                  type,
05485                                  proto),
05486                        ACE_HANDLE,
05487                        ACE_INVALID_HANDLE);
05488 }
05489 
05490 ACE_INLINE ACE_HANDLE
05491 ACE_OS::socket (int domain,
05492                 int type,
05493                 int proto,
05494                 ACE_Protocol_Info *protocolinfo,
05495                 ACE_SOCK_GROUP g,
05496                 u_long flags)
05497 {
05498   ACE_OS_TRACE ("ACE_OS::socket");
05499 
05500 #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
05501   ACE_SOCKCALL_RETURN (::WSASocket (domain,
05502                                     type,
05503                                     proto,
05504                                     protocolinfo,
05505                                     g,
05506                                     flags),
05507                        ACE_HANDLE,
05508                        ACE_INVALID_HANDLE);
05509 #else
05510   ACE_UNUSED_ARG (protocolinfo);
05511   ACE_UNUSED_ARG (g);
05512   ACE_UNUSED_ARG (flags);
05513 
05514   return ACE_OS::socket (domain,
05515                          type,
05516                          proto);
05517 #endif /* ACE_HAS_WINSOCK2 */
05518 }
05519 
05520 ACE_INLINE int
05521 ACE_OS::atoi (const char *s)
05522 {
05523   ACE_OSCALL_RETURN (::atoi (s), int, -1);
05524 }
05525 
05526 #if defined (ACE_HAS_WCHAR)
05527 ACE_INLINE int
05528 ACE_OS::atoi (const wchar_t *s)
05529 {
05530 #if defined (ACE_WIN32)
05531   ACE_OSCALL_RETURN (::_wtoi (s), int, -1);
05532 #else /* ACE_WIN32 */
05533   return ACE_OS::atoi (ACE_Wide_To_Ascii(s).char_rep());
05534 #endif /* ACE_WIN32 */
05535 }
05536 #endif /* ACE_HAS_WCHAR */
05537 
05538 
05539 ACE_INLINE void *
05540 ACE_OS::atop (const char *s)
05541 {
05542   ACE_TRACE ("ACE_OS::atop");
05543   // It would be nice to make use of Basic_Types.h here, but that
05544   // file relies on OS.h. Fortunately, most platforms have int
05545   // the same as pointer size (IA32, IA64), with Win64 being the
05546   // exception.
05547 #if defined (ACE_WIN64)
05548   __int64 ip = ::_atoi64 (s);
05549 #else
05550   int ip = ::atoi (s);
05551 #endif /* ACE_WIN64 */
05552   void *p = ACE_reinterpret_cast (void *, ip);
05553   return p;
05554 }
05555 
05556 #if defined (ACE_HAS_WCHAR)
05557 ACE_INLINE void *
05558 ACE_OS::atop (const wchar_t *s)
05559 {
05560 #  if defined (ACE_WIN64)
05561   __int64 ip = ::_wtoi64 (s);
05562 #  else
05563   int ip = ACE_OS::atoi (s);
05564 #  endif /* ACE_WIN64 */
05565   void *p = ACE_reinterpret_cast (void *, ip);
05566   return p;
05567 }
05568 #endif /* ACE_HAS_WCHAR */
05569 
05570 ACE_INLINE double
05571 ACE_OS::floor (double x)
05572 {
05573   // This method computes the largest integral value not greater than x.
05574   return double (ACE_static_cast (long, x));
05575 }
05576 
05577 ACE_INLINE double
05578 ACE_OS::ceil (double x)
05579 {
05580   // This method computes the smallest integral value not less than x.
05581   double floor = ACE_OS::floor (x);
05582   if (floor == x)
05583     return floor;
05584   else
05585     return floor + 1;
05586 }
05587 
05588 ACE_INLINE int
05589 ACE_OS::recvmsg (ACE_HANDLE handle, struct msghdr *msg, int flags)
05590 {
05591   ACE_OS_TRACE ("ACE_OS::recvmsg");
05592 #if !defined (ACE_LACKS_RECVMSG)
05593 # if (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
05594   DWORD bytes_received = 0;
05595 
05596   int result = ::WSARecvFrom ((SOCKET) handle,
05597                               (WSABUF *) msg->msg_iov,
05598                               msg->msg_iovlen,
05599                               &bytes_received,
05600                               (DWORD *) &flags,
05601                               msg->msg_name,
05602                               &msg->msg_namelen,
05603                               0,
05604                               0);
05605 
05606   if (result != 0)
05607     {
05608       ACE_OS::set_errno_to_last_error ();
05609       return -1;
05610     }
05611   else
05612     return (ssize_t) bytes_received;
05613 # else /* ACE_HAS_WINSOCK2 */
05614   ACE_SOCKCALL_RETURN (::recvmsg (handle, msg, flags), int, -1);
05615 # endif /* ACE_HAS_WINSOCK2 */
05616 #else
05617   ACE_UNUSED_ARG (flags);
05618   ACE_UNUSED_ARG (msg);
05619   ACE_UNUSED_ARG (handle);
05620 
05621   ACE_NOTSUP_RETURN (-1);
05622 #endif /* ACE_LACKS_RECVMSG */
05623 }
05624 
05625 ACE_INLINE int
05626 ACE_OS::sendmsg (ACE_HANDLE handle,
05627                  const struct msghdr *msg,
05628                  int flags)
05629 {
05630   ACE_OS_TRACE ("ACE_OS::sendmsg");
05631 #if !defined (ACE_LACKS_SENDMSG)
05632 # if (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
05633   DWORD bytes_sent = 0;
05634   int result = ::WSASendTo ((SOCKET) handle,
05635                             (WSABUF *) msg->msg_iov,
05636                             msg->msg_iovlen,
05637                             &bytes_sent,
05638                             flags,
05639                             msg->msg_name,
05640                             msg->msg_namelen,
05641                             0,
05642                             0);
05643 
05644   if (result != 0)
05645     {
05646       ACE_OS::set_errno_to_last_error ();
05647       return -1;
05648     }
05649   else
05650     return (ssize_t) bytes_sent;
05651 # elif defined (ACE_LACKS_POSIX_PROTOTYPES) ||  defined (ACE_PSOS)
05652   ACE_SOCKCALL_RETURN (::sendmsg (handle, (struct msghdr *) msg, flags), int, -1);
05653 # else
05654   ACE_SOCKCALL_RETURN (::sendmsg (handle, (ACE_SENDMSG_TYPE *) msg, flags), int, -1);
05655 # endif /* ACE_LACKS_POSIX_PROTOTYPES */
05656 #else
05657   ACE_UNUSED_ARG (flags);
05658   ACE_UNUSED_ARG (msg);
05659   ACE_UNUSED_ARG (handle);
05660 
05661   ACE_NOTSUP_RETURN (-1);
05662 #endif /* ACE_LACKS_SENDMSG */
05663 }
05664 
05665 ACE_INLINE int
05666 ACE_OS::fclose (FILE *fp)
05667 {
05668   ACE_OS_TRACE ("ACE_OS::fclose");
05669   ACE_OSCALL_RETURN (::fclose (fp), int, -1);
05670 }
05671 
05672 ACE_INLINE ACE_TCHAR *
05673 ACE_OS::fgets (ACE_TCHAR *buf, int size, FILE *fp)
05674 {
05675   ACE_OS_TRACE ("ACE_OS::fgets");
05676 #if defined (ACE_HAS_WINCE)
05677   ACE_UNUSED_ARG (buf);
05678   ACE_UNUSED_ARG (size);
05679   ACE_UNUSED_ARG (fp);
05680   ACE_NOTSUP_RETURN (0);
05681 #elif defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
05682   ACE_OSCALL_RETURN (::fgetws (buf, size, fp), wchar_t *, 0);
05683 #else /* ACE_WIN32 */
05684   ACE_OSCALL_RETURN (::fgets (buf, size, fp), char *, 0);
05685 #endif /* ACE_HAS_WINCE */
05686 }
05687 
05688 #if !defined (ACE_WIN32)
05689 // Win32 implementation of fopen(const ACE_TCHAR*, const ACE_TCHAR*)
05690 // is in OS.cpp.
05691 ACE_INLINE FILE *
05692 ACE_OS::fopen (const ACE_TCHAR *filename, const ACE_TCHAR *mode)
05693 {
05694   ACE_OS_TRACE ("ACE_OS::fopen");
05695   ACE_OSCALL_RETURN (::fopen (filename, mode), FILE *, 0);
05696 }
05697 #endif /* ACE_WIN32 */
05698 
05699 ACE_INLINE FILE *
05700 ACE_OS::freopen (const ACE_TCHAR *filename, const ACE_TCHAR *mode, FILE* stream)
05701 {
05702   ACE_OS_TRACE ("ACE_OS::freopen");
05703 #if defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
05704   ACE_OSCALL_RETURN (::_wfreopen (filename, mode, stream), FILE *, 0);
05705 #else
05706   ACE_OSCALL_RETURN (::freopen (filename, mode, stream), FILE *, 0);
05707 #endif /* ACE_WIN32 && ACE_USES_WCHAR */
05708 }
05709 
05710 ACE_INLINE int
05711 ACE_OS::fflush (FILE *fp)
05712 {
05713 #if !defined (ACE_HAS_WINCE)
05714   ACE_OS_TRACE ("ACE_OS::fflush");
05715 #if defined (VXWORKS)
05716   if (fp == 0)
05717     {
05718       // Do not allow fflush(0) on VxWorks
05719       return 0;
05720     }
05721 #endif /* VXWORKS */
05722 
05723   ACE_OSCALL_RETURN (::fflush (fp), int, -1);
05724 #else
05725   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL(::FlushFileBuffers (fp),
05726                                          ace_result_),
05727                         int, -1);
05728 #endif /* !ACE_HAS_WINCE */
05729 }
05730 
05731 ACE_INLINE size_t
05732 ACE_OS::fread (void *ptr, size_t size, size_t nelems, FILE *fp)
05733 {
05734   ACE_OS_TRACE ("ACE_OS::fread");
05735 #if defined (ACE_LACKS_POSIX_PROTOTYPES)
05736   ACE_OSCALL_RETURN (::fread ((char *) ptr, size, nelems, fp), int, 0);
05737 #else
05738   ACE_OSCALL_RETURN (::fread (ptr, size, nelems, fp), int, 0);
05739 #endif /* ACE_LACKS_POSIX_PROTOTYPES */
05740 }
05741 
05742 ACE_INLINE size_t
05743 ACE_OS::fwrite (const void *ptr, size_t size, size_t nitems, FILE *fp)
05744 {
05745   ACE_OS_TRACE ("ACE_OS::fwrite");
05746 #if defined (ACE_LACKS_POSIX_PROTOTYPES)
05747   ACE_OSCALL_RETURN (::fwrite ((const char *) ptr, size, nitems, fp), int, 0);
05748 #else
05749   ACE_OSCALL_RETURN (::fwrite (ptr, size, nitems, fp), int, 0);
05750 #endif /* ACE_LACKS_POSIX_PROTOTYPES */
05751 }
05752 
05753 ACE_INLINE int
05754 ACE_OS::truncate (const ACE_TCHAR *filename,
05755                   off_t offset)
05756 {
05757   ACE_OS_TRACE ("ACE_OS::truncate");
05758 #if defined (ACE_WIN32)
05759   ACE_HANDLE handle = ACE_OS::open (filename,
05760                                     O_WRONLY,
05761                                     ACE_DEFAULT_FILE_PERMS);
05762   if (handle == ACE_INVALID_HANDLE)
05763     ACE_FAIL_RETURN (-1);
05764   else if (::SetFilePointer (handle,
05765                              offset,
05766                              0,
05767                              FILE_BEGIN) != (unsigned) -1)
05768     {
05769       BOOL result = ::SetEndOfFile (handle);
05770       ::CloseHandle (handle);
05771       ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (result, ace_result_), int, -1);
05772     }
05773   else
05774     {
05775       ::CloseHandle (handle);
05776       ACE_FAIL_RETURN (-1);
05777     }
05778   /* NOTREACHED */
05779 #elif !defined (ACE_LACKS_TRUNCATE)
05780   ACE_OSCALL_RETURN (::truncate (filename, offset), int, -1);
05781 #else
05782   ACE_UNUSED_ARG (filename);
05783   ACE_UNUSED_ARG (offset);
05784   ACE_NOTSUP_RETURN (-1);
05785 #endif /* ACE_WIN32 */
05786 }
05787 
05788 // Accessors to PWD file.
05789 
05790 ACE_INLINE struct passwd *
05791 ACE_OS::getpwnam (const char *name)
05792 {
05793 #if !defined (ACE_LACKS_PWD_FUNCTIONS)
05794 # if !defined (ACE_WIN32)
05795   return ::getpwnam (name);
05796 # else
05797   ACE_UNUSED_ARG (name);
05798   ACE_NOTSUP_RETURN (0);
05799 # endif /* ACE_WIN32 */
05800 #else
05801   ACE_UNUSED_ARG (name);
05802   ACE_NOTSUP_RETURN (0);
05803 #endif /* ACE_LACKS_PWD_FUNCTIONS */
05804 }
05805 
05806 ACE_INLINE void
05807 ACE_OS::setpwent (void)
05808 {
05809 #if !defined (ACE_LACKS_PWD_FUNCTIONS)
05810 # if !defined (ACE_WIN32)
05811   ::setpwent ();
05812 # else
05813 # endif /* ACE_WIN32 */
05814 #else
05815 #endif /* ! ACE_LACKS_PWD_FUNCTIONS */
05816 }
05817 
05818 ACE_INLINE void
05819 ACE_OS::endpwent (void)
05820 {
05821 #if !defined (ACE_LACKS_PWD_FUNCTIONS)
05822 # if !defined (ACE_WIN32)
05823   ::endpwent ();
05824 # else
05825 # endif /* ACE_WIN32 */
05826 #else
05827 #endif /* ! ACE_LACKS_PWD_FUNCTIONS */
05828 }
05829 
05830 ACE_INLINE struct passwd *
05831 ACE_OS::getpwent (void)
05832 {
05833 #if !defined (ACE_LACKS_PWD_FUNCTIONS)
05834 # if !defined (ACE_WIN32)
05835   return ::getpwent ();
05836 # else
05837   ACE_NOTSUP_RETURN (0);
05838 # endif /* ACE_WIN32 */
05839 #else
05840   ACE_NOTSUP_RETURN (0);
05841 #endif /* ! ACE_LACKS_PWD_FUNCTIONS */
05842 }
05843 
05844 ACE_INLINE struct passwd *
05845 ACE_OS::getpwnam_r (const char *name, struct passwd *pwent,
05846                     char *buffer, int buflen)
05847 {
05848 #if defined (ACE_HAS_POSIX_GETPWNAM_R)
05849   struct passwd *result;
05850   int status;
05851 
05852   status = ::getpwnam_r (name, pwent, buffer, buflen, &result);
05853 
05854   if (status != 0)
05855   {
05856     errno = status;
05857     result = 0;
05858   }
05859   return result;
05860 #elif !defined (ACE_LACKS_PWD_FUNCTIONS)
05861 # if defined (ACE_HAS_REENTRANT_FUNCTIONS)
05862 #   if !defined (ACE_LACKS_PWD_REENTRANT_FUNCTIONS)
05863 #     if defined (ACE_HAS_PTHREADS_STD) && \
05864       !defined (ACE_HAS_STHREADS) || \
05865       defined (HPUX_11)  || \
05866       defined (__USLC__) // Added by Roland Gigler for SCO UnixWare 7.
05867   struct passwd *result;
05868   int status;
05869 #       if defined (DIGITAL_UNIX)
05870   ::_Pgetpwnam_r (name, pwent, buffer, buflen, &result);
05871 #       else
05872   // VAC++ doesn't correctly grok the ::getpwnam_r - the function is redefined
05873   // in pwd.h, and that redefinition is used here
05874 #         if defined (__IBMCPP__) && (__IBMCPP__ >= 400)   /* VAC++ 4 */
05875   status = _posix_getpwnam_r (name, pwent, buffer, buflen, &result);
05876 #         else
05877   status = ::getpwnam_r (name, pwent, buffer, buflen, &result);
05878 #         endif /* __IBMCPP__ && (__IBMCPP__ >= 400) */
05879   if (status != 0)
05880     {
05881       errno = status;
05882       result = 0;
05883     }
05884 #       endif /* (DIGITAL_UNIX) */
05885   return result;
05886 #     elif defined (AIX) || defined (HPUX_10)
05887   if (::getpwnam_r (name, pwent, buffer, buflen) == -1)
05888     return 0;
05889   else
05890     return pwent;
05891 #     else
05892   return ::getpwnam_r (name, pwent, buffer, buflen);
05893 #     endif /* ACE_HAS_PTHREADS_STD */
05894 #   else
05895   ACE_UNUSED_ARG (name);
05896   ACE_UNUSED_ARG (pwent);
05897   ACE_UNUSED_ARG (buffer);
05898   ACE_UNUSED_ARG (buflen);
05899   ACE_NOTSUP_RETURN (0);
05900 #   endif /* ! ACE_LACKS_PWD_REENTRANT_FUNCTIONS */
05901 # else
05902   ACE_UNUSED_ARG (name);
05903   ACE_UNUSED_ARG (pwent);
05904   ACE_UNUSED_ARG (buffer);
05905   ACE_UNUSED_ARG (buflen);
05906   ACE_NOTSUP_RETURN (0);
05907 # endif /* ACE_HAS_REENTRANT_FUNCTIONS */
05908 #else
05909   ACE_UNUSED_ARG (name);
05910   ACE_UNUSED_ARG (pwent);
05911   ACE_UNUSED_ARG (buffer);
05912   ACE_UNUSED_ARG (buflen);
05913   ACE_NOTSUP_RETURN (0);
05914 #endif /* ACE_HAS_POSIX_GETPWNAM_R */
05915 }
05916 
05917 // DNS accessors.
05918 
05919 #if !defined (VXWORKS)
05920 ACE_INLINE struct hostent *
05921 ACE_OS::gethostbyaddr_r (const char *addr,
05922                          int length,
05923                          int type,
05924                          struct hostent *result,
05925                          ACE_HOSTENT_DATA buffer,
05926                          int *h_errnop)
05927 {
05928   ACE_OS_TRACE ("ACE_OS::gethostbyaddr_r");
05929 # if defined (ACE_PSOS)
05930   ACE_UNUSED_ARG (addr);
05931   ACE_UNUSED_ARG (length);
05932   ACE_UNUSED_ARG (type);
05933   ACE_UNUSED_ARG (result);
05934   ACE_UNUSED_ARG (buffer);
05935   ACE_UNUSED_ARG (h_errnop);
05936   ACE_NOTSUP_RETURN (0);
05937 # elif defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (UNIXWARE)
05938 #   if defined (AIX) || defined (DIGITAL_UNIX) || defined (HPUX_10)
05939   ::memset (buffer, 0, sizeof (ACE_HOSTENT_DATA));
05940 
05941   if (::gethostbyaddr_r ((char *) addr, length, type, result,
05942                          (struct hostent_data *) buffer)== 0)
05943     return result;
05944   else
05945     {
05946       *h_errnop = h_errno;
05947       return (struct hostent *) 0;
05948     }
05949 # elif defined (__GLIBC__)
05950   // GNU C library has a different signature
05951   ::memset (buffer, 0, sizeof (ACE_HOSTENT_DATA));
05952 
05953   if (::gethostbyaddr_r ((char *) addr,
05954                          length,
05955                          type,
05956                          result,
05957                          buffer,
05958                          sizeof (ACE_HOSTENT_DATA),
05959                          &result,
05960                          h_errnop) == 0)
05961     return result;
05962   else
05963     return (struct hostent *) 0;
05964 #   else
05965 #     if defined(ACE_LACKS_NETDB_REENTRANT_FUNCTIONS)
05966   ACE_UNUSED_ARG (result);
05967   ACE_UNUSED_ARG (h_errnop);
05968   ACE_NETDBCALL_RETURN (::gethostbyaddr (addr, (ACE_SOCKET_LEN) length, type),
05969                         struct hostent *, 0,
05970                         buffer, sizeof (ACE_HOSTENT_DATA));
05971 #     else
05972   ACE_SOCKCALL_RETURN (::gethostbyaddr_r (addr, length, type, result,
05973                                           buffer, sizeof (ACE_HOSTENT_DATA),
05974                                           h_errnop),
05975                        struct hostent *, 0);
05976 #     endif /* ACE_LACKS_NETDB_REENTRANT_FUNCTIONS */
05977 #   endif /* defined (AIX) || defined (DIGITAL_UNIX) */
05978 # elif defined (ACE_HAS_NONCONST_GETBY)
05979   ACE_UNUSED_ARG (result);
05980   ACE_UNUSED_ARG (buffer);
05981   ACE_UNUSED_ARG (h_errnop);
05982   ACE_SOCKCALL_RETURN (::gethostbyaddr (ACE_const_cast (char *, addr),
05983                                         (ACE_SOCKET_LEN) length,
05984                                         type),
05985                        struct hostent *,
05986                        0);
05987 # else
05988   ACE_UNUSED_ARG (h_errnop);
05989   ACE_UNUSED_ARG (buffer);
05990   ACE_UNUSED_ARG (result);
05991 
05992   ACE_SOCKCALL_RETURN (::gethostbyaddr (addr,
05993                                         (ACE_SOCKET_LEN) length,
05994                                         type),
05995                        struct hostent *,
05996                        0);
05997 # endif /* defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (UNIXWARE) */
05998 }
05999 
06000 ACE_INLINE struct hostent *
06001 ACE_OS::gethostbyname_r (const char *name,
06002                          struct hostent *result,
06003                          ACE_HOSTENT_DATA buffer,
06004                          int *h_errnop)
06005 {
06006   ACE_OS_TRACE ("ACE_OS::gethostbyname_r");
06007 #if defined (ACE_PSOS)
06008   ACE_UNUSED_ARG (name);
06009   ACE_UNUSED_ARG (result);
06010   ACE_UNUSED_ARG (buffer);
06011   ACE_UNUSED_ARG (h_errnop);
06012   ACE_NOTSUP_RETURN (0);
06013 # elif defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (UNIXWARE)
06014 #   if defined (DIGITAL_UNIX) || \
06015        (defined (ACE_AIX_MINOR_VERS) && (ACE_AIX_MINOR_VERS > 2))
06016   ACE_UNUSED_ARG (result);
06017   ACE_UNUSED_ARG (buffer);
06018   ACE_UNUSED_ARG (h_errnop);
06019 
06020   // gethostbyname returns thread-specific storage on Digital Unix and
06021   // AIX 4.3
06022   ACE_SOCKCALL_RETURN (::gethostbyname (name), struct hostent *, 0);
06023 #   elif defined (AIX) || defined (HPUX_10)
06024   ::memset (buffer, 0, sizeof (ACE_HOSTENT_DATA));
06025 
06026   if (::gethostbyname_r (name, result, (struct hostent_data *) buffer) == 0)
06027     return result;
06028   else
06029     {
06030       *h_errnop = h_errno;
06031       return (struct hostent *) 0;
06032     }
06033 # elif defined (__GLIBC__)
06034   // GNU C library has a different signature
06035   ::memset (buffer, 0, sizeof (ACE_HOSTENT_DATA));
06036 
06037   if (::gethostbyname_r (name,
06038                          result,
06039                          buffer,
06040                          sizeof (ACE_HOSTENT_DATA),
06041                          &result,
06042                          h_errnop) == 0)
06043     return result;
06044   else
06045     return (struct hostent *) 0;
06046 #   else
06047 #     if defined(ACE_LACKS_NETDB_REENTRANT_FUNCTIONS)
06048   ACE_UNUSED_ARG (result);
06049   ACE_UNUSED_ARG (h_errnop);
06050   ACE_NETDBCALL_RETURN (::gethostbyname (name),
06051                         struct hostent *, 0,
06052                         buffer, sizeof (ACE_HOSTENT_DATA));
06053 #     else
06054   ACE_SOCKCALL_RETURN (::gethostbyname_r (name, result, buffer,
06055                                           sizeof (ACE_HOSTENT_DATA),
06056                                           h_errnop),
06057                        struct hostent *,
06058                        0);
06059 #     endif /* ACE_LACKS_NETDB_REENTRANT_FUNCTIONS */
06060 #   endif /* defined (AIX) || defined (DIGITAL_UNIX) */
06061 # elif defined (ACE_HAS_NONCONST_GETBY)
06062   ACE_UNUSED_ARG (result);
06063   ACE_UNUSED_ARG (buffer);
06064   ACE_UNUSED_ARG (h_errnop);
06065   ACE_SOCKCALL_RETURN (::gethostbyname (ACE_const_cast (char *, name)),
06066                        struct hostent *,
06067                        0);
06068 # else
06069   ACE_UNUSED_ARG (result);
06070   ACE_UNUSED_ARG (buffer);
06071   ACE_UNUSED_ARG (h_errnop);
06072 
06073   ACE_SOCKCALL_RETURN (::gethostbyname (name),
06074                        struct hostent *,
06075                        0);
06076 # endif /* defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (UNIXWARE) */
06077 }
06078 #endif /* ! VXWORKS */
06079 
06080 #if 0
06081 // @@ gets is evil anyway.
06082 //    and it is *** DEPRECATED *** now.  If you
06083 //    really needs gets, use ACE_OS::gets (char*, int)
06084 //    instead.
06085 ACE_INLINE char *
06086 ACE_OS::gets (char *str)
06087 {
06088   ACE_OS_TRACE ("ACE_OS::gets");
06089   ACE_OSCALL_RETURN (::gets (str), char *, 0);
06090 }
06091 #endif /* 0 */
06092 
06093 ACE_INLINE struct servent *
06094 ACE_OS::getservbyname_r (const char *svc,
06095                          const char *proto,
06096                          struct servent *result,
06097                          ACE_SERVENT_DATA buf)
06098 {
06099   ACE_OS_TRACE ("ACE_OS::getservbyname_r");
06100 #if defined (ACE_LACKS_GETSERVBYNAME)
06101   ACE_UNUSED_ARG (svc);
06102   ACE_UNUSED_ARG (proto);
06103   ACE_UNUSED_ARG (result);
06104   ACE_UNUSED_ARG (buf);
06105   ACE_NOTSUP_RETURN (0);
06106 #elif defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (UNIXWARE)
06107 # if defined (AIX) || defined (DIGITAL_UNIX) || defined (HPUX_10)
06108   ::memset (buf, 0, sizeof (ACE_SERVENT_DATA));
06109 
06110   if (::getservbyname_r (svc, proto, result, (struct servent_data *) buf) == 0)
06111     return result;
06112   else
06113     return (struct servent *) 0;
06114 # elif defined (__GLIBC__)
06115   // GNU C library has a different signature
06116   ::memset (buf, 0, sizeof (ACE_SERVENT_DATA));
06117 
06118   if (::getservbyname_r (svc,
06119                          proto,
06120                          result,
06121                          buf,
06122                          sizeof (ACE_SERVENT_DATA),
06123                          &result) == 0)
06124     return result;
06125   else
06126     return (struct servent *) 0;
06127 # else
06128 #   if defined(ACE_LACKS_NETDB_REENTRANT_FUNCTIONS)
06129   ACE_UNUSED_ARG (result);
06130   ACE_NETDBCALL_RETURN (::getservbyname (svc, proto),
06131                         struct servent *, 0,
06132                         buf, sizeof (ACE_SERVENT_DATA));
06133 #   else
06134   ACE_SOCKCALL_RETURN (::getservbyname_r (svc, proto, result, buf,
06135                                           sizeof (ACE_SERVENT_DATA)),
06136                        struct servent *, 0);
06137 #   endif /* ACE_LACKS_NETDB_REENTRANT_FUNCTIONS */
06138 # endif /* defined (AIX) || defined (DIGITAL_UNIX) */
06139 #elif defined (ACE_HAS_NONCONST_GETBY)
06140   ACE_UNUSED_ARG (buf);
06141   ACE_UNUSED_ARG (result);
06142   ACE_SOCKCALL_RETURN (::getservbyname (ACE_const_cast (char *, svc),
06143                                         ACE_const_cast (char *, proto)),
06144                        struct servent *,
06145                        0);
06146 #else
06147   ACE_UNUSED_ARG (buf);
06148   ACE_UNUSED_ARG (result);
06149 
06150   ACE_SOCKCALL_RETURN (::getservbyname (svc,
06151                                         proto),
06152                        struct servent *,
06153                        0);
06154 #endif /* defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (UNIXWARE) */
06155 }
06156 
06157 ACE_INLINE unsigned long
06158 ACE_OS::inet_addr (const char *name)
06159 {
06160   ACE_OS_TRACE ("ACE_OS::inet_addr");
06161 #if defined (VXWORKS) || defined (ACE_PSOS)
06162 
06163   u_long ret = 0;
06164   u_int segment;
06165   u_int valid = 1;
06166 
06167   for (u_int i = 0; i < 4; ++i)
06168     {
06169       ret <<= 8;
06170       if (*name != '\0')
06171         {
06172           segment = 0;
06173 
06174           while (*name >= '0'  &&  *name <= '9')
06175             {
06176               segment *= 10;
06177               segment += *name++ - '0';
06178             }
06179           if (*name != '.' && *name != '\0')
06180             {
06181               valid = 0;
06182               break;
06183             }
06184 
06185           ret |= segment;
06186 
06187           if (*name == '.')
06188             {
06189               ++name;
06190             }
06191         }
06192     }
06193   return valid ? htonl (ret) : INADDR_NONE;
06194 #elif defined (ACE_HAS_NONCONST_GETBY)
06195   return ::inet_addr ((char *) name);
06196 #else
06197   return ::inet_addr (name);
06198 #endif /* ACE_HAS_NONCONST_GETBY */
06199 }
06200 
06201 // For pSOS, this function is in OS.cpp
06202 #if !defined (ACE_PSOS)
06203 ACE_INLINE char *
06204 ACE_OS::inet_ntoa (const struct in_addr addr)
06205 {
06206   ACE_OS_TRACE ("ACE_OS::inet_ntoa");
06207   ACE_OSCALL_RETURN (::inet_ntoa (addr),
06208                      char *,
06209                      0);
06210 }
06211 #endif /* defined (ACE_PSOS) */
06212 
06213 ACE_INLINE int
06214 ACE_OS::inet_pton (int family, const char *strptr, void *addrptr)
06215 {
06216   ACE_OS_TRACE ("ACE_OS::inet_pton");
06217 
06218 #if defined (ACE_HAS_IPV6)
06219   ACE_OSCALL_RETURN (::inet_pton (family, strptr, addrptr), int, -1);
06220 #else
06221   if (family == AF_INET)
06222     {
06223       struct in_addr in_val;
06224 
06225       if (ACE_OS::inet_aton (strptr, &in_val))
06226         {
06227           ACE_OS::memcpy (addrptr, &in_val, sizeof (struct in_addr));
06228           return 1; // Success
06229         }
06230 
06231       return 0; // Input is not a valid presentation format
06232     }
06233 
06234   ACE_NOTSUP_RETURN(-1);
06235 #endif  /* ACE_HAS_IPV6 */
06236 }
06237 
06238 ACE_INLINE const char *
06239 ACE_OS::inet_ntop (int family, const void *addrptr, char *strptr, size_t len)
06240 {
06241   ACE_OS_TRACE ("ACE_OS::inet_ntop");
06242 
06243 #if defined (ACE_HAS_IPV6)
06244   ACE_OSCALL_RETURN (::inet_ntop (family, addrptr, strptr, len), const char *, 0);
06245 #else
06246   const u_char *p =
06247     ACE_reinterpret_cast (const u_char *, addrptr);
06248 
06249   if (family == AF_INET)
06250     {
06251       char temp[INET_ADDRSTRLEN];
06252 
06253       // Stevens uses snprintf() in his implementation but snprintf()
06254       // doesn't appear to be very portable.  For now, hope that using
06255       // sprintf() will not cause any string/memory overrun problems.
06256       ACE_OS::sprintf (temp,
06257                        "%d.%d.%d.%d",
06258                        p[0], p[1], p[2], p[3]);
06259 
06260       if (ACE_OS::strlen (temp) >= len)
06261         {
06262           errno = ENOSPC;
06263           return 0; // Failure
06264         }
06265 
06266       ACE_OS::strcpy (strptr, temp);
06267       return strptr;
06268     }
06269 
06270   ACE_NOTSUP_RETURN(0);
06271 #endif /* ACE_HAS_IPV6 */
06272 }
06273 
06274 ACE_INLINE int
06275 ACE_OS::set_errno_to_last_error (void)
06276 {
06277 # if defined (ACE_WIN32)
06278 // Borland C++ Builder 4 has a bug in the RTL that resets the
06279 // <GetLastError> value to zero when errno is accessed.  Thus, we have
06280 // to use this to set errno to GetLastError.  It's bad, but only for
06281 // WIN32.
06282 #   if defined(__BORLANDC__) && (__BORLANDC__ == 0x540) || defined (__IBMCPP__) && (__IBMCPP__ >= 400)
06283   int last_error = ::GetLastError ();
06284   return errno = last_error;
06285 #   else /* defined(__BORLANDC__) && (__BORLANDC__ == 0x540) */
06286   return errno = ::GetLastError ();
06287 #   endif /* defined(__BORLANDC__) && (__BORLANDC__ == 0x540) */
06288 #else
06289   return errno;
06290 # endif /* defined(ACE_WIN32) */
06291 }
06292 
06293 ACE_INLINE int
06294 ACE_OS::set_errno_to_wsa_last_error (void)
06295 {
06296 # if defined (ACE_WIN32)
06297 // Borland C++ Builder 4 has a bug in the RTL that resets the
06298 // <GetLastError> value to zero when errno is accessed.  Thus, we have
06299 // to use this to set errno to GetLastError.  It's bad, but only for
06300 // WIN32
06301 #   if defined(__BORLANDC__) && (__BORLANDC__ == 0x540) || defined (__IBMCPP__) && (__IBMCPP__ >= 400)
06302   int last_error = ::WSAGetLastError ();
06303   return errno = last_error;
06304 #   else /* defined(__BORLANDC__) && (__BORLANDC__ == 0x540) */
06305   return errno = ::WSAGetLastError ();
06306 #   endif /* defined(__BORLANDC__) && (__BORLANDC__ == 0x540) */
06307 #else
06308   return errno;
06309 # endif /* defined(ACE_WIN32) */
06310 }
06311 
06312 ACE_INLINE int
06313 ACE_OS::last_error (void)
06314 {
06315   // ACE_OS_TRACE ("ACE_OS::last_error");
06316 
06317 #if defined (ACE_WIN32)
06318   int lerror = ::GetLastError ();
06319   int lerrno = errno;
06320   return lerrno == 0 ? lerror : lerrno;
06321 #else
06322   return errno;
06323 #endif /* ACE_WIN32 */
06324 }
06325 
06326 ACE_INLINE void
06327 ACE_OS::last_error (int error)
06328 {
06329   ACE_OS_TRACE ("ACE_OS::last_error");
06330 #if defined (ACE_WIN32)
06331   ::SetLastError (error);
06332 #else
06333   errno = error;
06334 #endif /* ACE_WIN32 */
06335 }
06336 
06337 ACE_INLINE void
06338 ACE_OS::perror (const ACE_TCHAR *s)
06339 {
06340   ACE_OS_TRACE ("ACE_OS::perror");
06341 #if defined (ACE_HAS_WINCE)
06342   // @@ WINCE: How should this be handled
06343   ACE_UNUSED_ARG (s);
06344 #elif defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
06345   ::_wperror (s);
06346 #else
06347   ::perror (s);
06348 #endif /* ACE_HAS_WINCE */
06349 }
06350 
06351 ACE_INLINE int
06352 ACE_OS::puts (const ACE_TCHAR *s)
06353 {
06354   ACE_OS_TRACE ("ACE_OS::puts");
06355 #if defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
06356   ACE_OSCALL_RETURN (::_putws (s), int, -1);
06357 #else /* ACE_WIN32 */
06358   ACE_OSCALL_RETURN (::puts (s), int, -1);
06359 #endif /* ACE_WIN32 && ACE_USES_WCHAR */
06360 }
06361 
06362 ACE_INLINE int
06363 ACE_OS::fputs (const ACE_TCHAR *s, FILE *stream)
06364 {
06365   ACE_OS_TRACE ("ACE_OS::fputs");
06366 #if defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
06367   ACE_OSCALL_RETURN (::fputws (s, stream), int, -1);
06368 #else /* ACE_WIN32 */
06369   ACE_OSCALL_RETURN (::fputs (s, stream), int, -1);
06370 #endif /* ACE_WIN32 && ACE_USES_WCHAR */
06371 }
06372 
06373 ACE_INLINE ACE_SignalHandler
06374 ACE_OS::signal (int signum, ACE_SignalHandler func)
06375 {
06376   if (signum == 0)
06377     return 0;
06378   else
06379 #if defined (ACE_PSOS) && !defined (ACE_PSOS_TM) && !defined (ACE_PSOS_DIAB_MIPS) && !defined (ACE_PSOS_DIAB_PPC)
06380     return (ACE_SignalHandler) ::signal (signum, (void (*)(void)) func);
06381 #elif defined (ACE_PSOS_DIAB_MIPS) || defined (ACE_PSOS_DIAB_PPC)
06382     return 0;
06383 #elif defined (ACE_PSOS_TM)
06384     // @@ It would be good to rework this so the ACE_PSOS_TM specific
06385     //    branch is not needed, but prying it out of ACE_LACKS_UNIX_SIGNALS
06386     //    will take some extra work - deferred for now.
06387     return (ACE_SignalHandler) ::signal (signum, (void (*)(int)) func);
06388 #elif defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) || !defined (ACE_LACKS_UNIX_SIGNALS)
06389 #  if !defined (ACE_HAS_TANDEM_SIGNALS) && !defined (ACE_HAS_LYNXOS_SIGNALS)
06390     return ::signal (signum, func);
06391 #  else
06392     return (ACE_SignalHandler) ::signal (signum, (void (*)(int)) func);
06393 #  endif /* !ACE_HAS_TANDEM_SIGNALS */
06394 #else
06395     // @@ WINCE: Don't know how to implement signal on WinCE (yet.)
06396     ACE_UNUSED_ARG (signum);
06397     ACE_UNUSED_ARG (func);
06398     ACE_NOTSUP_RETURN (0);     // Should return SIG_ERR but it is not defined on WinCE.
06399 #endif /*  ACE_PSOS && !ACE_PSOS_TM && !ACE_PSOS_DIAB_MIPS && !ACE_PSOS_DIAB_PPC */
06400 }
06401 
06402 ACE_INLINE int
06403 ACE_OS::system (const ACE_TCHAR *s)
06404 {
06405   // ACE_OS_TRACE ("ACE_OS::system");
06406 #if defined (CHORUS) || defined (ACE_HAS_WINCE) || defined(ACE_PSOS)
06407   ACE_UNUSED_ARG (s);
06408   ACE_NOTSUP_RETURN (-1);
06409 #elif defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
06410   ACE_OSCALL_RETURN (::_wsystem (s), int, -1);
06411 #else
06412   ACE_OSCALL_RETURN (::system (s), int, -1);
06413 #endif /* !CHORUS */
06414 }
06415 
06416 ACE_INLINE int
06417 ACE_OS::thr_continue (ACE_hthread_t target_thread)
06418 {
06419   ACE_OS_TRACE ("ACE_OS::thr_continue");
06420 #if defined (ACE_HAS_THREADS)
06421 # if defined (ACE_HAS_STHREADS)
06422   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_continue (target_thread), ace_result_), int, -1);
06423 # elif defined (ACE_HAS_PTHREADS)
06424 #  if defined (ACE_HAS_PTHREAD_CONTINUE)
06425   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_continue (target_thread),
06426                                        ace_result_),
06427                      int, -1);
06428 #  else
06429   ACE_UNUSED_ARG (target_thread);
06430   ACE_NOTSUP_RETURN (-1);
06431 #  endif /* ACE_HAS_PTHREAD_CONTINUE */
06432 # elif defined (ACE_HAS_WTHREADS)
06433   DWORD result = ::ResumeThread (target_thread);
06434   if (result == ACE_SYSCALL_FAILED)
06435     ACE_FAIL_RETURN (-1);
06436   else
06437     return 0;
06438 # elif defined (ACE_PSOS)
06439   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::t_resume (target_thread), ace_result_), int, -1);
06440 # elif defined (VXWORKS)
06441   ACE_OSCALL_RETURN (::taskResume (target_thread), int, -1);
06442 # endif /* ACE_HAS_STHREADS */
06443 #else
06444   ACE_UNUSED_ARG (target_thread);
06445   ACE_NOTSUP_RETURN (-1);
06446 #endif /* ACE_HAS_THREADS */
06447 }
06448 
06449 ACE_INLINE int
06450 ACE_OS::thr_cmp (ACE_hthread_t t1, ACE_hthread_t t2)
06451 {
06452 #if defined (ACE_HAS_PTHREADS)
06453 # if defined (pthread_equal)
06454   // If it's a macro we can't say "::pthread_equal"...
06455   return pthread_equal (t1, t2);
06456 # else
06457   return ::pthread_equal (t1, t2);
06458 # endif /* pthread_equal */
06459 #else /* For STHREADS, WTHREADS, and VXWORKS ... */
06460   // Hum, Do we need to treat WTHREAD differently?
06461   // levine 13 oct 98 % Probably, ACE_hthread_t is a HANDLE.
06462   return t1 == t2;
06463 #endif /* ACE_HAS_PTHREADS */
06464 }
06465 
06466 ACE_INLINE int
06467 ACE_OS::thr_getconcurrency (void)
06468 {
06469   ACE_OS_TRACE ("ACE_OS::thr_getconcurrency");
06470 #if defined (ACE_HAS_THREADS)
06471 # if defined (ACE_HAS_STHREADS)
06472   return ::thr_getconcurrency ();
06473 # elif defined (ACE_HAS_PTHREADS) || defined (VXWORKS) || defined (ACE_PSOS)
06474   ACE_NOTSUP_RETURN (-1);
06475 # elif defined (ACE_HAS_WTHREADS)
06476   ACE_NOTSUP_RETURN (-1);
06477 # endif /* ACE_HAS_STHREADS */
06478 #else
06479   ACE_NOTSUP_RETURN (-1);
06480 #endif /* ACE_HAS_THREADS */
06481 }
06482 
06483 ACE_INLINE int
06484 ACE_OS::thr_getprio (ACE_hthread_t id, int &priority, int &policy)
06485 {
06486   ACE_OS_TRACE ("ACE_OS::thr_getprio");
06487   ACE_UNUSED_ARG (policy);
06488 #if defined (ACE_HAS_THREADS)
06489 # if (defined (ACE_HAS_PTHREADS) && !defined (ACE_LACKS_SETSCHED))
06490 
06491 #   if defined (ACE_HAS_PTHREADS_DRAFT4)
06492   int result;
06493   result = ::pthread_getprio (id);
06494   if (result != -1)
06495     {
06496       priority = result;
06497       return 0;
06498     }
06499   else
06500     return -1;
06501 #   elif defined (ACE_HAS_PTHREADS_DRAFT6)
06502 
06503   pthread_attr_t  attr;
06504   if (pthread_getschedattr (id, &attr) == 0)
06505     {
06506       priority = pthread_attr_getprio(&attr);
06507       return 0;
06508     }
06509   return -1;
06510 #   else
06511 
06512   struct sched_param param;
06513   int result;
06514 
06515   ACE_OSCALL (ACE_ADAPT_RETVAL (::pthread_getschedparam (id, &policy, &param),
06516                                 result), int,
06517               -1, result);
06518   priority = param.sched_priority;
06519   return result;
06520 #   endif /* ACE_HAS_PTHREADS_DRAFT4 */
06521 # elif defined (ACE_HAS_STHREADS)
06522   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_getprio (id, &priority), ace_result_), int, -1);
06523 # elif defined (ACE_HAS_WTHREADS)
06524   priority = ::GetThreadPriority (id);
06525   if (priority == THREAD_PRIORITY_ERROR_RETURN)
06526     ACE_FAIL_RETURN (-1);
06527   else
06528     return 0;
06529 # elif defined (ACE_PSOS)
06530   // passing a 0 in the second argument does not alter task priority, third arg gets existing one
06531   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::t_setpri (id, 0, (u_long *) &priority), ace_result_), int, -1);
06532 # elif defined (VXWORKS)
06533   ACE_OSCALL_RETURN (::taskPriorityGet (id, &priority), int, -1);
06534 # else
06535   ACE_UNUSED_ARG (id);
06536   ACE_UNUSED_ARG (priority);
06537   ACE_NOTSUP_RETURN (-1);
06538 # endif /* ACE_HAS_STHREADS */
06539 #else
06540   ACE_UNUSED_ARG (id);
06541   ACE_UNUSED_ARG (priority);
06542   ACE_NOTSUP_RETURN (-1);
06543 #endif /* ACE_HAS_THREADS */
06544 }
06545 
06546 ACE_INLINE int
06547 ACE_OS::thr_getprio (ACE_hthread_t id, int &priority)
06548 {
06549   ACE_OS_TRACE ("ACE_OS::thr_getprio");
06550   int policy = 0;
06551   return ACE_OS::thr_getprio (id, priority, policy);
06552 }
06553 
06554 #if defined (ACE_HAS_TSS_EMULATION)
06555 
06556 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
06557 ACE_INLINE int
06558 ACE_OS::thr_getspecific (ACE_OS_thread_key_t key, void **data)
06559 {
06560   ACE_OS_TRACE ("ACE_OS::thr_getspecific");
06561 #  if defined (ACE_HAS_THREADS)
06562 #   if defined (ACE_HAS_PTHREADS)
06563 #    if defined (ACE_HAS_PTHREADS_DRAFT4) || defined (ACE_HAS_PTHREADS_DRAFT6)
06564     return pthread_getspecific (key, data);
06565 #    else /* this is ACE_HAS_PTHREADS_DRAFT7 or STD */
06566 #     if (pthread_getspecific)
06567     // This is a macro on some platforms, e.g., CHORUS!
06568     *data = pthread_getspecific (key);
06569 #     else
06570     *data = pthread_getspecific (key);
06571 #     endif /* pthread_getspecific */
06572 #    endif       /*  ACE_HAS_PTHREADS_DRAFT4, 6 */
06573     return 0;
06574 #   elif defined (ACE_HAS_STHREADS)
06575     ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_getspecific (key, data), ace_result_), int, -1);
06576 #   elif defined (ACE_PSOS) && defined (ACE_PSOS_HAS_TSS)
06577     ACE_hthread_t tid;
06578     ACE_OS::thr_self (tid);
06579     return (::tsd_getval (key, tid, data) == 0) ? 0 : -1;
06580 #   elif defined (ACE_HAS_WTHREADS)
06581 
06582   // The following handling of errno is designed like this due to
06583   // ACE_Log_Msg::instance calling ACE_OS::thr_getspecific.
06584   // Basically, it is ok for a system call to reset the error to zero.
06585   // (It really shouldn't, though).  However, we have to remember to
06586   // store errno *immediately* after an error is detected.  Calling
06587   // ACE_ERROR_RETURN((..., errno)) did not work because errno was
06588   // cleared before being passed to the thread-specific instance of
06589   // ACE_Log_Msg.  The workaround for was to make it so
06590   // thr_getspecific did not have the side effect of clearing errno.
06591   // The correct fix is for ACE_ERROR_RETURN to store errno
06592   //(actually ACE_OS::last_error) before getting the ACE_Log_Msg tss
06593   // pointer, which is how it is implemented now.  However, other uses
06594   // of ACE_Log_Msg may not work correctly, so we're keeping this as
06595   // it is for now.
06596 
06597   ACE_Errno_Guard error (errno);
06598   *data = ::TlsGetValue (key);
06599 #    if !defined (ACE_HAS_WINCE)
06600   if (*data == 0 && (error = ::GetLastError ()) != NO_ERROR)
06601     return -1;
06602   else
06603 #    endif /* ACE_HAS_WINCE */
06604     return 0;
06605 #   endif /* ACE_HAS_STHREADS */
06606 #  else
06607   ACE_UNUSED_ARG (key);
06608   ACE_UNUSED_ARG (data);
06609   ACE_NOTSUP_RETURN (-1);
06610 #  endif /* ACE_HAS_THREADS */
06611 }
06612 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
06613 
06614 # if !defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
06615 ACE_INLINE
06616 void **&
06617 ACE_TSS_Emulation::tss_base ()
06618 {
06619 #  if defined (VXWORKS)
06620   return (void **&) taskIdCurrent->ACE_VXWORKS_SPARE;
06621 #  elif defined (ACE_PSOS)
06622   // not supported
06623   long x=0;   //JINLU
06624   return (void **&) x;
06625 #  else
06626   // Uh oh.
06627   ACE_NOTSUP_RETURN (0);
06628 #  endif /* VXWORKS */
06629 }
06630 # endif /* ! ACE_HAS_THREAD_SPECIFIC_STORAGE */
06631 
06632 ACE_INLINE
06633 ACE_TSS_Emulation::ACE_TSS_DESTRUCTOR
06634 ACE_TSS_Emulation::tss_destructor (const ACE_thread_key_t key)
06635 {
06636   ACE_KEY_INDEX (key_index, key);
06637   return tss_destructor_ [key_index];
06638 }
06639 
06640 ACE_INLINE
06641 void
06642 ACE_TSS_Emulation::tss_destructor (const ACE_thread_key_t key,
06643                                    ACE_TSS_DESTRUCTOR destructor)
06644 {
06645   ACE_KEY_INDEX (key_index, key);
06646   tss_destructor_ [key_index] = destructor;
06647 }
06648 
06649 ACE_INLINE
06650 void *&
06651 ACE_TSS_Emulation::ts_object (const ACE_thread_key_t key)
06652 {
06653   ACE_KEY_INDEX (key_index, key);
06654 
06655 #if defined (ACE_PSOS)
06656   u_long tss_base;
06657   t_getreg (0, PSOS_TASK_REG_TSS, &tss_base);
06658   return ((void **) tss_base)[key_index];
06659 #else
06660 # if defined (VXWORKS)
06661     /* If someone wants tss_base make sure they get one.  This
06662        gets used if someone spawns a VxWorks task directly, not
06663        through ACE.  The allocated array will never be deleted! */
06664     if (0 == taskIdCurrent->ACE_VXWORKS_SPARE)
06665       {
06666         taskIdCurrent->ACE_VXWORKS_SPARE =
06667           ACE_reinterpret_cast (int, new void *[ACE_TSS_THREAD_KEYS_MAX]);
06668 
06669         // Zero the entire TSS array.  Do it manually instead of using
06670         // memset, for optimum speed.  Though, memset may be faster :-)
06671         void **tss_base_p =
06672           ACE_reinterpret_cast (void **, taskIdCurrent->ACE_VXWORKS_SPARE);
06673         for (u_int i = 0; i < ACE_TSS_THREAD_KEYS_MAX; ++i, ++tss_base_p)
06674           {
06675             *tss_base_p = 0;
06676           }
06677       }
06678 #     endif /* VXWORKS */
06679 
06680   return tss_base ()[key_index];
06681 #endif /* defined (ACE_PSOS) */
06682 }
06683 
06684 #endif /* ACE_HAS_TSS_EMULATION */
06685 
06686 
06687 ACE_INLINE int
06688 ACE_OS::thr_getspecific (ACE_thread_key_t key, void **data)
06689 {
06690   // ACE_OS_TRACE ("ACE_OS::thr_getspecific");
06691 #if defined (ACE_HAS_THREADS)
06692 # if defined (ACE_HAS_TSS_EMULATION)
06693     ACE_KEY_INDEX (key_index, key);
06694     if (key_index >= ACE_TSS_Emulation::total_keys ())
06695       {
06696         errno = EINVAL;
06697         data = 0;
06698         return -1;
06699       }
06700     else
06701       {
06702         *data = ACE_TSS_Emulation::ts_object (key);
06703         return 0;
06704       }
06705 # elif defined (ACE_HAS_STHREADS)
06706     ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_getspecific (key, data), ace_result_), int, -1);
06707 # elif defined (ACE_HAS_PTHREADS)
06708 #   if defined (ACE_HAS_PTHREADS_DRAFT4) || defined (ACE_HAS_PTHREADS_DRAFT6)
06709       return ::pthread_getspecific (key, data);
06710 #   else /* this is Draft 7 or STD */
06711       *data = pthread_getspecific (key);
06712       return 0;
06713 #   endif       /*  ACE_HAS_PTHREADS_DRAFT4, 6 */
06714 # elif defined (ACE_HAS_WTHREADS)
06715 
06716   // The following handling of errno is designed like this due to
06717   // ACE_Log_Msg::instance calling ACE_OS::thr_getspecific.
06718   // Basically, it is ok for a system call to reset the error to zero.
06719   // (It really shouldn't, though).  However, we have to remember to
06720   // store errno *immediately* after an error is detected.  Calling
06721   // ACE_ERROR_RETURN((..., errno)) did not work because errno was
06722   // cleared before being passed to the thread-specific instance of
06723   // ACE_Log_Msg.  The workaround for was to make it so
06724   // thr_getspecific did not have the side effect of clearing errno.
06725   // The correct fix is for ACE_ERROR_RETURN to store errno
06726   //(actually ACE_OS::last_error) before getting the ACE_Log_Msg tss
06727   // pointer, which is how it is implemented now.  However, other uses
06728   // of ACE_Log_Msg may not work correctly, so we're keeping this as
06729   // it is for now.
06730 
06731   ACE_Errno_Guard error (errno);
06732   *data = ::TlsGetValue (key);
06733 #   if !defined (ACE_HAS_WINCE)
06734   if (*data == 0 && (error = ::GetLastError ()) != NO_ERROR)
06735 
06736     return -1;
06737   else
06738 #   endif /* ACE_HAS_WINCE */
06739     return 0;
06740 # elif defined (ACE_PSOS) && defined (ACE_PSOS_HAS_TSS)
06741   ACE_hthread_t tid;
06742   ACE_OS::thr_self (tid);
06743   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::tsd_getval (key, tid, data),
06744                                        ace_result_),
06745                      int, -1);
06746 # else
06747   ACE_UNUSED_ARG (key);
06748   ACE_UNUSED_ARG (data);
06749   ACE_NOTSUP_RETURN (-1);
06750 # endif /* ACE_HAS_STHREADS */
06751 #else
06752   ACE_UNUSED_ARG (key);
06753   ACE_UNUSED_ARG (data);
06754   ACE_NOTSUP_RETURN (-1);
06755 #endif /* ACE_HAS_THREADS */
06756 }
06757 
06758 #if !defined (VXWORKS)
06759 ACE_INLINE int
06760 ACE_OS::thr_join (ACE_hthread_t thr_handle,
06761                   ACE_THR_FUNC_RETURN *status)
06762 {
06763   ACE_OS_TRACE ("ACE_OS::thr_join");
06764 #if defined (ACE_HAS_THREADS)
06765 # if defined (ACE_HAS_STHREADS)
06766   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_join (thr_handle, 0, status), ace_result_),
06767                      int, -1);
06768 # elif defined (ACE_HAS_PTHREADS)
06769 #   if defined (ACE_HAS_PTHREADS_DRAFT4) || defined (ACE_HAS_PTHREADS_DRAFT6)
06770   int ace_result;
06771 #     if defined (ACE_LACKS_NULL_PTHREAD_STATUS)
06772   void *temp;
06773   ACE_OSCALL (::pthread_join (thr_handle,
06774                               status == 0  ?  &temp  :  status),
06775               int, -1, ace_result);
06776 #     else
06777   ACE_OSCALL (::pthread_join (thr_handle, status), int, -1, ace_result);
06778 #     endif /* ACE_LACKS_NULL_PTHREAD_STATUS */
06779   // Joinable threads need to be detached after joining on Pthreads
06780   // draft 4 (at least) to reclaim thread storage.
06781 #     if defined (ACE_HAS_PTHREADS_DRAFT4)
06782 #       if defined (HPUX_10)
06783   // HP-UX DCE threads' pthread_detach will smash thr_id if it's just given
06784   // as an argument.  Since the id is still needed, give pthread_detach
06785   // a junker to scribble on.
06786   ACE_thread_t  junker;
06787   cma_handle_assign(&thr_handle, &junker);
06788   ::pthread_detach (&junker);
06789 #       else
06790   ::pthread_detach (&thr_handle);
06791 #       endif  /* HPUX_10 */
06792 #     endif /* ACE_HAS_PTHREADS_DRAFT4 */
06793 
06794     return ace_result;
06795 
06796 #   else
06797   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_join (thr_handle, status), ace_result_),
06798                      int, -1);
06799 #   endif /* ACE_HAS_PTHREADS_DRAFT4, 6 */
06800 # elif defined (ACE_HAS_WTHREADS)
06801   ACE_THR_FUNC_RETURN local_status = 0;
06802 
06803   // Make sure that status is non-NULL.
06804   if (status == 0)
06805     status = &local_status;
06806 
06807   if (::WaitForSingleObject (thr_handle, INFINITE) == WAIT_OBJECT_0
06808       && ::GetExitCodeThread (thr_handle, status) != FALSE)
06809     {
06810       ::CloseHandle (thr_handle);
06811       return 0;
06812     }
06813   ACE_FAIL_RETURN (-1);
06814   /* NOTREACHED */
06815 # elif defined (ACE_PSOS)
06816   ACE_UNUSED_ARG (thr_handle);
06817   ACE_UNUSED_ARG (status);
06818   ACE_NOTSUP_RETURN (-1);
06819 # else
06820   ACE_UNUSED_ARG (thr_handle);
06821   ACE_UNUSED_ARG (status);
06822   ACE_NOTSUP_RETURN (-1);
06823 # endif /* ACE_HAS_STHREADS */
06824 #else
06825   ACE_UNUSED_ARG (thr_handle);
06826   ACE_UNUSED_ARG (status);
06827   ACE_NOTSUP_RETURN (-1);
06828 #endif /* ACE_HAS_THREADS */
06829 }
06830 
06831 ACE_INLINE int
06832 ACE_OS::thr_join (ACE_thread_t waiter_id,
06833                   ACE_thread_t *thr_id,
06834                   ACE_THR_FUNC_RETURN *status)
06835 {
06836   ACE_OS_TRACE ("ACE_OS::thr_join");
06837 #if defined (ACE_HAS_THREADS)
06838 # if defined (ACE_HAS_STHREADS)
06839   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_join (waiter_id, thr_id, status), ace_result_),
06840                      int, -1);
06841 # elif defined (ACE_HAS_PTHREADS)
06842   ACE_UNUSED_ARG (thr_id);
06843 #   if defined (ACE_HAS_PTHREADS_DRAFT4) || defined (ACE_HAS_PTHREADS_DRAFT6)
06844 #     if defined (ACE_LACKS_NULL_PTHREAD_STATUS)
06845   void *temp;
06846   ACE_OSCALL_RETURN (::pthread_join (waiter_id,
06847     status == 0  ?  &temp  :  status), int, -1);
06848 #     else
06849   ACE_OSCALL_RETURN (::pthread_join (waiter_id, status), int, -1);
06850 #     endif
06851 #   else
06852   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_join (waiter_id, status), ace_result_),
06853                      int, -1);
06854 #   endif /* ACE_HAS_PTHREADS_DRAFT4, 6 */
06855 # elif defined (ACE_HAS_WTHREADS)
06856   ACE_UNUSED_ARG (waiter_id);
06857   ACE_UNUSED_ARG (thr_id);
06858   ACE_UNUSED_ARG (status);
06859 
06860   // This could be implemented if the DLL-Main function or the
06861   // task exit base class some log the threads which have exited
06862   ACE_NOTSUP_RETURN (-1);
06863 # elif defined (ACE_PSOS)
06864   ACE_UNUSED_ARG (waiter_id);
06865   ACE_UNUSED_ARG (thr_id);
06866   ACE_UNUSED_ARG (status);
06867   ACE_NOTSUP_RETURN (-1);
06868 # endif /* ACE_HAS_STHREADS */
06869 #else
06870   ACE_UNUSED_ARG (waiter_id);
06871   ACE_UNUSED_ARG (thr_id);
06872   ACE_UNUSED_ARG (status);
06873   ACE_NOTSUP_RETURN (-1);
06874 #endif /* ACE_HAS_THREADS */
06875 }
06876 #endif /* !VXWORKS */
06877 
06878 ACE_INLINE int
06879 ACE_OS::thr_setcancelstate (int new_state, int *old_state)
06880 {
06881   ACE_OS_TRACE ("ACE_OS::thr_setcancelstate");
06882 #if defined (ACE_HAS_THREADS)
06883 # if defined (ACE_HAS_PTHREADS) && !defined (ACE_LACKS_PTHREAD_CANCEL)
06884 #   if defined (ACE_HAS_PTHREADS_DRAFT4)
06885   int old;
06886   old = pthread_setcancel (new_state);
06887   if (old == -1)
06888     return -1;
06889   *old_state = old;
06890   return 0;
06891 #   elif defined (ACE_HAS_PTHREADS_DRAFT6)
06892   ACE_UNUSED_ARG(old_state);
06893   ACE_OSCALL_RETURN (pthread_setintr (new_state), int, -1);
06894 #   else /* this is draft 7 or std */
06895   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_setcancelstate (new_state,
06896                                                                  old_state),
06897                                        ace_result_),
06898                      int, -1);
06899 #   endif /* ACE_HAS_PTHREADS_DRAFT4 */
06900 # elif defined (ACE_HAS_STHREADS)
06901   ACE_UNUSED_ARG (new_state);
06902   ACE_UNUSED_ARG (old_state);
06903   ACE_NOTSUP_RETURN (-1);
06904 # elif defined (ACE_HAS_WTHREADS)
06905   ACE_UNUSED_ARG (new_state);
06906   ACE_UNUSED_ARG (old_state);
06907   ACE_NOTSUP_RETURN (-1);
06908 # else /* Could be ACE_HAS_PTHREADS && ACE_LACKS_PTHREAD_CANCEL */
06909   ACE_UNUSED_ARG (new_state);
06910   ACE_UNUSED_ARG (old_state);
06911   ACE_NOTSUP_RETURN (-1);
06912 # endif /* ACE_HAS_PTHREADS */
06913 #else
06914   ACE_UNUSED_ARG (new_state);
06915   ACE_UNUSED_ARG (old_state);
06916   ACE_NOTSUP_RETURN (-1);
06917 #endif /* ACE_HAS_THREADS */
06918 }
06919 
06920 ACE_INLINE int
06921 ACE_OS::thr_setcanceltype (int new_type, int *old_type)
06922 {
06923   ACE_OS_TRACE ("ACE_OS::thr_setcanceltype");
06924 #if defined (ACE_HAS_THREADS)
06925 # if defined (ACE_HAS_PTHREADS) && !defined (ACE_LACKS_PTHREAD_CANCEL)
06926 #   if defined (ACE_HAS_PTHREADS_DRAFT4)
06927   int old;
06928   old = pthread_setasynccancel(new_type);
06929   if (old == -1)
06930     return -1;
06931   *old_type = old;
06932   return 0;
06933 #   elif defined (ACE_HAS_PTHREADS_DRAFT6)
06934   ACE_UNUSED_ARG(old_type);
06935   ACE_OSCALL_RETURN (pthread_setintrtype (new_type), int, -1);
06936 #   else /* this is draft 7 or std */
06937   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_setcanceltype (new_type,
06938                                                                 old_type),
06939                                        ace_result_),
06940                      int, -1);
06941 #   endif /* ACE_HAS_PTHREADS_DRAFT4 */
06942 # else /* Could be ACE_HAS_PTHREADS && ACE_LACKS_PTHREAD_CANCEL */
06943   ACE_UNUSED_ARG (new_type);
06944   ACE_UNUSED_ARG (old_type);
06945   ACE_NOTSUP_RETURN (-1);
06946 # endif /* ACE_HAS_PTHREADS */
06947 #else
06948   ACE_UNUSED_ARG (new_type);
06949   ACE_UNUSED_ARG (old_type);
06950   ACE_NOTSUP_RETURN (-1);
06951 #endif /* ACE_HAS_THREADS */
06952 }
06953 
06954 ACE_INLINE int
06955 ACE_OS::thr_cancel (ACE_thread_t thr_id)
06956 {
06957   ACE_OS_TRACE ("ACE_OS::thr_cancel");
06958 #if defined (ACE_HAS_THREADS)
06959 # if defined (ACE_HAS_PTHREADS) && !defined (ACE_LACKS_PTHREAD_CANCEL)
06960 #   if defined (ACE_HAS_PTHREADS_DRAFT4) || defined (ACE_HAS_PTHREADS_DRAFT6)
06961   ACE_OSCALL_RETURN (::pthread_cancel (thr_id), int, -1);
06962 #   else
06963   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_cancel (thr_id),
06964                                        ace_result_),
06965                      int, -1);
06966 #   endif /* ACE_HAS_PTHREADS_DRAFT4 || ACE_HAS_PTHREADS_DRAFT6 */
06967 # else /* Could be ACE_HAS_PTHREADS && ACE_LACKS_PTHREAD_CANCEL */
06968   ACE_UNUSED_ARG (thr_id);
06969   ACE_NOTSUP_RETURN (-1);
06970 # endif /* ACE_HAS_PTHREADS */
06971 #else
06972   ACE_UNUSED_ARG (thr_id);
06973   ACE_NOTSUP_RETURN (-1);
06974 #endif /* ACE_HAS_THREADS */
06975 }
06976 
06977 ACE_INLINE int
06978 ACE_OS::sigwait (sigset_t *sset, int *sig)
06979 {
06980   ACE_OS_TRACE ("ACE_OS::sigwait");
06981   int local_sig;
06982   if (sig == 0)
06983     sig = &local_sig;
06984 #if defined (ACE_HAS_THREADS)
06985 # if (defined (__FreeBSD__) && (__FreeBSD__ < 3)) || defined (CHORUS) || defined (ACE_PSOS)
06986     ACE_UNUSED_ARG (sset);
06987     ACE_NOTSUP_RETURN (-1);
06988 # elif (defined (ACE_HAS_STHREADS) && !defined (_POSIX_PTHREAD_SEMANTICS))
06989     *sig = ::sigwait (sset);
06990     return *sig;
06991 # elif defined (ACE_HAS_PTHREADS)
06992   // LynxOS and Digital UNIX have their own hoops to jump through.
06993 #   if defined (__Lynx__)
06994     // Second arg is a void **, which we don't need (the selected
06995     // signal number is returned).
06996     *sig = ::sigwait (sset, 0);
06997     return *sig;
06998 #   elif defined (DIGITAL_UNIX)  &&  defined (__DECCXX_VER)
06999       // DEC cxx (but not g++) needs this direct call to its internal
07000       // sigwait ().  This allows us to #undef sigwait, so that we can
07001       // have ACE_OS::sigwait.  cxx gets confused by ACE_OS::sigwait
07002       // if sigwait is _not_ #undef'ed.
07003       errno = ::_Psigwait (sset, sig);
07004       return errno == 0  ?  *sig  :  -1;
07005 #   else /* ! __Lynx __ && ! (DIGITAL_UNIX && __DECCXX_VER) */
07006 #     if (defined (ACE_HAS_PTHREADS_DRAFT4) || (defined (ACE_HAS_PTHREADS_DRAFT6)) && !defined(ACE_HAS_FSU_PTHREADS)) || (defined (_UNICOS) && _UNICOS == 9)
07007 #       if defined (HPUX_10)
07008         *sig = cma_sigwait (sset);
07009 #       else
07010         *sig = ::sigwait (sset);
07011 #       endif  /* HPUX_10 */
07012         return *sig;
07013 #     elif defined(ACE_HAS_FSU_PTHREADS)
07014         return ::sigwait (sset, sig);
07015 #     else   /* this is draft 7 or std */
07016         errno = ::sigwait (sset, sig);
07017         return errno == 0  ?  *sig  :  -1;
07018 #     endif /* ACE_HAS_PTHREADS_DRAFT4, 6 */
07019 #   endif /* ! __Lynx__ && ! (DIGITAL_UNIX && __DECCXX_VER) */
07020 # elif defined (ACE_HAS_WTHREADS)
07021     ACE_UNUSED_ARG (sset);
07022     ACE_NOTSUP_RETURN (-1);
07023 # elif defined (VXWORKS)
07024     // Second arg is a struct siginfo *, which we don't need (the
07025     // selected signal number is returned).  Third arg is timeout:  0
07026     // means forever.
07027     *sig = ::sigtimedwait (sset, 0, 0);
07028     return *sig;
07029 # endif /* __FreeBSD__ */
07030 #else
07031     ACE_UNUSED_ARG (sset);
07032     ACE_UNUSED_ARG (sig);
07033     ACE_NOTSUP_RETURN (-1);
07034 #endif /* ACE_HAS_THREADS */
07035 }
07036 
07037 ACE_INLINE int
07038 ACE_OS::sigtimedwait (const sigset_t *sset,
07039                       siginfo_t *info,
07040                       const ACE_Time_Value *timeout)
07041 {
07042   ACE_OS_TRACE ("ACE_OS::sigtimedwait");
07043 #if defined (ACE_HAS_SIGTIMEDWAIT)
07044   timespec_t ts;
07045   timespec_t *tsp;
07046 
07047   if (timeout != 0)
07048     {
07049       ts = *timeout; // Calls ACE_Time_Value::operator timespec_t().
07050       tsp = &ts;
07051     }
07052   else
07053     tsp = 0;
07054 
07055   ACE_OSCALL_RETURN (::sigtimedwait (sset, info, tsp),
07056                      int, -1);
07057 #else
07058     ACE_UNUSED_ARG (sset);
07059     ACE_UNUSED_ARG (info);
07060     ACE_UNUSED_ARG (timeout);
07061     ACE_NOTSUP_RETURN (-1);
07062 #endif /* ACE_HAS_SIGTIMEDWAIT */
07063 }
07064 
07065 ACE_INLINE int
07066 ACE_OS::sigwaitinfo (const sigset_t *sset,
07067                      siginfo_t *info)
07068 {
07069   ACE_OS_TRACE ("ACE_OS::sigwaitinfo");
07070   // If this platform has sigtimedwait, it should have sigwaitinfo as well.
07071   // If this isn't true somewhere, let me know and I'll fix this.
07072   // -Steve Huston <shuston@riverace.com>.
07073 #if defined (ACE_HAS_SIGTIMEDWAIT)
07074   ACE_OSCALL_RETURN (::sigwaitinfo (sset, info), int, -1);
07075 #else
07076   ACE_UNUSED_ARG (sset);
07077   ACE_UNUSED_ARG (info);
07078   ACE_NOTSUP_RETURN (-1);
07079 #endif /* ACE_HAS_SIGTIMEDWAIT */
07080 }
07081 
07082 ACE_INLINE void
07083 ACE_OS::thr_testcancel (void)
07084 {
07085   ACE_OS_TRACE ("ACE_OS::thr_testcancel");
07086 #if defined (ACE_HAS_THREADS)
07087 # if defined (ACE_HAS_PTHREADS) && !defined (ACE_LACKS_PTHREAD_CANCEL)
07088 #if defined(ACE_HAS_PTHREADS_DRAFT6)
07089   ::pthread_testintr ();
07090 #else /* ACE_HAS_PTHREADS_DRAFT6 */
07091   ::pthread_testcancel ();
07092 #endif /* !ACE_HAS_PTHREADS_DRAFT6 */
07093 # elif defined (ACE_HAS_STHREADS)
07094 # elif defined (ACE_HAS_WTHREADS)
07095 # elif defined (VXWORKS) || defined (ACE_PSOS)
07096 # else
07097   // no-op:  can't use ACE_NOTSUP_RETURN because there is no return value
07098 # endif /* ACE_HAS_PTHREADS */
07099 #else
07100 #endif /* ACE_HAS_THREADS */
07101 }
07102 
07103 ACE_INLINE int
07104 ACE_OS::thr_sigsetmask (int how,
07105                         const sigset_t *nsm,
07106                         sigset_t *osm)
07107 {
07108   ACE_OS_TRACE ("ACE_OS::thr_sigsetmask");
07109 #if defined (ACE_HAS_THREADS)
07110 # if defined (ACE_LACKS_PTHREAD_THR_SIGSETMASK)
07111   // DCE threads and Solaris 2.4 have no such function.
07112   ACE_UNUSED_ARG (osm);
07113   ACE_UNUSED_ARG (nsm);
07114   ACE_UNUSED_ARG (how);
07115 
07116   ACE_NOTSUP_RETURN (-1);
07117 # elif defined (ACE_HAS_SIGTHREADMASK)
07118   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sigthreadmask (how, nsm, osm),
07119                                        ace_result_), int, -1);
07120 # elif defined (ACE_HAS_STHREADS)
07121   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_sigsetmask (how, nsm, osm),
07122                                        ace_result_),
07123                      int, -1);
07124 # elif defined (ACE_HAS_PTHREADS)
07125 #   if defined (AIX)
07126   ACE_OSCALL_RETURN (sigthreadmask (how, nsm, osm), int, -1);
07127   // Draft 4 and 6 implementations will sometimes have a sigprocmask () that
07128   // modifies the calling thread's mask only.  If this is not so for your
07129   // platform, define ACE_LACKS_PTHREAD_THR_SIGSETMASK.
07130 #   elif defined(ACE_HAS_PTHREADS_DRAFT4) || \
07131     defined (ACE_HAS_PTHREADS_DRAFT6) || (defined (_UNICOS) && _UNICOS == 9)
07132   ACE_OSCALL_RETURN (::sigprocmask (how, nsm, osm), int, -1);
07133 #   elif !defined (ACE_LACKS_PTHREAD_SIGMASK)
07134   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_sigmask (how, nsm, osm),
07135                                        ace_result_), int, -1);
07136 #   endif /* AIX */
07137 
07138 #if 0
07139   /* Don't know if anyt platform actually needs this... */
07140   // as far as I can tell, this is now pthread_sigaction() -- jwr
07141   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_sigaction (how, nsm, osm),
07142                                        ace_result_), int, -1);
07143 #endif /* 0 */
07144 
07145 # elif defined (ACE_HAS_WTHREADS) || defined (ACE_PSOS)
07146   ACE_UNUSED_ARG (osm);
07147   ACE_UNUSED_ARG (nsm);
07148   ACE_UNUSED_ARG (how);
07149 
07150   ACE_NOTSUP_RETURN (-1);
07151 # elif defined (VXWORKS)
07152   switch (how)
07153     {
07154     case SIG_BLOCK:
07155     case SIG_UNBLOCK:
07156       {
07157         // get the old mask
07158         *osm = ::sigsetmask (*nsm);
07159         // create a new mask:  the following assumes that sigset_t is 4 bytes,
07160         // which it is on VxWorks 5.2, so bit operations are done simply . . .
07161         ::sigsetmask (how == SIG_BLOCK ? (*osm |= *nsm) : (*osm &= ~*nsm));
07162         break;
07163       }
07164     case SIG_SETMASK:
07165       *osm = ::sigsetmask (*nsm);
07166       break;
07167     default:
07168       return -1;
07169     }
07170 
07171   return 0;
07172 # else /* Should not happen. */
07173   ACE_UNUSED_ARG (how);
07174   ACE_UNUSED_ARG (nsm);
07175   ACE_UNUSED_ARG (osm);
07176   ACE_NOTSUP_RETURN (-1);
07177 # endif /* ACE_LACKS_PTHREAD_THR_SIGSETMASK */
07178 #else
07179   ACE_UNUSED_ARG (how);
07180   ACE_UNUSED_ARG (nsm);
07181   ACE_UNUSED_ARG (osm);
07182   ACE_NOTSUP_RETURN (-1);
07183 #endif /* ACE_HAS_THREADS */
07184 }
07185 
07186 ACE_INLINE int
07187 ACE_OS::thr_kill (ACE_thread_t thr_id, int signum)
07188 {
07189   ACE_OS_TRACE ("ACE_OS::thr_kill");
07190 #if defined (ACE_HAS_THREADS)
07191 # if defined (ACE_HAS_PTHREADS)
07192 #   if defined (ACE_HAS_PTHREADS_DRAFT4) || defined(ACE_LACKS_PTHREAD_KILL)
07193   ACE_UNUSED_ARG (signum);
07194   ACE_UNUSED_ARG (thr_id);
07195   ACE_NOTSUP_RETURN (-1);
07196 #   else
07197   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_kill (thr_id, signum),
07198                                        ace_result_),
07199                      int, -1);
07200 #   endif /* ACE_HAS_PTHREADS_DRAFT4 */
07201 # elif defined (ACE_HAS_STHREADS)
07202   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_kill (thr_id, signum),
07203                                        ace_result_),
07204                      int, -1);
07205 # elif defined (ACE_HAS_WTHREADS) || defined (ACE_PSOS)
07206   ACE_UNUSED_ARG (signum);
07207   ACE_UNUSED_ARG (thr_id);
07208 
07209   ACE_NOTSUP_RETURN (-1);
07210 # elif defined (VXWORKS)
07211   ACE_hthread_t tid;
07212   ACE_OSCALL (::taskNameToId (thr_id), int, ERROR, tid);
07213 
07214   if (tid == ERROR)
07215     return -1;
07216   else
07217     ACE_OSCALL_RETURN (::kill (tid, signum), int, -1);
07218 
07219 # else /* This should not happen! */
07220   ACE_UNUSED_ARG (thr_id);
07221   ACE_UNUSED_ARG (signum);
07222   ACE_NOTSUP_RETURN (-1);
07223 # endif /* ACE_HAS_STHREADS */
07224 #else
07225   ACE_UNUSED_ARG (thr_id);
07226   ACE_UNUSED_ARG (signum);
07227   ACE_NOTSUP_RETURN (-1);
07228 #endif /* ACE_HAS_THREADS */
07229 }
07230 
07231 ACE_INLINE size_t
07232 ACE_OS::thr_min_stack (void)
07233 {
07234   ACE_OS_TRACE ("ACE_OS::thr_min_stack");
07235 #if defined (ACE_HAS_THREADS)
07236 # if defined (ACE_HAS_STHREADS)
07237 #   if defined (ACE_HAS_THR_MINSTACK)
07238   // Tandem did some weirdo mangling of STHREAD names...
07239   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_minstack (),
07240                                        ace_result_),
07241                      int, -1);
07242 #   else
07243   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_min_stack (),
07244                                        ace_result_),
07245                      int, -1);
07246 #   endif /* !ACE_HAS_THR_MINSTACK */
07247 # elif defined (ACE_HAS_PTHREADS)
07248 #   if defined (_SC_THREAD_STACK_MIN)
07249   return (size_t) ACE_OS::sysconf (_SC_THREAD_STACK_MIN);
07250 #   elif defined (PTHREAD_STACK_MIN)
07251   return PTHREAD_STACK_MIN;
07252 #   else
07253   ACE_NOTSUP_RETURN (0);
07254 #   endif /* _SC_THREAD_STACK_MIN */
07255 # elif defined (ACE_HAS_WTHREADS)
07256   ACE_NOTSUP_RETURN (0);
07257 # elif defined (ACE_PSOS)
07258   // there does not appear to be a way to get the
07259   // task stack size except at task creation
07260   ACE_NOTSUP_RETURN (0);
07261 # elif defined (VXWORKS)
07262   TASK_DESC taskDesc;
07263   STATUS status;
07264 
07265   ACE_hthread_t tid;
07266   ACE_OS::thr_self (tid);
07267 
07268   ACE_OSCALL (ACE_ADAPT_RETVAL (::taskInfoGet (tid, &taskDesc),
07269                                 status),
07270               STATUS, -1, status);
07271   return status == OK ? taskDesc.td_stackSize : 0;
07272 # else /* Should not happen... */
07273   ACE_NOTSUP_RETURN (0);
07274 # endif /* ACE_HAS_STHREADS */
07275 #else
07276   ACE_NOTSUP_RETURN (0);
07277 #endif /* ACE_HAS_THREADS */
07278 }
07279 
07280 ACE_INLINE int
07281 ACE_OS::thr_setconcurrency (int hint)
07282 {
07283   ACE_OS_TRACE ("ACE_OS::thr_setconcurrency");
07284 #if defined (ACE_HAS_THREADS)
07285 # if defined (ACE_HAS_STHREADS)
07286   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_setconcurrency (hint),
07287                                        ace_result_),
07288                      int, -1);
07289 # elif defined (ACE_HAS_PTHREADS)
07290   ACE_UNUSED_ARG (hint);
07291   ACE_NOTSUP_RETURN (-1);
07292 # elif defined (ACE_HAS_WTHREADS)
07293   ACE_UNUSED_ARG (hint);
07294 
07295   ACE_NOTSUP_RETURN (-1);
07296 # elif defined (VXWORKS) || defined (ACE_PSOS)
07297   ACE_UNUSED_ARG (hint);
07298   ACE_NOTSUP_RETURN (-1);
07299 # endif /* ACE_HAS_STHREADS */
07300 #else
07301   ACE_UNUSED_ARG (hint);
07302   ACE_NOTSUP_RETURN (-1);
07303 #endif /* ACE_HAS_THREADS */
07304 }
07305 
07306 ACE_INLINE int
07307 ACE_OS::thr_setprio (ACE_hthread_t id, int priority, int policy)
07308 {
07309   ACE_OS_TRACE ("ACE_OS::thr_setprio");
07310   ACE_UNUSED_ARG (policy);
07311 #if defined (ACE_HAS_THREADS)
07312 # if (defined (ACE_HAS_PTHREADS) && !defined (ACE_LACKS_SETSCHED))
07313 
07314 #   if defined (ACE_HAS_PTHREADS_DRAFT4)
07315   int result;
07316   result = ::pthread_setprio (id, priority);
07317   return (result == -1 ? -1 : 0);
07318 #   elif defined (ACE_HAS_PTHREADS_DRAFT6)
07319   pthread_attr_t  attr;
07320   if (pthread_getschedattr (id, &attr) == -1)
07321     return -1;
07322   if (pthread_attr_setprio (attr, priority) == -1)
07323     return -1;
07324   return pthread_setschedattr (id, attr);
07325 #   else
07326   int result;
07327   struct sched_param param;
07328   memset ((void *) &param, 0, sizeof param);
07329 
07330   // If <policy> is -1, we don't want to use it for
07331   // pthread_setschedparam().  Instead, obtain policy from
07332   // pthread_getschedparam().
07333   if (policy == -1)
07334     {
07335       ACE_OSCALL (ACE_ADAPT_RETVAL (::pthread_getschedparam (id, &policy, &param),
07336                                     result),
07337                   int, -1, result);
07338       if (result == -1)
07339         return result;
07340     }
07341 
07342   param.sched_priority = priority;
07343 
07344   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_setschedparam (id, policy, &param),
07345                                        ace_result_),
07346                      int, -1);
07347 #   endif /* ACE_HAS_PTHREADS_DRAFT4 */
07348 # elif defined (ACE_HAS_STHREADS)
07349   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_setprio (id, priority),
07350                                        ace_result_),
07351                      int, -1);
07352 # elif defined (ACE_HAS_WTHREADS)
07353   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::SetThreadPriority (id, priority),
07354                                           ace_result_),
07355                         int, -1);
07356 # elif defined (ACE_PSOS)
07357   u_long oldpriority;
07358   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::t_setpri (id, priority, &oldpriority),
07359                                        ace_result_),
07360                      int, -1);
07361 # elif defined (VXWORKS)
07362   ACE_OSCALL_RETURN (::taskPrioritySet (id, priority), int, -1);
07363 # else
07364   // For example, platforms that support Pthreads but LACK_SETSCHED.
07365   ACE_UNUSED_ARG (id);
07366   ACE_UNUSED_ARG (priority);
07367   ACE_NOTSUP_RETURN (-1);
07368 # endif /* ACE_HAS_STHREADS */
07369 #else
07370   ACE_UNUSED_ARG (id);
07371   ACE_UNUSED_ARG (priority);
07372   ACE_NOTSUP_RETURN (-1);
07373 #endif /* ACE_HAS_THREADS */
07374 }
07375 
07376 ACE_INLINE int
07377 ACE_OS::thr_suspend (ACE_hthread_t target_thread)
07378 {
07379   ACE_OS_TRACE ("ACE_OS::thr_suspend");
07380 #if defined (ACE_HAS_THREADS)
07381 # if defined (ACE_HAS_STHREADS)
07382   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_suspend (target_thread), ace_result_), int, -1);
07383 # elif defined (ACE_HAS_PTHREADS)
07384 #  if defined (ACE_HAS_PTHREAD_SUSPEND)
07385   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (pthread_suspend (target_thread),
07386                                        ace_result_),
07387                      int, -1);
07388 #  else
07389   ACE_UNUSED_ARG (target_thread);
07390   ACE_NOTSUP_RETURN (-1);
07391 #  endif /* ACE_HAS_PTHREAD_SUSPEND */
07392 # elif defined (ACE_HAS_WTHREADS)
07393   if (::SuspendThread (target_thread) != ACE_SYSCALL_FAILED)
07394     return 0;
07395   else
07396     ACE_FAIL_RETURN (-1);
07397   /* NOTREACHED */
07398 # elif defined (ACE_PSOS)
07399   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::t_suspend (target_thread), ace_result_), int, -1);
07400 # elif defined (VXWORKS)
07401   ACE_OSCALL_RETURN (::taskSuspend (target_thread), int, -1);
07402 # endif /* ACE_HAS_STHREADS */
07403 #else
07404   ACE_UNUSED_ARG (target_thread);
07405   ACE_NOTSUP_RETURN (-1);
07406 #endif /* ACE_HAS_THREADS */
07407 }
07408 
07409 ACE_INLINE void
07410 ACE_OS::thr_yield (void)
07411 {
07412   ACE_OS_TRACE ("ACE_OS::thr_yield");
07413 #if defined (ACE_HAS_THREADS)
07414 # if defined (ACE_HAS_PTHREADS)
07415 #   if defined (ACE_HAS_PTHREADS_STD)
07416   // Note - this is a POSIX.4 function - not a POSIX.1c function...
07417   ::sched_yield ();
07418 #   elif defined (ACE_HAS_PTHREADS_DRAFT6)
07419   ::pthread_yield (0);
07420 #   else    /* Draft 4 and 7 */
07421   ::pthread_yield ();
07422 #   endif  /* ACE_HAS_PTHREADS_STD */
07423 # elif defined (ACE_HAS_STHREADS)
07424   ::thr_yield ();
07425 # elif defined (ACE_HAS_WTHREADS)
07426   ::Sleep (0);
07427 # elif defined (VXWORKS)
07428   // An argument of 0 to ::taskDelay doesn't appear to yield the
07429   // current thread.
07430   // Now, it does seem to work.  The context_switch_time test
07431   // works fine with task_delay set to 0.
07432   ::taskDelay (0);
07433 # endif /* ACE_HAS_STHREADS */
07434 #else
07435   ;
07436 #endif /* ACE_HAS_THREADS */
07437 }
07438 
07439 ACE_INLINE int
07440 ACE_OS::priority_control (ACE_idtype_t idtype, ACE_id_t id, int cmd, void *arg)
07441 {
07442   ACE_OS_TRACE ("ACE_OS::priority_control");
07443 #if defined (ACE_HAS_PRIOCNTL)
07444   ACE_OSCALL_RETURN (priocntl (idtype, id, cmd, ACE_static_cast (caddr_t, arg)),
07445                      int, -1);
07446 #else  /* ! ACE_HAS_PRIOCNTL*/
07447   ACE_UNUSED_ARG (idtype);
07448   ACE_UNUSED_ARG (id);
07449   ACE_UNUSED_ARG (cmd);
07450   ACE_UNUSED_ARG (arg);
07451   ACE_NOTSUP_RETURN (-1);
07452 #endif /* ! ACE_HAS_PRIOCNTL*/
07453 }
07454 
07455 ACE_INLINE void
07456 ACE_OS::rewind (FILE *fp)
07457 {
07458 #if !defined (ACE_HAS_WINCE)
07459   ACE_OS_TRACE ("ACE_OS::rewind");
07460   ::rewind (fp);
07461 #else
07462   // In WinCE, "FILE *" is actually a HANDLE.
07463   ::SetFilePointer (fp, 0L, 0L, FILE_BEGIN);
07464 #endif /* ACE_HAS_WINCE */
07465 }
07466 
07467 ACE_INLINE ssize_t
07468 ACE_OS::readv (ACE_HANDLE handle,
07469                iovec *iov,
07470                int iovlen)
07471 {
07472   ACE_OS_TRACE ("ACE_OS::readv");
07473 #if defined (ACE_LACKS_READV)
07474   ACE_OSCALL_RETURN (ACE_OS::readv_emulation (handle, iov, iovlen),
07475                      ssize_t,
07476                      -1);
07477 #else /* ACE_LACKS_READV */
07478   ACE_OSCALL_RETURN (::readv (handle, iov, iovlen), ssize_t, -1);
07479 #endif /* ACE_LACKS_READV */
07480 }
07481 
07482 ACE_INLINE ssize_t
07483 ACE_OS::writev (ACE_HANDLE handle,
07484                 const iovec *iov,
07485                 int iovcnt)
07486 {
07487   ACE_OS_TRACE ("ACE_OS::writev");
07488 #if defined (ACE_LACKS_WRITEV)
07489   ACE_OSCALL_RETURN (ACE_OS::writev_emulation (handle,
07490                                                (ACE_WRITEV_TYPE *) iov,
07491                                                iovcnt), int, -1);
07492 #else /* ACE_LACKS_WRITEV */
07493   ACE_OSCALL_RETURN (::writev (handle,
07494                                (ACE_WRITEV_TYPE *) iov,
07495                                iovcnt), int, -1);
07496 #endif /* ACE_LACKS_WRITEV */
07497 }
07498 
07499 ACE_INLINE ssize_t
07500 ACE_OS::recvv (ACE_HANDLE handle,
07501                iovec *buffers,
07502                int n)
07503 {
07504 #if defined (ACE_HAS_WINSOCK2)
07505 
07506   DWORD bytes_received = 0;
07507   int result = 1;
07508 
07509   // Winsock 2 has WSARecv and can do this directly, but Winsock 1 needs
07510   // to do the recvs piece-by-piece.
07511 
07512 # if (ACE_HAS_WINSOCK2 != 0)
07513   DWORD flags = 0;
07514   result = ::WSARecv ((SOCKET) handle,
07515                       (WSABUF *) buffers,
07516                       n,
07517                       &bytes_received,
07518                       &flags,
07519                       0,
07520                       0);
07521 # else
07522   int i, chunklen;
07523   char *chunkp = 0;
07524 
07525   // Step through the buffers requested by caller; for each one, cycle
07526   // through reads until it's filled or an error occurs.
07527   for (i = 0; i < n && result > 0; i++)
07528     {
07529       chunkp = buffers[i].iov_base;     // Point to part of chunk being read
07530       chunklen = buffers[i].iov_len;    // Track how much to read to chunk
07531       while (chunklen > 0 && result > 0)
07532         {
07533           result = ::recv ((SOCKET) handle, chunkp, chunklen, 0);
07534           if (result > 0)
07535             {
07536               chunkp += result;
07537               chunklen -= result;
07538               bytes_received += result;
07539             }
07540         }
07541     }
07542 # endif /* ACE_HAS_WINSOCK2 != 0 */
07543 
07544   if (result == SOCKET_ERROR)
07545     {
07546       ACE_OS::set_errno_to_wsa_last_error ();
07547       return -1;
07548     }
07549   else
07550     return (ssize_t) bytes_received;
07551 #else
07552   return ACE_OS::readv (handle, buffers, n);
07553 #endif /* ACE_HAS_WINSOCK2 */
07554 }
07555 
07556 ACE_INLINE ssize_t
07557 ACE_OS::sendv (ACE_HANDLE handle,
07558                const iovec *buffers,
07559                int n)
07560 {
07561 #if defined (ACE_HAS_WINSOCK2)
07562   DWORD bytes_sent = 0;
07563   int result = 0;
07564 
07565   // Winsock 2 has WSASend and can do this directly, but Winsock 1
07566   // needs to do the sends one-by-one.
07567 # if (ACE_HAS_WINSOCK2 != 0)
07568   result = ::WSASend ((SOCKET) handle,
07569                       (WSABUF *) buffers,
07570                       n,
07571                       &bytes_sent,
07572                       0,
07573                       0,
07574                       0);
07575 # else
07576   int i;
07577   for (i = 0; i < n && result != SOCKET_ERROR; i++)
07578     {
07579       result = ::send ((SOCKET) handle,
07580                        buffers[i].iov_base,
07581                        buffers[i].iov_len,
07582                        0);
07583       // Gets ignored on error anyway
07584       bytes_sent += buffers[i].iov_len;
07585 
07586       // If the transfer isnt complete just drop out of the loop.
07587       if (result < (int)buffers[i].iov_len)
07588         break;
07589     }
07590 # endif /* ACE_HAS_WINSOCK2 != 0 */
07591 
07592   if (result == SOCKET_ERROR)
07593     {
07594       ACE_OS::set_errno_to_wsa_last_error ();
07595       return -1;
07596     }
07597   else
07598     return (ssize_t) bytes_sent;
07599 
07600 #else
07601   return ACE_OS::writev (handle, buffers, n);
07602 #endif /* ACE_HAS_WINSOCK2 */
07603 }
07604 
07605 ACE_INLINE int
07606 ACE_OS::poll (struct pollfd *pollfds, u_long len, const ACE_Time_Value *timeout)
07607 {
07608   ACE_OS_TRACE ("ACE_OS::poll");
07609 #if defined (ACE_HAS_POLL)
07610   int to = timeout == 0 ? -1 : int (timeout->msec ());
07611   ACE_OSCALL_RETURN (::poll (pollfds, len, to), int, -1);
07612 #else
07613   ACE_UNUSED_ARG (timeout);
07614   ACE_UNUSED_ARG (len);
07615   ACE_UNUSED_ARG (pollfds);
07616 
07617   ACE_NOTSUP_RETURN (-1);
07618 #endif /* ACE_HAS_POLL */
07619 }
07620 
07621 ACE_INLINE int
07622 ACE_OS::poll (struct pollfd *pollfds, u_long len, const ACE_Time_Value &timeout)
07623 {
07624   ACE_OS_TRACE ("ACE_OS::poll");
07625 #if defined (ACE_HAS_POLL)
07626   ACE_OSCALL_RETURN (::poll (pollfds, len, int (timeout.msec ())), int, -1);
07627 #else
07628   ACE_UNUSED_ARG (timeout);
07629   ACE_UNUSED_ARG (len);
07630   ACE_UNUSED_ARG (pollfds);
07631 
07632   ACE_NOTSUP_RETURN (-1);
07633 #endif /* ACE_HAS_POLL */
07634 }
07635 
07636 ACE_INLINE char *
07637 ACE_OS::compile (const char *instring, char *expbuf, char *endbuf)
07638 {
07639   ACE_OS_TRACE ("ACE_OS::compile");
07640 #if defined (ACE_HAS_REGEX)
07641   ACE_OSCALL_RETURN (::compile (instring, expbuf, endbuf), char *, 0);
07642 #else
07643   ACE_UNUSED_ARG (instring);
07644   ACE_UNUSED_ARG (expbuf);
07645   ACE_UNUSED_ARG (endbuf);
07646 
07647   ACE_NOTSUP_RETURN (0);
07648 #endif /* ACE_HAS_REGEX */
07649 }
07650 
07651 ACE_INLINE long
07652 ACE_OS::filesize (const ACE_TCHAR *filename)
07653 {
07654   ACE_OS_TRACE ("ACE_OS::filesize");
07655 
07656   ACE_HANDLE h = ACE_OS::open (filename, O_RDONLY);
07657   if (h != ACE_INVALID_HANDLE)
07658     {
07659       long size = ACE_OS::filesize (h);
07660       ACE_OS::close (h);
07661       return size;
07662     }
07663   else
07664     return -1;
07665 }
07666 
07667 ACE_INLINE int
07668 ACE_OS::closesocket (ACE_HANDLE handle)
07669 {
07670   ACE_OS_TRACE ("ACE_OS::closesocket");
07671 #if defined (ACE_WIN32)
07672   ACE_SOCKCALL_RETURN (::closesocket ((SOCKET) handle), int, -1);
07673 #elif defined (ACE_PSOS_DIAB_PPC)
07674   ACE_OSCALL_RETURN (::pna_close (handle), int, -1);
07675 #else
07676   ACE_OSCALL_RETURN (::close (handle), int, -1);
07677 #endif /* ACE_WIN32 */
07678 }
07679 
07680 ACE_INLINE int
07681 ACE_OS::access (const char *path, int amode)
07682 {
07683   ACE_OS_TRACE ("ACE_OS::access");
07684 #if defined (ACE_LACKS_ACCESS)
07685 #  if defined (ACE_HAS_WINCE)
07686   // @@ WINCE: There should be a Win32 API that can do this.
07687   // Hard coded read access here.
07688     FILE* handle = ACE_OS::fopen (ACE_TEXT_CHAR_TO_TCHAR(path), ACE_LIB_TEXT ("r"));
07689   ACE_UNUSED_ARG (amode);
07690 
07691   ACE_OS::fclose (handle);
07692   return (handle == ACE_INVALID_HANDLE ? -1 : 0);
07693 #  else
07694     ACE_UNUSED_ARG (path);
07695     ACE_UNUSED_ARG (amode);
07696     ACE_NOTSUP_RETURN (-1);
07697 #  endif  // ACE_HAS_WINCE
07698 #else
07699   ACE_OSCALL_RETURN (::access (path, amode), int, -1);
07700 #endif /* ACE_LACKS_ACCESS */
07701 }
07702 
07703 
07704 #if defined (ACE_HAS_WCHAR)
07705 ACE_INLINE int
07706 ACE_OS::access (const wchar_t *path, int amode)
07707 {
07708 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
07709   ACE_OSCALL_RETURN (::_waccess (path, amode), int, -1);
07710 #else /* ACE_WIN32 && !ACE_HAS_WINCE */
07711   return ACE_OS::access (ACE_Wide_To_Ascii (path).char_rep (), amode);
07712 #endif /* ACE_WIN32 && !ACE_HAS_WINCE */
07713 }
07714 #endif /* ACE_HAS_WCHAR */
07715 
07716 ACE_INLINE ACE_HANDLE
07717 ACE_OS::creat (const ACE_TCHAR *filename, mode_t mode)
07718 {
07719   ACE_OS_TRACE ("ACE_OS::creat");
07720 #if defined (ACE_WIN32)
07721   return ACE_OS::open (filename, O_CREAT|O_TRUNC|O_WRONLY, mode);
07722 #elif defined(ACE_PSOS)
07723    ACE_OSCALL_RETURN(::create_f((char *)filename, 1024,
07724                               S_IRUSR | S_IWUSR | S_IXUSR),
07725                      ACE_HANDLE, ACE_INVALID_HANDLE);
07726 #elif defined(ACE_PSOS_TM)
07727   ACE_UNUSED_ARG (filename);
07728   ACE_UNUSED_ARG (mode);
07729   ACE_NOTSUP_RETURN (-1);
07730 #elif defined(ACE_PSOS)
07731   ACE_UNUSED_ARG (filename);
07732   ACE_UNUSED_ARG (mode);
07733   ACE_NOTSUP_RETURN (-1);
07734 #else
07735   ACE_OSCALL_RETURN (::creat (filename, mode),
07736                      ACE_HANDLE, ACE_INVALID_HANDLE);
07737 #endif /* ACE_WIN32 */
07738 }
07739 
07740 #if !defined (ACE_WIN32) && !defined (VXWORKS) && !defined (CHORUS) && !defined (ACE_PSOS)
07741 // Don't inline on those platforms because this function contains
07742 // string literals, and some compilers, e.g., g++, don't handle those
07743 // efficiently in unused inline functions.
07744 ACE_INLINE int
07745 ACE_OS::uname (ACE_utsname *name)
07746 {
07747   ACE_OS_TRACE ("ACE_OS::uname");
07748   ACE_OSCALL_RETURN (::uname (name), int, -1);
07749 }
07750 #endif /* ! ACE_WIN32 && ! VXWORKS && ! CHORUS */
07751 
07752 ACE_INLINE int
07753 ACE_OS::hostname (char name[], size_t maxnamelen)
07754 {
07755   ACE_OS_TRACE ("ACE_OS::hostname");
07756 #if defined (ACE_HAS_PHARLAP)
07757   // PharLap only can do net stuff with the RT version.
07758 #   if defined (ACE_HAS_PHARLAP_RT)
07759   // @@This is not at all reliable... requires ethernet and BOOTP to be used.
07760   // A more reliable way is to go thru the devices w/ EtsTCPGetDeviceCfg until
07761   // a legit IP address is found, then get its name w/ gethostbyaddr.
07762   ACE_SOCKCALL_RETURN (gethostname (name, maxnamelen), int, SOCKET_ERROR);
07763 #   else
07764   ACE_UNUSED_ARG (name);
07765   ACE_UNUSED_ARG (maxnamelen);
07766   ACE_NOTSUP_RETURN (-1);
07767 #   endif /* ACE_HAS_PHARLAP_RT */
07768 #elif defined (VXWORKS) || defined (ACE_HAS_WINCE)
07769   ACE_OSCALL_RETURN (::gethostname (name, maxnamelen), int, -1);
07770 #elif defined (ACE_WIN32)
07771   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::GetComputerNameA (name,
07772                                                         LPDWORD (&maxnamelen)),
07773                                           ace_result_), int, -1);
07774 #elif defined (CHORUS)
07775   if (::gethostname (name, maxnamelen) == -1)
07776     return -1;
07777   else
07778     {
07779       if (ACE_OS::strlen (name) == 0)
07780         {
07781           // Try the HOST environment variable.
07782           ACE_TCHAR *const hostenv = ::getenv (ACE_LIB_TEXT ("HOST"));
07783           if (hostenv)
07784             ACE_OS::strsncpy (name, hostenv, maxnamelen);
07785         }
07786       return 0;
07787     }
07788 #else /* ACE_HAS_PHARLAP */
07789   ACE_utsname host_info;
07790 
07791   if (ACE_OS::uname (&host_info) == -1)
07792     return -1;
07793   else
07794     {
07795       ACE_OS::strsncpy (name, host_info.nodename, maxnamelen);
07796       return 0;
07797     }
07798 #endif /* ACE_HAS_PHARLAP */
07799 }
07800 
07801 #if defined (ACE_HAS_WCHAR)
07802 ACE_INLINE int
07803 ACE_OS::hostname (wchar_t name[], size_t maxnamelen)
07804 {
07805 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
07806   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (GetComputerNameW (name,
07807                                                         LPDWORD (&maxnamelen)),
07808                                           ace_result_), int, -1);
07809 #else /* ACE_WIN32 && !ACE_HAS_WINCE */
07810   // Emulate using the char version
07811   char *char_name = 0;
07812   int result = 0;
07813 
07814   ACE_NEW_RETURN (char_name, char[maxnamelen], -1);
07815 
07816   result = ACE_OS::hostname(char_name, maxnamelen);
07817   ACE_OS::strcpy (name, ACE_Ascii_To_Wide (char_name).wchar_rep ());
07818 
07819   delete [] char_name;
07820   return result;
07821 #endif /* ACE_WIN32 && !ACE_HAS_WINCE */
07822 }
07823 #endif /* ACE_HAS_WCHAR */
07824 
07825 ACE_INLINE int
07826 ACE_OS::msgctl (int msqid, int cmd, struct msqid_ds *val)
07827 {
07828   ACE_OS_TRACE ("ACE_OS::msgctl");
07829 #if defined (ACE_HAS_SYSV_IPC)
07830   ACE_OSCALL_RETURN (::msgctl (msqid, cmd, val), int, -1);
07831 #else
07832   ACE_UNUSED_ARG (msqid);
07833   ACE_UNUSED_ARG (cmd);
07834   ACE_UNUSED_ARG (val);
07835 
07836   ACE_NOTSUP_RETURN (-1);
07837 #endif /* ACE_HAS_SYSV_IPC */
07838 }
07839 
07840 ACE_INLINE int
07841 ACE_OS::msgget (key_t key, int msgflg)
07842 {
07843   ACE_OS_TRACE ("ACE_OS::msgget");
07844 #if defined (ACE_HAS_SYSV_IPC)
07845   ACE_OSCALL_RETURN (::msgget (key, msgflg), int, -1);
07846 #else
07847   ACE_UNUSED_ARG (key);
07848   ACE_UNUSED_ARG (msgflg);
07849 
07850   ACE_NOTSUP_RETURN (-1);
07851 #endif /* ACE_HAS_SYSV_IPC */
07852 }
07853 
07854 ACE_INLINE int
07855 ACE_OS::msgrcv (int int_id, void *buf, size_t len,
07856                 long type, int flags)
07857 {
07858   ACE_OS_TRACE ("ACE_OS::msgrcv");
07859 #if defined (ACE_HAS_SYSV_IPC)
07860 # if defined (ACE_LACKS_POSIX_PROTOTYPES) || defined (ACE_LACKS_SOME_POSIX_PROTOTYPES)
07861   ACE_OSCALL_RETURN (::msgrcv (int_id, (msgbuf *) buf, len, type, flags),
07862                      int, -1);
07863 # else
07864   ACE_OSCALL_RETURN (::msgrcv (int_id, buf, len, type, flags),
07865                      int, -1);
07866 # endif /* ACE_LACKS_POSIX_PROTOTYPES */
07867 #else
07868   ACE_UNUSED_ARG (int_id);
07869   ACE_UNUSED_ARG (buf);
07870   ACE_UNUSED_ARG (len);
07871   ACE_UNUSED_ARG (type);
07872   ACE_UNUSED_ARG (flags);
07873 
07874   ACE_NOTSUP_RETURN (-1);
07875 #endif /* ACE_HAS_SYSV_IPC */
07876 }
07877 
07878 ACE_INLINE int
07879 ACE_OS::msgsnd (int int_id, const void *buf, size_t len, int flags)
07880 {
07881   ACE_OS_TRACE ("ACE_OS::msgsnd");
07882 #if defined (ACE_HAS_SYSV_IPC)
07883 # if defined (ACE_HAS_NONCONST_MSGSND)
07884   ACE_OSCALL_RETURN (::msgsnd (int_id, (void *) buf, len, flags), int, -1);
07885 # elif defined (ACE_LACKS_POSIX_PROTOTYPES) || defined (ACE_LACKS_SOME_POSIX_PROTOTYPES)
07886   ACE_OSCALL_RETURN (::msgsnd (int_id, (msgbuf *) buf, len, flags), int, -1);
07887 # else
07888   ACE_OSCALL_RETURN (::msgsnd (int_id, buf, len, flags), int, -1);
07889 # endif /* ACE_LACKS_POSIX_PROTOTYPES || ACE_HAS_NONCONST_MSGSND */
07890 #else
07891   ACE_UNUSED_ARG (int_id);
07892   ACE_UNUSED_ARG (buf);
07893   ACE_UNUSED_ARG (len);
07894   ACE_UNUSED_ARG (flags);
07895 
07896   ACE_NOTSUP_RETURN (-1);
07897 #endif /* ACE_HAS_SYSV_IPC */
07898 }
07899 
07900 ACE_INLINE u_int
07901 ACE_OS::alarm (u_int secs)
07902 {
07903   ACE_OS_TRACE ("ACE_OS::alarm");
07904 #if defined (ACE_WIN32) || defined (VXWORKS) || defined (CHORUS) || defined (ACE_PSOS)
07905   ACE_UNUSED_ARG (secs);
07906 
07907   ACE_NOTSUP_RETURN (0);
07908 #else
07909   return ::alarm (secs);
07910 #endif /* ACE_WIN32 || VXWORKS || CHORUS || ACE_PSOS */
07911 }
07912 
07913 ACE_INLINE u_int
07914 ACE_OS::ualarm (u_int usecs, u_int interval)
07915 {
07916   ACE_OS_TRACE ("ACE_OS::ualarm");
07917 
07918 #if defined (ACE_HAS_UALARM)
07919   return ::ualarm (usecs, interval);
07920 #elif !defined (ACE_LACKS_UNIX_SIGNALS)
07921   ACE_UNUSED_ARG (interval);
07922   return ::alarm (usecs * ACE_ONE_SECOND_IN_USECS);
07923 #else
07924   ACE_UNUSED_ARG (usecs);
07925   ACE_UNUSED_ARG (interval);
07926   ACE_NOTSUP_RETURN (0);
07927 #endif /* ACE_HAS_UALARM */
07928 }
07929 
07930 ACE_INLINE u_int
07931 ACE_OS::ualarm (const ACE_Time_Value &tv,
07932                 const ACE_Time_Value &tv_interval)
07933 {
07934   ACE_OS_TRACE ("ACE_OS::ualarm");
07935 
07936 #if defined (ACE_HAS_UALARM)
07937   u_int usecs = (tv.sec () * ACE_ONE_SECOND_IN_USECS) + tv.usec ();
07938   u_int interval = (tv_interval.sec () * ACE_ONE_SECOND_IN_USECS) + tv_interval.usec ();
07939   return ::ualarm (usecs, interval);
07940 #elif !defined (ACE_LACKS_UNIX_SIGNALS)
07941   ACE_UNUSED_ARG (tv_interval);
07942   return ::alarm (tv.sec ());
07943 #else
07944   ACE_UNUSED_ARG (tv_interval);
07945   ACE_UNUSED_ARG (tv);
07946   ACE_NOTSUP_RETURN (0);
07947 #endif /* ACE_HAS_UALARM */
07948 }
07949 
07950 ACE_INLINE int
07951 ACE_OS::dlclose (ACE_SHLIB_HANDLE handle)
07952 {
07953   ACE_OS_TRACE ("ACE_OS::dlclose");
07954 #if defined (ACE_LACKS_DLCLOSE)
07955   ACE_UNUSED_ARG (handle);
07956   return 0;
07957 #elif defined (ACE_HAS_SVR4_DYNAMIC_LINKING)
07958 
07959 # if !defined (ACE_HAS_AUTOMATIC_INIT_FINI)
07960   // SunOS4 does not automatically call _fini()!
07961   void *ptr;
07962 
07963   ACE_OSCALL (::dlsym (handle, ACE_LIB_TEXT ("_fini")), void *, 0, ptr);
07964 
07965   if (ptr != 0)
07966     (*((int (*)(void)) ptr)) (); // Call _fini hook explicitly.
07967 # endif /* ACE_HAS_AUTOMATIC_INIT_FINI */
07968 #if defined (_M_UNIX)
07969   ACE_OSCALL_RETURN (::_dlclose (handle), int, -1);
07970 #else /* _MUNIX */
07971     ACE_OSCALL_RETURN (::dlclose (handle), int, -1);
07972 #endif /* _M_UNIX */
07973 #elif defined (ACE_WIN32)
07974   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::FreeLibrary (handle), ace_result_), int, -1);
07975 #elif defined (__hpux)
07976   // HP-UX 10.x and 32-bit 11.00 do not pay attention to the ref count
07977   // when unloading a dynamic lib.  So, if the ref count is more than
07978   // 1, do not unload the lib.  This will cause a library loaded more
07979   // than once to not be unloaded until the process runs down, but
07980   // that's life.  It's better than unloading a library that's in use.
07981   // So far as I know, there's no way to decrement the refcnt that the
07982   // kernel is looking at - the shl_descriptor is a copy of what the
07983   // kernel has, not the actual struct.  On 64-bit HP-UX using dlopen,
07984   // this problem has been fixed.
07985   struct shl_descriptor  desc;
07986   if (shl_gethandle_r (handle, &desc) == -1)
07987     return -1;
07988   if (desc.ref_count > 1)
07989     return 0;
07990 # if defined(__GNUC__) || __cplusplus >= 199707L
07991   ACE_OSCALL_RETURN (::shl_unload (handle), int, -1);
07992 # else
07993   ACE_OSCALL_RETURN (::cxxshl_unload (handle), int, -1);
07994 # endif  /* aC++ vs. Hp C++ */
07995 #else
07996   ACE_UNUSED_ARG (handle);
07997   ACE_NOTSUP_RETURN (-1);
07998 #endif /* ACE_HAS_SVR4_DYNAMIC_LINKING */
07999 }
08000 
08001 ACE_INLINE ACE_TCHAR *
08002 ACE_OS::dlerror (void)
08003 {
08004   ACE_OS_TRACE ("ACE_OS::dlerror");
08005 # if defined (ACE_HAS_SVR4_DYNAMIC_LINKING)
08006 #if defined(_M_UNIX)
08007   ACE_OSCALL_RETURN ((char *)::_dlerror (), char *, 0);
08008 #else /* _M_UNIX */
08009   ACE_OSCALL_RETURN ((char *)::dlerror (), char *, 0);
08010 #endif /* _M_UNIX */
08011 # elif defined (__hpux)
08012   ACE_OSCALL_RETURN (::strerror(errno), char *, 0);
08013 # elif defined (ACE_WIN32)
08014   static ACE_TCHAR buf[128];
08015 #   if defined (ACE_HAS_PHARLAP)
08016   ACE_OS::sprintf (buf, "error code %d", GetLastError());
08017 #   else
08018   ACE_TEXT_FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM,
08019                           0,
08020                           ::GetLastError (),
08021                           0,
08022                           buf,
08023                           sizeof buf / sizeof buf[0],
08024                           0);
08025 #   endif /* ACE_HAS_PHARLAP */
08026   return buf;
08027 # else
08028   ACE_NOTSUP_RETURN (0);
08029 # endif /* ACE_HAS_SVR4_DYNAMIC_LINKING */
08030 }
08031 
08032 ACE_INLINE ACE_SHLIB_HANDLE
08033 ACE_OS::dlopen (const ACE_TCHAR *fname,
08034                 int mode)
08035 {
08036   ACE_OS_TRACE ("ACE_OS::dlopen");
08037 
08038   // Get the correct OS type.
08039   ACE_DL_TYPE filename = ACE_const_cast (ACE_DL_TYPE, fname);
08040 
08041 # if defined (ACE_HAS_SVR4_DYNAMIC_LINKING)
08042   void *handle;
08043 #   if defined (ACE_HAS_SGIDLADD)
08044   ACE_OSCALL (::sgidladd (filename, mode), void *, 0, handle);
08045 #   elif defined (_M_UNIX)
08046   ACE_OSCALL (::_dlopen (filename, mode), void *, 0, handle);
08047 #   else
08048   ACE_OSCALL (::dlopen (filename, mode), void *, 0, handle);
08049 #   endif /* ACE_HAS_SGIDLADD */
08050 #   if !defined (ACE_HAS_AUTOMATIC_INIT_FINI)
08051   if (handle != 0)
08052     {
08053       void *ptr;
08054       // Some systems (e.g., SunOS4) do not automatically call _init(), so
08055       // we'll have to call it manually.
08056 
08057       ACE_OSCALL (::dlsym (handle, ACE_LIB_TEXT ("_init")), void *, 0, ptr);
08058 
08059       if (ptr != 0 && (*((int (*)(void)) ptr)) () == -1) // Call _init hook explicitly.
08060         {
08061           // Close down the handle to prevent leaks.
08062           ::dlclose (handle);
08063           return 0;
08064         }
08065     }
08066 #   endif /* ACE_HAS_AUTOMATIC_INIT_FINI */
08067   return handle;
08068 # elif defined (ACE_WIN32)
08069   ACE_UNUSED_ARG (mode);
08070 
08071   ACE_WIN32CALL_RETURN (ACE_TEXT_LoadLibrary (filename), ACE_SHLIB_HANDLE, 0);
08072 # elif defined (__hpux)
08073 
08074 #   if defined(__GNUC__) || __cplusplus >= 199707L
08075   ACE_OSCALL_RETURN (::shl_load(filename, mode, 0L), ACE_SHLIB_HANDLE, 0);
08076 #   else
08077   ACE_OSCALL_RETURN (::cxxshl_load(filename, mode, 0L), ACE_SHLIB_HANDLE, 0);
08078 #   endif  /* aC++ vs. Hp C++ */
08079 
08080 # else
08081   ACE_UNUSED_ARG (filename);
08082   ACE_UNUSED_ARG (mode);
08083   ACE_NOTSUP_RETURN (0);
08084 # endif /* ACE_HAS_SVR4_DYNAMIC_LINKING */
08085 }
08086 
08087 ACE_INLINE void *
08088 ACE_OS::dlsym (ACE_SHLIB_HANDLE handle,
08089                const ACE_TCHAR *sname)
08090 {
08091   ACE_OS_TRACE ("ACE_OS::dlsym");
08092 
08093 #if defined (ACE_HAS_DLSYM_SEGFAULT_ON_INVALID_HANDLE)
08094   // Check if the handle is valid before making any calls using it.
08095   if (handle == ACE_SHLIB_INVALID_HANDLE)
08096     return 0;
08097 #endif /* ACE_HAS_DLSYM_SEGFAULT_ON_INVALID_HANDLE */
08098 
08099   // Get the correct OS type.
08100 #if defined (ACE_HAS_WINCE)
08101   const wchar_t *symbolname = sname;
08102 #elif defined (ACE_HAS_CHARPTR_DL)
08103   char *symbolname = ACE_const_cast (char *, sname);
08104 #elif !defined (ACE_WIN32) || !defined (ACE_USES_WCHAR)
08105   const char *symbolname = sname;
08106 #endif /* ACE_HAS_CHARPTR_DL */
08107 
08108 # if defined (ACE_HAS_SVR4_DYNAMIC_LINKING)
08109 
08110 #   if defined (ACE_LACKS_POSIX_PROTOTYPES)
08111   ACE_OSCALL_RETURN (::dlsym (handle, symbolname), void *, 0);
08112 #   elif defined (ACE_USES_ASM_SYMBOL_IN_DLSYM)
08113   int l = ACE_OS::strlen (symbolname) + 2;
08114   char *asm_symbolname = 0;
08115   ACE_NEW_RETURN (asm_symbolname, char[l], 0);
08116   ACE_OS::strcpy (asm_symbolname, "_") ;
08117   ACE_OS::strcpy (asm_symbolname + 1, symbolname) ;
08118   void *ace_result;
08119   ACE_OSCALL (::dlsym (handle, asm_symbolname), void *, 0, ace_result);
08120   delete [] asm_symbolname;
08121   return ace_result;
08122 #   elif defined (_M_UNIX)
08123   ACE_OSCALL_RETURN (::_dlsym (handle, symbolname), void *, 0);
08124 #   else
08125   ACE_OSCALL_RETURN (::dlsym (handle, symbolname), void *, 0);
08126 #   endif /* ACE_LACKS_POSIX_PROTOTYPES */
08127 
08128 # elif defined (ACE_WIN32) && defined (ACE_USES_WCHAR) && !defined (ACE_HAS_WINCE)
08129 
08130   ACE_WIN32CALL_RETURN (::GetProcAddress (handle, ACE_TEXT_ALWAYS_CHAR (sname)), void *, 0);
08131 
08132 # elif defined (ACE_WIN32)
08133 
08134   ACE_WIN32CALL_RETURN (::GetProcAddress (handle, symbolname), void *, 0);
08135 
08136 # elif defined (__hpux)
08137 
08138   void *value;
08139   int status;
08140   shl_t _handle = handle;
08141   ACE_OSCALL (::shl_findsym(&_handle, symbolname, TYPE_UNDEFINED, &value), int, -1, status);
08142   return status == 0 ? value : 0;
08143 
08144 # else
08145 
08146   ACE_UNUSED_ARG (handle);
08147   ACE_UNUSED_ARG (symbolname);
08148   ACE_NOTSUP_RETURN (0);
08149 
08150 # endif /* ACE_HAS_SVR4_DYNAMIC_LINKING */
08151 }
08152 
08153 ACE_INLINE int
08154 ACE_OS::step (const char *str, char *expbuf)
08155 {
08156   ACE_OS_TRACE ("ACE_OS::step");
08157 #if defined (ACE_HAS_REGEX)
08158   ACE_OSCALL_RETURN (::step (str, expbuf), int, -1);
08159 #else
08160   ACE_UNUSED_ARG (str);
08161   ACE_UNUSED_ARG (expbuf);
08162 
08163   ACE_NOTSUP_RETURN (-1);
08164 #endif /* ACE_HAS_REGEX */
08165 }
08166 
08167 ACE_INLINE long
08168 ACE_OS::sysinfo (int cmd, char *buf, long count)
08169 {
08170   ACE_OS_TRACE ("ACE_OS::sysinfo");
08171 #if defined (ACE_HAS_SYSINFO)
08172   ACE_OSCALL_RETURN (::sysinfo (cmd, buf, count), long, -1);
08173 #else
08174   ACE_UNUSED_ARG (cmd);
08175   ACE_UNUSED_ARG (buf);
08176   ACE_UNUSED_ARG (count);
08177 
08178   ACE_NOTSUP_RETURN (0);
08179 #endif /* ACE_HAS_SYSINFO */
08180 }
08181 
08182 ACE_INLINE ssize_t
08183 ACE_OS::write (ACE_HANDLE handle, const void *buf, size_t nbyte)
08184 {
08185   ACE_OS_TRACE ("ACE_OS::write");
08186 #if defined (ACE_WIN32)
08187   DWORD bytes_written; // This is set to 0 byte WriteFile.
08188 
08189   // Strictly correctly, we should loop writing all the data if more
08190   // than a DWORD length can hold.
08191   DWORD short_nbyte = ACE_static_cast (DWORD, nbyte);
08192   if (::WriteFile (handle, buf, short_nbyte, &bytes_written, 0))
08193     return (ssize_t) bytes_written;
08194   else
08195     ACE_FAIL_RETURN (-1);
08196 #elif defined (ACE_PSOS)
08197 # if defined (ACE_PSOS_LACKS_PHILE)
08198   ACE_UNUSED_ARG (handle);
08199   ACE_UNUSED_ARG (buf);
08200   ACE_UNUSED_ARG (nbyte);
08201   ACE_NOTSUP_RETURN (-1);
08202 # else
08203   if(::write_f (handle, (void *) buf, nbyte) == 0)
08204     return (ssize_t) nbyte;
08205   else
08206     return -1;
08207 # endif /* defined (ACE_PSOS_LACKS_PHILE) */
08208 #else
08209 # if defined (ACE_LACKS_POSIX_PROTOTYPES)
08210   ACE_OSCALL_RETURN (::write (handle, (const char *) buf, nbyte), ssize_t, -1);
08211 # elif defined (ACE_PSOS)
08212   ACE_OSCALL_RETURN (::write_f(handle, (void *) buf, nbyte), ssize_t, -1);
08213 # elif defined (ACE_HAS_CHARPTR_SOCKOPT)
08214   ACE_OSCALL_RETURN (::write (handle, (char *) buf, nbyte), ssize_t, -1);
08215 # else
08216   ACE_OSCALL_RETURN (::write (handle, buf, nbyte), ssize_t, -1);
08217 # endif /* ACE_LACKS_POSIX_PROTOTYPES */
08218 #endif /* ACE_WIN32 */
08219 }
08220 
08221 ACE_INLINE ssize_t
08222 ACE_OS::write (ACE_HANDLE handle, const void *buf, size_t nbyte,
08223                ACE_OVERLAPPED *overlapped)
08224 {
08225   ACE_OS_TRACE ("ACE_OS::write");
08226   overlapped = overlapped;
08227 #if defined (ACE_WIN32)
08228   DWORD bytes_written; // This is set to 0 byte WriteFile.
08229 
08230   DWORD short_nbyte = ACE_static_cast (DWORD, nbyte);
08231   if (::WriteFile (handle, buf, short_nbyte, &bytes_written, overlapped))
08232     return (ssize_t) bytes_written;
08233   else
08234     return -1;
08235 #else
08236   return ACE_OS::write (handle, buf, nbyte);
08237 #endif /* ACE_WIN32 */
08238 }
08239 
08240 ACE_INLINE ssize_t
08241 ACE_OS::read (ACE_HANDLE handle, void *buf, size_t len)
08242 {
08243   ACE_OS_TRACE ("ACE_OS::read");
08244 #if defined (ACE_WIN32)
08245   DWORD ok_len;
08246   if (::ReadFile (handle, buf, ACE_static_cast (DWORD, len), &ok_len, 0))
08247     return (ssize_t) ok_len;
08248   else
08249     ACE_FAIL_RETURN (-1);
08250 #elif defined (ACE_PSOS)
08251 # if defined (ACE_PSOS_LACKS_PHILE)
08252   ACE_UNUSED_ARG (handle);
08253   ACE_UNUSED_ARG (buf);
08254   ACE_UNUSED_ARG (len);
08255   ACE_NOTSUP_RETURN (-1);
08256 # else
08257   u_long count;
08258   u_long result = ::read_f (handle, buf, len, &count);
08259   if (result != 0)
08260     return ACE_static_cast (ssize_t, -1);
08261   else
08262     return ACE_static_cast (ssize_t, count == len ? count : 0);
08263 # endif /* defined (ACE_PSOS_LACKS_PHILE */
08264 #else
08265 
08266   int result;
08267 
08268 # if defined (ACE_LACKS_POSIX_PROTOTYPES) || defined (ACE_HAS_CHARPTR_SOCKOPT)
08269   ACE_OSCALL (::read (handle, (char *) buf, len), ssize_t, -1, result);
08270 # else
08271   ACE_OSCALL (::read (handle, buf, len), ssize_t, -1, result);
08272 # endif /* ACE_LACKS_POSIX_PROTOTYPES */
08273   if (result == -1 && errno == EAGAIN)
08274     errno = EWOULDBLOCK;
08275   return result;
08276 #endif /* ACE_WIN32 */
08277 }
08278 
08279 ACE_INLINE ssize_t
08280 ACE_OS::read (ACE_HANDLE handle, void *buf, size_t len,
08281               ACE_OVERLAPPED *overlapped)
08282 {
08283   ACE_OS_TRACE ("ACE_OS::read");
08284   overlapped = overlapped;
08285 #if defined (ACE_WIN32)
08286   DWORD ok_len;
08287   DWORD short_len = ACE_static_cast (DWORD, len);
08288   if (::ReadFile (handle, buf, short_len, &ok_len, overlapped))
08289     return (ssize_t) ok_len;
08290   else
08291     ACE_FAIL_RETURN (-1);
08292 #else
08293   return ACE_OS::read (handle, buf, len);
08294 #endif /* ACE_WIN32 */
08295 }
08296 
08297 ACE_INLINE int
08298 ACE_OS::readlink (const char *path, char *buf, size_t bufsiz)
08299 {
08300   ACE_OS_TRACE ("ACE_OS::readlink");
08301 # if defined (ACE_LACKS_READLINK) || \
08302      defined (ACE_HAS_WINCE) || defined (ACE_WIN32)
08303   ACE_UNUSED_ARG (path);
08304   ACE_UNUSED_ARG (buf);
08305   ACE_UNUSED_ARG (bufsiz);
08306   ACE_NOTSUP_RETURN (-1);
08307 # else
08308 #   if !defined(ACE_HAS_NONCONST_READLINK)
08309       ACE_OSCALL_RETURN (::readlink (path, buf, bufsiz), int, -1);
08310 #   else
08311       ACE_OSCALL_RETURN (::readlink ((char *)path, buf, bufsiz), int, -1);
08312 #   endif
08313 # endif /* ACE_LACKS_READLINK */
08314 }
08315 
08316 ACE_INLINE int
08317 ACE_OS::getmsg (ACE_HANDLE handle,
08318                 struct strbuf *ctl,
08319                 struct strbuf *data,
08320                 int *flags)
08321 {
08322   ACE_OS_TRACE ("ACE_OS::getmsg");
08323 #if defined (ACE_HAS_STREAM_PIPES)
08324   ACE_OSCALL_RETURN (::getmsg (handle, ctl, data, flags), int, -1);
08325 #else
08326   ACE_UNUSED_ARG (handle);
08327   ACE_UNUSED_ARG (ctl);
08328   ACE_UNUSED_ARG (data);
08329   ACE_UNUSED_ARG (flags);
08330 
08331   // I'm not sure how to implement this correctly.
08332   ACE_NOTSUP_RETURN (-1);
08333 #endif /* ACE_HAS_STREAM_PIPES */
08334 }
08335 
08336 ACE_INLINE int
08337 ACE_OS::getpmsg (ACE_HANDLE handle,
08338                  struct strbuf *ctl,
08339                  struct strbuf *data,
08340                  int *band,
08341                  int *flags)
08342 {
08343   ACE_OS_TRACE ("ACE_OS::getpmsg");
08344 #if defined (ACE_HAS_STREAM_PIPES)
08345   ACE_OSCALL_RETURN (::getpmsg (handle, ctl, data, band, flags), int, -1);
08346 #else
08347   ACE_UNUSED_ARG (handle);
08348   ACE_UNUSED_ARG (ctl);
08349   ACE_UNUSED_ARG (data);
08350   ACE_UNUSED_ARG (band);
08351   ACE_UNUSED_ARG (flags);
08352 
08353   // I'm not sure how to implement this correctly.
08354   ACE_NOTSUP_RETURN (-1);
08355 #endif /* ACE_HAS_STREAM_PIPES */
08356 }
08357 
08358 ACE_INLINE int
08359 ACE_OS::getrusage (int who, struct rusage *ru)
08360 {
08361   ACE_OS_TRACE ("ACE_OS::getrusage");
08362 
08363 #if defined (ACE_HAS_SYSCALL_GETRUSAGE)
08364   // This nonsense is necessary for HP/UX...
08365   ACE_OSCALL_RETURN (::syscall (SYS_GETRUSAGE, who, ru), int, -1);
08366 #elif defined (ACE_HAS_GETRUSAGE)
08367 # if defined (ACE_WIN32)
08368   ACE_UNUSED_ARG (who);
08369 
08370   FILETIME dummy_1;
08371   FILETIME dummy_2;
08372   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::GetProcessTimes (::GetCurrentProcess(),
08373                                                              &dummy_1,   // start
08374                                                              &dummy_2,     // exited
08375                                                              &ru->ru_stime,
08376                                                              &ru->ru_utime),
08377                                           ace_result_),
08378                         int, -1);
08379 # else
08380 #   if defined (ACE_HAS_RUSAGE_WHO_ENUM)
08381   ACE_OSCALL_RETURN (::getrusage ((ACE_HAS_RUSAGE_WHO_ENUM) who, ru), int, -1);
08382 #   else
08383   ACE_OSCALL_RETURN (::getrusage (who, ru), int, -1);
08384 #   endif /* ACE_HAS_RUSAGE_WHO_ENUM */
08385 # endif /* ACE_WIN32 */
08386 #else
08387   who = who;
08388   ru = ru;
08389   ACE_NOTSUP_RETURN (-1);
08390 #endif /* ACE_HAS_SYSCALL_GETRUSAGE */
08391 }
08392 
08393 ACE_INLINE int
08394 ACE_OS::isastream (ACE_HANDLE handle)
08395 {
08396   ACE_OS_TRACE ("ACE_OS::isastream");
08397 #if defined (ACE_HAS_STREAM_PIPES)
08398   ACE_OSCALL_RETURN (::isastream (handle), int, -1);
08399 #else
08400   ACE_UNUSED_ARG (handle);
08401 
08402   ACE_NOTSUP_RETURN (-1);
08403 #endif /* ACE_HAS_STREAM_PIPES */
08404 }
08405 
08406 // Implements simple read/write control for pages.  Affects a page if
08407 // part of the page is referenced.  Currently PROT_READ, PROT_WRITE,
08408 // and PROT_RDWR has been mapped in OS.h.  This needn't have anything
08409 // to do with a mmap region.
08410 
08411 ACE_INLINE int
08412 ACE_OS::mprotect (void *addr, size_t len, int prot)
08413 {
08414   ACE_OS_TRACE ("ACE_OS::mprotect");
08415 #if defined (ACE_WIN32) && !defined (ACE_HAS_PHARLAP)
08416   DWORD dummy; // Sigh!
08417   return ::VirtualProtect(addr, len, prot, &dummy) ? 0 : -1;
08418 #elif !defined (ACE_LACKS_MPROTECT)
08419   ACE_OSCALL_RETURN (::mprotect ((ACE_MMAP_TYPE) addr, len, prot), int, -1);
08420 #else
08421   ACE_UNUSED_ARG (addr);
08422   ACE_UNUSED_ARG (len);
08423   ACE_UNUSED_ARG (prot);
08424   ACE_NOTSUP_RETURN (-1);
08425 #endif /* ACE_WIN32 && !ACE_HAS_PHARLAP */
08426 }
08427 
08428 ACE_INLINE int
08429 ACE_OS::msync (void *addr, size_t len, int sync)
08430 {
08431   ACE_OS_TRACE ("ACE_OS::msync");
08432 #if defined (ACE_WIN32) && !defined (ACE_HAS_PHARLAP)
08433   ACE_UNUSED_ARG (sync);
08434 
08435   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::FlushViewOfFile (addr, len), ace_result_), int, -1);
08436 #elif !defined (ACE_LACKS_MSYNC)
08437 # if !defined (ACE_HAS_BROKEN_NETBSD_MSYNC)
08438   ACE_OSCALL_RETURN (::msync ((ACE_MMAP_TYPE) addr, len, sync), int, -1);
08439 # else
08440   ACE_OSCALL_RETURN (::msync ((ACE_MMAP_TYPE) addr, len), int, -1);
08441   ACE_UNUSED_ARG (sync);
08442 # endif /* ACE_HAS_BROKEN_NETBSD_MSYNC */
08443 #else
08444   ACE_UNUSED_ARG (addr);
08445   ACE_UNUSED_ARG (len);
08446   ACE_UNUSED_ARG (sync);
08447   ACE_NOTSUP_RETURN (-1);
08448 #endif /* ACE_WIN32 && !ACE_HAS_PHARLAP */
08449 }
08450 
08451 ACE_INLINE int
08452 ACE_OS::munmap (void *addr, size_t len)
08453 {
08454   ACE_OS_TRACE ("ACE_OS::munmap");
08455 #if defined (ACE_WIN32)
08456   ACE_UNUSED_ARG (len);
08457 
08458   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::UnmapViewOfFile (addr), ace_result_), int, -1);
08459 #elif !defined (ACE_LACKS_MMAP)
08460   ACE_OSCALL_RETURN (::munmap ((ACE_MMAP_TYPE) addr, len), int, -1);
08461 #else
08462   ACE_UNUSED_ARG (addr);
08463   ACE_UNUSED_ARG (len);
08464   ACE_NOTSUP_RETURN (-1);
08465 #endif /* ACE_WIN32 */
08466 }
08467 
08468 ACE_INLINE int
08469 ACE_OS::madvise (caddr_t addr, size_t len, int advice)
08470 {
08471   ACE_OS_TRACE ("ACE_OS::madvise");
08472 #if defined (ACE_WIN32)
08473   ACE_UNUSED_ARG (addr);
08474   ACE_UNUSED_ARG (len);
08475   ACE_UNUSED_ARG (advice);
08476 
08477   ACE_NOTSUP_RETURN (-1);
08478 #elif !defined (ACE_LACKS_MADVISE)
08479   ACE_OSCALL_RETURN (::madvise (addr, len, advice), int, -1);
08480 #else
08481   ACE_UNUSED_ARG (addr);
08482   ACE_UNUSED_ARG (len);
08483   ACE_UNUSED_ARG (advice);
08484   ACE_NOTSUP_RETURN (-1);
08485 #endif /* ACE_WIN32 */
08486 }
08487 
08488 ACE_INLINE int
08489 ACE_OS::putmsg (ACE_HANDLE handle, const struct strbuf *ctl,
08490                 const struct strbuf *data, int flags)
08491 {
08492   ACE_OS_TRACE ("ACE_OS::putmsg");
08493 #if defined (ACE_HAS_STREAM_PIPES)
08494   ACE_OSCALL_RETURN (::putmsg (handle,
08495                                (ACE_STRBUF_TYPE) ctl,
08496                                (ACE_STRBUF_TYPE) data,
08497                                flags), int, -1);
08498 #else
08499   ACE_UNUSED_ARG (flags);
08500   if (ctl == 0 && data == 0)
08501     {
08502       errno = EINVAL;
08503       return 0;
08504     }
08505   // Handle the two easy cases.
08506   else if (ctl != 0)
08507     return ACE_OS::write (handle, ctl->buf, ctl->len);
08508   else if (data != 0)
08509     return ACE_OS::write (handle, data->buf, data->len);
08510   else
08511     {
08512       // This is the hard case.
08513       char *buf;
08514       ACE_NEW_RETURN (buf, char [ctl->len + data->len], -1);
08515       ACE_OS::memcpy (buf, ctl->buf, ctl->len);
08516       ACE_OS::memcpy (buf + ctl->len, data->buf, data->len);
08517       int result = ACE_OS::write (handle, buf, ctl->len + data->len);
08518       delete [] buf;
08519       return result;
08520     }
08521 #endif /* ACE_HAS_STREAM_PIPES */
08522 }
08523 
08524 ACE_INLINE int
08525 ACE_OS::putpmsg (ACE_HANDLE handle,
08526                  const struct strbuf *ctl,
08527                  const struct strbuf *data,
08528                  int band,
08529                  int flags)
08530 {
08531   ACE_OS_TRACE ("ACE_OS::putpmsg");
08532 #if defined (ACE_HAS_STREAM_PIPES)
08533   ACE_OSCALL_RETURN (::putpmsg (handle,
08534                                 (ACE_STRBUF_TYPE) ctl,
08535                                 (ACE_STRBUF_TYPE) data,
08536                                 band, flags), int, -1);
08537 #else
08538   ACE_UNUSED_ARG (flags);
08539   ACE_UNUSED_ARG (band);
08540   return ACE_OS::putmsg (handle, ctl, data, flags);
08541 #endif /* ACE_HAS_STREAM_PIPES */
08542 }
08543 
08544 ACE_INLINE int
08545 ACE_OS::semctl (int int_id, int semnum, int cmd, semun value)
08546 {
08547   ACE_OS_TRACE ("ACE_OS::semctl");
08548 #if defined (ACE_HAS_SYSV_IPC)
08549   ACE_OSCALL_RETURN (::semctl (int_id, semnum, cmd, value), int, -1);
08550 #else
08551   ACE_UNUSED_ARG (int_id);
08552   ACE_UNUSED_ARG (semnum);
08553   ACE_UNUSED_ARG (cmd);
08554   ACE_UNUSED_ARG (value);
08555 
08556   ACE_NOTSUP_RETURN (-1);
08557 #endif /* ACE_HAS_SYSV_IPC */
08558 }
08559 
08560 ACE_INLINE int
08561 ACE_OS::semget (key_t key, int nsems, int flags)
08562 {
08563   ACE_OS_TRACE ("ACE_OS::semget");
08564 #if defined (ACE_HAS_SYSV_IPC)
08565   ACE_OSCALL_RETURN (::semget (key, nsems, flags), int, -1);
08566 #else
08567   ACE_UNUSED_ARG (key);
08568   ACE_UNUSED_ARG (nsems);
08569   ACE_UNUSED_ARG (flags);
08570 
08571   ACE_NOTSUP_RETURN (-1);
08572 #endif /* ACE_HAS_SYSV_IPC */
08573 }
08574 
08575 ACE_INLINE int
08576 ACE_OS::semop (int int_id, struct sembuf *sops, size_t nsops)
08577 {
08578   ACE_OS_TRACE ("ACE_OS::semop");
08579 #if defined (ACE_HAS_SYSV_IPC)
08580   ACE_OSCALL_RETURN (::semop (int_id, sops, nsops), int, -1);
08581 #else
08582   ACE_UNUSED_ARG (int_id);
08583   ACE_UNUSED_ARG (sops);
08584   ACE_UNUSED_ARG (nsops);
08585 
08586   ACE_NOTSUP_RETURN (-1);
08587 #endif /* ACE_HAS_SYSV_IPC */
08588 }
08589 
08590 ACE_INLINE void *
08591 ACE_OS::shmat (int int_id, void *shmaddr, int shmflg)
08592 {
08593   ACE_OS_TRACE ("ACE_OS::shmat");
08594 #if defined (ACE_HAS_SYSV_IPC)
08595 # if defined (ACE_LACKS_POSIX_PROTOTYPES) || defined (ACE_LACKS_SOME_POSIX_PROTOTYPES)
08596   ACE_OSCALL_RETURN (::shmat (int_id, (char *)shmaddr, shmflg), void *, (void *) -1);
08597 # else
08598   ACE_OSCALL_RETURN (::shmat (int_id, shmaddr, shmflg), void *, (void *) -1);
08599 # endif /* ACE_LACKS_POSIX_PROTOTYPES */
08600 #else
08601   ACE_UNUSED_ARG (int_id);
08602   ACE_UNUSED_ARG (shmaddr);
08603   ACE_UNUSED_ARG (shmflg);
08604 
08605   ACE_NOTSUP_RETURN ((void *) -1);
08606 #endif /* ACE_HAS_SYSV_IPC */
08607 }
08608 
08609 ACE_INLINE int
08610 ACE_OS::shmctl (int int_id, int cmd, struct shmid_ds *buf)
08611 {
08612   ACE_OS_TRACE ("ACE_OS::shmctl");
08613 #if defined (ACE_HAS_SYSV_IPC)
08614   ACE_OSCALL_RETURN (::shmctl (int_id, cmd, buf), int, -1);
08615 #else
08616   ACE_UNUSED_ARG (buf);
08617   ACE_UNUSED_ARG (cmd);
08618   ACE_UNUSED_ARG (int_id);
08619 
08620   ACE_NOTSUP_RETURN (-1);
08621 #endif /* ACE_HAS_SYSV_IPC */
08622 }
08623 
08624 ACE_INLINE int
08625 ACE_OS::shmdt (void *shmaddr)
08626 {
08627   ACE_OS_TRACE ("ACE_OS::shmdt");
08628 #if defined (ACE_HAS_SYSV_IPC)
08629   ACE_OSCALL_RETURN (::shmdt ((char *) shmaddr), int, -1);
08630 #else
08631   ACE_UNUSED_ARG (shmaddr);
08632 
08633   ACE_NOTSUP_RETURN (-1);
08634 #endif /* ACE_HAS_SYSV_IPC */
08635 }
08636 
08637 ACE_INLINE int
08638 ACE_OS::shmget (key_t key, int size, int flags)
08639 {
08640   ACE_OS_TRACE ("ACE_OS::shmget");
08641 #if defined (ACE_HAS_SYSV_IPC)
08642   ACE_OSCALL_RETURN (::shmget (key, size, flags), int, -1);
08643 #else
08644   ACE_UNUSED_ARG (flags);
08645   ACE_UNUSED_ARG (size);
08646   ACE_UNUSED_ARG (key);
08647 
08648   ACE_NOTSUP_RETURN (-1);
08649 #endif /* ACE_HAS_SYSV_IPC */
08650 }
08651 
08652 ACE_INLINE void
08653 ACE_OS::tzset (void)
08654 {
08655 #if !defined (ACE_HAS_WINCE) && !defined (VXWORKS) && !defined (ACE_PSOS) && ! defined(__rtems__)
08656 #   if defined (ACE_WIN32)
08657   ::_tzset ();  // For Win32.
08658 #   else
08659   ::tzset ();   // For UNIX platforms.
08660 #   endif /* ACE_WIN32 */
08661 # else
08662   errno = ENOTSUP;
08663 # endif /* ACE_HAS_WINCE && !VXWORKS && !ACE_PSOS && !__rtems__ */
08664 }
08665 
08666 ACE_INLINE long
08667 ACE_OS::timezone (void)
08668 {
08669   return ::ace_timezone ();
08670 }
08671 
08672 #if !defined (ACE_LACKS_DIFFTIME)
08673 ACE_INLINE double
08674 ACE_OS::difftime (time_t t1, time_t t0)
08675 {
08676   return ::ace_difftime (t1, t0);
08677 }
08678 #endif /* ! ACE_LACKS_DIFFTIME */
08679 
08680 // Magic number declaration and definition for ctime and ctime_r ()
08681 static const int ctime_buf_size = 26;
08682 
08683 ACE_INLINE ACE_TCHAR *
08684 ACE_OS::ctime (const time_t *t)
08685 {
08686   ACE_OS_TRACE ("ACE_OS::ctime");
08687 #if defined (ACE_HAS_BROKEN_CTIME)
08688   ACE_OSCALL_RETURN (::asctime (::localtime (t)), char *, 0);
08689 #elif defined(ACE_PSOS) && ! defined (ACE_PSOS_HAS_TIME)
08690   return "ctime-return";
08691 #elif defined (ACE_HAS_WINCE)
08692   static ACE_TCHAR buf [ctime_buf_size];
08693   return ACE_OS::ctime_r (t,
08694                           buf,
08695                           ctime_buf_size);
08696 #elif defined (ACE_USES_WCHAR)
08697   ACE_OSCALL_RETURN (::_wctime (t), wchar_t *, 0);
08698 #else
08699   ACE_OSCALL_RETURN (::ctime (t), char *, 0);
08700 # endif /* ACE_HAS_BROKEN_CTIME */
08701 }
08702 
08703 #if !defined (ACE_HAS_WINCE)  /* CE version in OS.cpp */
08704 ACE_INLINE ACE_TCHAR *
08705 ACE_OS::ctime_r (const time_t *t, ACE_TCHAR *buf, int buflen)
08706 {
08707   ACE_OS_TRACE ("ACE_OS::ctime_r");
08708 
08709 #if defined (ACE_HAS_REENTRANT_FUNCTIONS)
08710 #   if defined (ACE_HAS_2_PARAM_ASCTIME_R_AND_CTIME_R)
08711   if (buflen < ctime_buf_size)
08712     {
08713       errno = ERANGE;
08714       return 0;
08715     }
08716 #      if defined (DIGITAL_UNIX)
08717   ACE_OSCALL_RETURN (::_Pctime_r (t, buf), ACE_TCHAR *, 0);
08718 #      else /* DIGITAL_UNIX */
08719   ACE_OSCALL_RETURN (::ctime_r (t, buf), ACE_TCHAR *, 0);
08720 #      endif /* DIGITAL_UNIX */
08721   return buf;
08722 #   else /* ACE_HAS_2_PARAM_ASCTIME_R_AND_CTIME_R */
08723 
08724 #      if defined (ACE_CTIME_R_RETURNS_INT)
08725   return (::ctime_r (t, buf, buflen) == -1 ? 0 : buf);
08726 #      else /* ACE_CTIME_R_RETURNS_INT */
08727   ACE_OSCALL_RETURN (::ctime_r (t, buf, buflen), ACE_TCHAR *, 0);
08728 #      endif /* ACE_CTIME_R_RETURNS_INT */
08729 
08730 #   endif /* ACE_HAS_2_PARAM_ASCTIME_R_AND_CTIME_R */
08731 #else /* ACE_HAS_REENTRANT_FUNCTIONS */
08732 #   if defined(ACE_PSOS) && ! defined (ACE_PSOS_HAS_TIME)
08733   ACE_OS::strsncpy (buf, "ctime-return", buflen);
08734   return buf;
08735 #   else /* ACE_PSOS && !ACE_PSOS_HAS_TIME */
08736   if (buflen < ctime_buf_size)
08737     {
08738       errno = ERANGE;
08739       return 0;
08740     }
08741 
08742   ACE_TCHAR *result;
08743 #     if defined (ACE_USES_WCHAR)
08744   ACE_OSCALL (::_wctime (t), wchar_t *, 0, result);
08745 #     else /* ACE_USES_WCHAR */
08746   ACE_OSCALL (::ctime (t), char *, 0, result);
08747 #     endif /* ACE_USES_WCHAR */
08748   if (result != 0)
08749     ACE_OS::strsncpy (buf, result, buflen);
08750   return buf;
08751 #   endif /* ACE_PSOS && !ACE_PSOS_HAS_TIME */
08752 #endif /* ACE_HAS_REENTRANT_FUNCTIONS */
08753 }
08754 #endif /* !ACE_HAS_WINCE */
08755 
08756 ACE_INLINE struct tm *
08757 ACE_OS::localtime (const time_t *t)
08758 {
08759 #if !defined (ACE_HAS_WINCE) && !defined (ACE_PSOS) || defined (ACE_PSOS_HAS_TIME)
08760   ACE_OS_TRACE ("ACE_OS::localtime");
08761   ACE_OSCALL_RETURN (::localtime (t), struct tm *, 0);
08762 #else
08763   // @@ Don't you start wondering what kind of functions
08764   //    does WinCE really support?
08765   ACE_UNUSED_ARG (t);
08766   ACE_NOTSUP_RETURN (0);
08767 #endif /* ACE_HAS_WINCE && !ACE_PSOS || ACE_PSOS_HAS_TIME */
08768 }
08769 
08770 ACE_INLINE struct tm *
08771 ACE_OS::gmtime (const time_t *t)
08772 {
08773 #if !defined (ACE_HAS_WINCE) && !defined (ACE_PSOS) || defined (ACE_PSOS_HAS_TIME)
08774   ACE_OS_TRACE ("ACE_OS::gmtime");
08775   ACE_OSCALL_RETURN (::gmtime (t), struct tm *, 0);
08776 #else
08777   // @@ WinCE doesn't have gmtime also.
08778   ACE_UNUSED_ARG (t);
08779   ACE_NOTSUP_RETURN (0);
08780 #endif /* ACE_HAS_WINCE && !ACE_PSOS || ACE_PSOS_HAS_TIME */
08781 }
08782 
08783 ACE_INLINE struct tm *
08784 ACE_OS::gmtime_r (const time_t *t, struct tm *res)
08785 {
08786   ACE_OS_TRACE ("ACE_OS::gmtime_r");
08787 #if defined (ACE_HAS_REENTRANT_FUNCTIONS)
08788 # if defined (DIGITAL_UNIX)
08789   ACE_OSCALL_RETURN (::_Pgmtime_r (t, res), struct tm *, 0);
08790 # elif defined (HPUX_10)
08791   return (::gmtime_r (t, res) == 0 ? res : (struct tm *) 0);
08792 # else
08793   ACE_OSCALL_RETURN (::gmtime_r (t, res), struct tm *, 0);
08794 # endif /* DIGITAL_UNIX */
08795 #elif !defined (ACE_HAS_WINCE) && !defined(ACE_PSOS) || defined (ACE_PSOS_HAS_TIME)
08796   struct tm *result;
08797   ACE_OSCALL (::gmtime (t), struct tm *, 0, result) ;
08798   if (result != 0)
08799     *res = *result;
08800   return res;
08801 #else
08802   // @@ Same as ACE_OS::gmtime (), you need to implement it
08803   //    yourself.
08804   ACE_UNUSED_ARG (t);
08805   ACE_UNUSED_ARG (res);
08806   ACE_NOTSUP_RETURN (0);
08807 #endif /* ACE_HAS_REENTRANT_FUNCTIONS */
08808 }
08809 
08810 ACE_INLINE char *
08811 ACE_OS::asctime (const struct tm *t)
08812 {
08813 #if !defined (ACE_HAS_WINCE) && !defined(ACE_PSOS) || defined (ACE_PSOS_HAS_TIME)
08814   ACE_OS_TRACE ("ACE_OS::asctime");
08815   ACE_OSCALL_RETURN (::asctime (t), char *, 0);
08816 #else
08817   // @@ WinCE doesn't have gmtime also.
08818   ACE_UNUSED_ARG (t);
08819   ACE_NOTSUP_RETURN (0);
08820 #endif /*  !ACE_HAS_WINCE && !ACE_PSOS || ACE_PSOS_HAS_TIME */
08821 }
08822 
08823 ACE_INLINE char *
08824 ACE_OS::asctime_r (const struct tm *t, char *buf, int buflen)
08825 {
08826   ACE_OS_TRACE ("ACE_OS::asctime_r");
08827 #if defined (ACE_HAS_REENTRANT_FUNCTIONS)
08828 # if defined (ACE_HAS_2_PARAM_ASCTIME_R_AND_CTIME_R)
08829   char *result;
08830 #   if defined (DIGITAL_UNIX)
08831   ACE_OSCALL (::_Pasctime_r (t, buf), char *, 0, result);
08832 #   else
08833   ACE_OSCALL (::asctime_r (t, buf), char *, 0, result);
08834 #   endif /* DIGITAL_UNIX */
08835   ACE_OS::strsncpy (buf, result, buflen);
08836   return buf;
08837 # else
08838 #   if defined (HPUX_10)
08839   return (::asctime_r(t, buf, buflen) == 0 ? buf : (char *)0);
08840 #   else
08841   ACE_OSCALL_RETURN (::asctime_r (t, buf, buflen), char *, 0);
08842 #   endif /* HPUX_10 */
08843 # endif /* ACE_HAS_2_PARAM_ASCTIME_R_AND_CTIME_R */
08844 #elif ! defined (ACE_HAS_WINCE) && !defined(ACE_PSOS) || defined (ACE_PSOS_HAS_TIME)
08845   char *result;
08846   ACE_OSCALL (::asctime (t), char *, 0, result);
08847   ACE_OS::strsncpy (buf, result, buflen);
08848   return buf;
08849 #else
08850   // @@ Same as ACE_OS::asctime (), you need to implement it
08851   //    yourself.
08852   ACE_UNUSED_ARG (t);
08853   ACE_UNUSED_ARG (buf);
08854   ACE_UNUSED_ARG (buflen);
08855   ACE_NOTSUP_RETURN (0);
08856 #endif /* ACE_HAS_REENTRANT_FUNCTIONS */
08857 }
08858 
08859 ACE_INLINE size_t
08860 ACE_OS::strftime (char *s, size_t maxsize, const char *format,
08861                   const struct tm *timeptr)
08862 {
08863 #if !defined (ACE_HAS_WINCE) && !defined(ACE_PSOS) || defined (ACE_PSOS_HAS_TIME)
08864   return ::strftime (s, maxsize, format, timeptr);
08865 #else
08866   ACE_UNUSED_ARG (s);
08867   ACE_UNUSED_ARG (maxsize);
08868   ACE_UNUSED_ARG (format);
08869   ACE_UNUSED_ARG (timeptr);
08870   ACE_NOTSUP_RETURN (0);
08871 #endif /* !ACE_HAS_WINCE && !ACE_PSOS || ACE_PSOS_HAS_TIME */
08872 }
08873 
08874 ACE_INLINE int
08875 ACE_OS::flock_init (ACE_OS::ace_flock_t *lock,
08876                     int flags,
08877                     const ACE_TCHAR *name,
08878                     mode_t perms)
08879 {
08880   ACE_OS_TRACE ("ACE_OS::flock_init");
08881 #if defined (CHORUS)
08882   lock->lockname_ = 0;
08883   // Let's see if it already exists.
08884   lock->handle_ = ACE_OS::shm_open (name,
08885                                     flags | O_CREAT | O_EXCL,
08886                                     perms);
08887   if (lock->handle_ == ACE_INVALID_HANDLE)
08888     {
08889       if (errno == EEXIST)
08890         // It's already there, so we'll just open it.
08891         lock->handle_ = ACE_OS::shm_open (name,
08892                                           flags | O_CREAT,
08893                                           ACE_DEFAULT_FILE_PERMS);
08894       else
08895         return -1;
08896     }
08897   else
08898     {
08899       // We own this shared memory object!  Let's set its size.
08900       if (ACE_OS::ftruncate (lock->handle_,
08901                              sizeof (ACE_mutex_t)) == -1)
08902         return -1;
08903       // Note that only the owner can destroy a file lock...
08904       ACE_ALLOCATOR_RETURN (lock->lockname_,
08905                             ACE_OS::strdup (name),
08906                             -1);
08907     }
08908   if (lock->handle_ == ACE_INVALID_HANDLE)
08909     return -1;
08910 
08911   lock->process_lock_ =
08912     (ACE_mutex_t *) ACE_OS::mmap (0,
08913                                   sizeof (ACE_mutex_t),
08914                                   PROT_RDWR,
08915                                   MAP_SHARED,
08916                                   lock->handle_,
08917                                   0);
08918   if (lock->process_lock_ == MAP_FAILED)
08919     return -1;
08920 
08921   if (lock->lockname_
08922       // Only initialize it if we're the one who created it.
08923       && ACE_OS::mutex_init (lock->process_lock_,
08924                              USYNC_PROCESS,
08925                              name,
08926                              0) != 0)
08927         return -1;
08928   return 0;
08929 #else
08930 #if defined (ACE_WIN32)
08931   // Once initialized, these values are never changed.
08932   lock->overlapped_.Internal = 0;
08933   lock->overlapped_.InternalHigh = 0;
08934   lock->overlapped_.OffsetHigh = 0;
08935   lock->overlapped_.hEvent = 0;
08936 #endif /* ACE_WIN32 */
08937   lock->handle_ = ACE_INVALID_HANDLE;
08938   lock->lockname_ = 0;
08939 
08940   if (name != 0)
08941     {
08942       ACE_OSCALL (ACE_OS::open (name, flags, perms),
08943                   ACE_HANDLE,
08944                   ACE_INVALID_HANDLE,
08945                   lock->handle_);
08946       lock->lockname_ = ACE_OS::strdup (name);
08947       return lock->handle_ == ACE_INVALID_HANDLE ? -1 : 0;
08948     }
08949   else
08950     return 0;
08951 #endif /* CHORUS */
08952 }
08953 
08954 #if defined (ACE_WIN32)
08955 ACE_INLINE void
08956 ACE_OS::adjust_flock_params (ACE_OS::ace_flock_t *lock,
08957                              short whence,
08958                              off_t &start,
08959                              off_t &len)
08960 {
08961   switch (whence)
08962     {
08963     case SEEK_SET:
08964       break;
08965     case SEEK_CUR:
08966       start += SetFilePointer (lock->handle_, 0, 0, FILE_CURRENT);
08967       break;
08968     case SEEK_END:
08969       start += ::GetFileSize (lock->handle_, 0);
08970       break;
08971     }
08972   lock->overlapped_.Offset = start;
08973   if (len == 0)
08974     len = ::GetFileSize (lock->handle_,
08975                          0) - start;
08976 }
08977 #endif /* ACE_WIN32 */
08978 
08979 ACE_INLINE int
08980 ACE_OS::flock_wrlock (ACE_OS::ace_flock_t *lock,
08981                       short whence,
08982                       off_t start,
08983                       off_t len)
08984 {
08985   ACE_OS_TRACE ("ACE_OS::flock_wrlock");
08986 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
08987   ACE_OS::adjust_flock_params (lock, whence, start, len);
08988 #  if defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)
08989   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::LockFileEx (lock->handle_,
08990                                                         LOCKFILE_EXCLUSIVE_LOCK,
08991                                                         0,
08992                                                         len,
08993                                                         0,
08994                                                         &lock->overlapped_),
08995                                           ace_result_), int, -1);
08996 #  else /* ACE_HAS_WINNT4 && (ACE_HAS_WINNT4 != 0) */
08997   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::LockFile (lock->handle_,
08998                                                       lock->overlapped_.Offset,
08999                                                       0,
09000                                                       len,
09001                                                       0),
09002                                           ace_result_), int, -1);
09003 #  endif /* ACE_HAS_WINNT4 && (ACE_HAS_WINNT4 != 0) */
09004 #elif defined (CHORUS)
09005   ACE_UNUSED_ARG (whence);
09006   ACE_UNUSED_ARG (start);
09007   ACE_UNUSED_ARG (len);
09008   return ACE_OS::mutex_lock (lock->process_lock_);
09009 #elif defined (ACE_LACKS_FILELOCKS)
09010   ACE_UNUSED_ARG (lock);
09011   ACE_UNUSED_ARG (whence);
09012   ACE_UNUSED_ARG (start);
09013   ACE_UNUSED_ARG (len);
09014   ACE_NOTSUP_RETURN (-1);
09015 #else
09016   lock->lock_.l_whence = whence;
09017   lock->lock_.l_start = start;
09018   lock->lock_.l_len = len;
09019   lock->lock_.l_type = F_WRLCK;         // set write lock
09020   // block, if no access
09021   ACE_OSCALL_RETURN (ACE_OS::fcntl (lock->handle_, F_SETLKW,
09022                                     ACE_reinterpret_cast (long, &lock->lock_)),
09023                      int, -1);
09024 #endif /* ACE_WIN32 */
09025 }
09026 
09027 ACE_INLINE int
09028 ACE_OS::flock_rdlock (ACE_OS::ace_flock_t *lock,
09029                       short whence,
09030                       off_t start,
09031                       off_t len)
09032 {
09033   ACE_OS_TRACE ("ACE_OS::flock_rdlock");
09034 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
09035   ACE_OS::adjust_flock_params (lock, whence, start, len);
09036 #  if defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)
09037   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::LockFileEx (lock->handle_,
09038                                                         0,
09039                                                         0,
09040                                                         len,
09041                                                         0,
09042                                                         &lock->overlapped_),
09043                                           ace_result_), int, -1);
09044 #  else /* ACE_HAS_WINNT4 && (ACE_HAS_WINNT4 != 0) */
09045   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::LockFile (lock->handle_,
09046                                                       lock->overlapped_.Offset,
09047                                                       0,
09048                                                       len,
09049                                                       0),
09050                                           ace_result_), int, -1);
09051 #  endif /* ACE_HAS_WINNT4 && (ACE_HAS_WINNT4 != 0) */
09052 #elif defined (CHORUS)
09053   ACE_UNUSED_ARG (whence);
09054   ACE_UNUSED_ARG (start);
09055   ACE_UNUSED_ARG (len);
09056   return ACE_OS::mutex_lock (lock->process_lock_);
09057 #elif defined (ACE_LACKS_FILELOCKS)
09058   ACE_UNUSED_ARG (lock);
09059   ACE_UNUSED_ARG (whence);
09060   ACE_UNUSED_ARG (start);
09061   ACE_UNUSED_ARG (len);
09062   ACE_NOTSUP_RETURN (-1);
09063 #else
09064   lock->lock_.l_whence = whence;
09065   lock->lock_.l_start = start;
09066   lock->lock_.l_len = len;
09067   lock->lock_.l_type = F_RDLCK;         // set read lock
09068   // block, if no access
09069   ACE_OSCALL_RETURN (ACE_OS::fcntl (lock->handle_, F_SETLKW,
09070                                     ACE_reinterpret_cast (long, &lock->lock_)),
09071                      int, -1);
09072 #endif /* ACE_WIN32 */
09073 }
09074 
09075 ACE_INLINE int
09076 ACE_OS::flock_trywrlock (ACE_OS::ace_flock_t *lock,
09077                          short whence,
09078                          off_t start,
09079                          off_t len)
09080 {
09081   ACE_OS_TRACE ("ACE_OS::ace_flock_trywrlock");
09082 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
09083 #  if defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)
09084   ACE_OS::adjust_flock_params (lock, whence, start, len);
09085   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::LockFileEx (lock->handle_,
09086                                                         LOCKFILE_FAIL_IMMEDIATELY | LOCKFILE_EXCLUSIVE_LOCK,
09087                                                         0,
09088                                                         len,
09089                                                         0,
09090                                                         &lock->overlapped_),
09091                                           ace_result_), int, -1);
09092 #  else /* ACE_HAS_WINNT4 && (ACE_HAS_WINNT4 != 0) */
09093   ACE_UNUSED_ARG (lock);
09094   ACE_UNUSED_ARG (whence);
09095   ACE_UNUSED_ARG (start);
09096   ACE_UNUSED_ARG (len);
09097   ACE_NOTSUP_RETURN (-1);
09098 #  endif /* ACE_HAS_WINNT4 && (ACE_HAS_WINNT4 != 0) */
09099 #elif defined (CHORUS)
09100   ACE_UNUSED_ARG (whence);
09101   ACE_UNUSED_ARG (start);
09102   ACE_UNUSED_ARG (len);
09103   return ACE_OS::mutex_trylock (lock->process_lock_);
09104 #elif defined (ACE_LACKS_FILELOCKS)
09105   ACE_UNUSED_ARG (lock);
09106   ACE_UNUSED_ARG (whence);
09107   ACE_UNUSED_ARG (start);
09108   ACE_UNUSED_ARG (len);
09109   ACE_NOTSUP_RETURN (-1);
09110 #else
09111   lock->lock_.l_whence = whence;
09112   lock->lock_.l_start = start;
09113   lock->lock_.l_len = len;
09114   lock->lock_.l_type = F_WRLCK;         // set write lock
09115 
09116   int result = 0;
09117   // Does not block, if no access, returns -1 and set errno = EBUSY;
09118   ACE_OSCALL (ACE_OS::fcntl (lock->handle_,
09119                              F_SETLK,
09120                              ACE_reinterpret_cast (long, &lock->lock_)),
09121               int, -1, result);
09122 
09123 # if ! defined (ACE_PSOS)
09124   if (result == -1 && (errno == EACCES || errno == EAGAIN))
09125     errno = EBUSY;
09126 # endif /* ! defined (ACE_PSOS) */
09127 
09128   return result;
09129 #endif /* ACE_WIN32 */
09130 }
09131 
09132 ACE_INLINE int
09133 ACE_OS::flock_tryrdlock (ACE_OS::ace_flock_t *lock,
09134                          short whence,
09135                          off_t start,
09136                          off_t len)
09137 {
09138   ACE_OS_TRACE ("ACE_OS::ace_flock_tryrdlock");
09139 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
09140 #  if defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)
09141   ACE_OS::adjust_flock_params (lock, whence, start, len);
09142   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::LockFileEx (lock->handle_,
09143                                                         LOCKFILE_FAIL_IMMEDIATELY,
09144                                                         0,
09145                                                         len,
09146                                                         0,
09147                                                         &lock->overlapped_),
09148                                           ace_result_), int, -1);
09149 #  else /* ACE_HAS_WINNT4 && (ACE_HAS_WINNT4 != 0) */
09150   ACE_UNUSED_ARG (lock);
09151   ACE_UNUSED_ARG (whence);
09152   ACE_UNUSED_ARG (start);
09153   ACE_UNUSED_ARG (len);
09154   ACE_NOTSUP_RETURN (-1);
09155 #  endif /* ACE_HAS_WINNT4 && (ACE_HAS_WINNT4 != 0) */
09156 #elif defined (CHORUS)
09157   ACE_UNUSED_ARG (whence);
09158   ACE_UNUSED_ARG (start);
09159   ACE_UNUSED_ARG (len);
09160   return ACE_OS::mutex_trylock (lock->process_lock_);
09161 #elif defined (ACE_LACKS_FILELOCKS)
09162   ACE_UNUSED_ARG (lock);
09163   ACE_UNUSED_ARG (whence);
09164   ACE_UNUSED_ARG (start);
09165   ACE_UNUSED_ARG (len);
09166   ACE_NOTSUP_RETURN (-1);
09167 #else
09168   lock->lock_.l_whence = whence;
09169   lock->lock_.l_start = start;
09170   lock->lock_.l_len = len;
09171   lock->lock_.l_type = F_RDLCK;         // set read lock
09172 
09173   int result = 0;
09174   // Does not block, if no access, returns -1 and set errno = EBUSY;
09175   ACE_OSCALL (ACE_OS::fcntl (lock->handle_, F_SETLK,
09176                              ACE_reinterpret_cast (long, &lock->lock_)),
09177               int, -1, result);
09178 
09179 # if ! defined (ACE_PSOS)
09180   if (result == -1 && (errno == EACCES || errno == EAGAIN))
09181     errno = EBUSY;
09182 # endif /* ! defined (ACE_PSOS) */
09183 
09184   return result;
09185 #endif /* ACE_WIN32 */
09186 }
09187 
09188 ACE_INLINE int
09189 ACE_OS::flock_unlock (ACE_OS::ace_flock_t *lock,
09190                       short whence,
09191                       off_t start,
09192                       off_t len)
09193 {
09194   ACE_OS_TRACE ("ACE_OS::flock_unlock");
09195 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
09196   ACE_OS::adjust_flock_params (lock, whence, start, len);
09197   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::UnlockFile (lock->handle_,
09198                                                         lock->overlapped_.Offset,
09199                                                         0,
09200                                                         len,
09201                                                         0),
09202                                           ace_result_), int, -1);
09203 #elif defined (CHORUS)
09204   ACE_UNUSED_ARG (whence);
09205   ACE_UNUSED_ARG (start);
09206   ACE_UNUSED_ARG (len);
09207   return ACE_OS::mutex_unlock (lock->process_lock_);
09208 #elif defined (ACE_LACKS_FILELOCKS)
09209   ACE_UNUSED_ARG (lock);
09210   ACE_UNUSED_ARG (whence);
09211   ACE_UNUSED_ARG (start);
09212   ACE_UNUSED_ARG (len);
09213   ACE_NOTSUP_RETURN (-1);
09214 #else
09215   lock->lock_.l_whence = whence;
09216   lock->lock_.l_start = start;
09217   lock->lock_.l_len = len;
09218   lock->lock_.l_type = F_UNLCK;   // Unlock file.
09219 
09220   // release lock
09221   ACE_OSCALL_RETURN (ACE_OS::fcntl (lock->handle_, F_SETLK,
09222                                     ACE_reinterpret_cast (long, &lock->lock_)),
09223                      int, -1);
09224 #endif /* ACE_WIN32 */
09225 }
09226 
09227 ACE_INLINE int
09228 ACE_OS::flock_destroy (ACE_OS::ace_flock_t *lock,
09229                        int unlink_file)
09230 {
09231   ACE_OS_TRACE ("ACE_OS::flock_destroy");
09232   if (lock->handle_ != ACE_INVALID_HANDLE)
09233     {
09234       ACE_OS::flock_unlock (lock);
09235       // Close the handle.
09236       ACE_OS::close (lock->handle_);
09237       lock->handle_ = ACE_INVALID_HANDLE;
09238 #if defined (CHORUS)
09239       // Are we the owner?
09240       if (lock->process_lock_ && lock->lockname_ != 0)
09241         {
09242           // Only destroy the lock if we're the owner
09243           ACE_OS::mutex_destroy (lock->process_lock_);
09244           ACE_OS::munmap (lock->process_lock_,
09245                           sizeof (ACE_mutex_t));
09246           if (unlink_file)
09247             ACE_OS::shm_unlink (lock->lockname_);
09248           ACE_OS::free (ACE_static_cast (void *,
09249                                          ACE_const_cast (ACE_TCHAR *,
09250                                                          lock->lockname_)));
09251         }
09252       else if (lock->process_lock_)
09253         // Just unmap the memory.
09254         ACE_OS::munmap (lock->process_lock_,
09255                         sizeof (ACE_mutex_t));
09256 #else
09257       if (lock->lockname_ != 0)
09258         {
09259           if (unlink_file)
09260             ACE_OS::unlink (lock->lockname_);
09261           ACE_OS::free (ACE_static_cast (void *,
09262                                          ACE_const_cast (ACE_TCHAR *,
09263                                                          lock->lockname_)));
09264         }
09265 #endif /* CHORUS */
09266       lock->lockname_ = 0;
09267     }
09268   return 0;
09269 }
09270 
09271 ACE_INLINE int
09272 ACE_OS::execv (const char *path,
09273                char *const argv[])
09274 {
09275   ACE_OS_TRACE ("ACE_OS::execv");
09276 #if defined (ACE_LACKS_EXEC)
09277   ACE_UNUSED_ARG (path);
09278   ACE_UNUSED_ARG (argv);
09279 
09280   ACE_NOTSUP_RETURN (-1);
09281 #elif defined (CHORUS)
09282   KnCap cactorcap;
09283   int result = ::afexecv (path, &cactorcap, 0, argv);
09284   if (result != -1)
09285     ACE_OS::actorcaps_[result] = cactorcap;
09286   return result;
09287 #elif defined (ACE_WIN32)
09288 # if defined (__BORLANDC__) /* VSB */
09289   return ::execv (path, argv);
09290 # elif defined (__MINGW32__)
09291   return ::_execv (path, (char *const *) argv);
09292 # else
09293   return ::_execv (path, (const char *const *) argv);
09294 # endif /* __BORLANDC__ */
09295 #elif defined (ACE_LACKS_POSIX_PROTOTYPES)
09296   ACE_OSCALL_RETURN (::execv (path, (const char **) argv), int, -1);
09297 #else
09298   ACE_OSCALL_RETURN (::execv (path, argv), int, -1);
09299 #endif /* ACE_LACKS_EXEC */
09300 }
09301 
09302 ACE_INLINE int
09303 ACE_OS::execve (const char *path,
09304                 char *const argv[],
09305                 char *const envp[])
09306 {
09307   ACE_OS_TRACE ("ACE_OS::execve");
09308 #if defined (ACE_LACKS_EXEC)
09309   ACE_UNUSED_ARG (path);
09310   ACE_UNUSED_ARG (argv);
09311   ACE_UNUSED_ARG (envp);
09312 
09313   ACE_NOTSUP_RETURN (-1);
09314 #elif defined(CHORUS)
09315   KnCap cactorcap;
09316   int result = ::afexecve (path, &cactorcap, 0, argv, envp);
09317   if (result != -1)
09318     ACE_OS::actorcaps_[result] = cactorcap;
09319   return result;
09320 #elif defined (ACE_WIN32)
09321 # if defined (__BORLANDC__) /* VSB */
09322   return ::execve (path, argv, envp);
09323 # elif defined (__MINGW32__)
09324   return ::_execve (path, (char *const *) argv, (char *const *) envp);
09325 # else
09326   return ::_execve (path, (const char *const *) argv, (const char *const *) envp);
09327 # endif /* __BORLANDC__ */
09328 #elif defined (ACE_LACKS_POSIX_PROTOTYPES)
09329   ACE_OSCALL_RETURN (::execve (path, (const char **) argv, (char **) envp), int, -1);
09330 #else
09331   ACE_OSCALL_RETURN (::execve (path, argv, envp), int, -1);
09332 #endif /* ACE_LACKS_EXEC */
09333 }
09334 
09335 ACE_INLINE int
09336 ACE_OS::execvp (const char *file,
09337                 char *const argv[])
09338 {
09339   ACE_OS_TRACE ("ACE_OS::execvp");
09340 #if defined (ACE_LACKS_EXEC)
09341   ACE_UNUSED_ARG (file);
09342   ACE_UNUSED_ARG (argv);
09343 
09344   ACE_NOTSUP_RETURN (-1);
09345 #elif defined(CHORUS)
09346   KnCap cactorcap;
09347   int result = ::afexecvp (file, &cactorcap, 0, argv);
09348   if (result != -1)
09349     ACE_OS::actorcaps_[result] = cactorcap;
09350   return result;
09351 #elif defined (ACE_WIN32)
09352 # if defined (__BORLANDC__) /* VSB */
09353   return ::execvp (file, argv);
09354 # elif defined (__MINGW32__)
09355   return ::_execvp (file, (char *const *) argv);
09356 # else
09357   return ::_execvp (file, (const char *const *) argv);
09358 # endif /* __BORLANDC__ */
09359 #elif defined (ACE_LACKS_POSIX_PROTOTYPES)
09360   ACE_OSCALL_RETURN (::execvp (file, (const char **) argv), int, -1);
09361 #else
09362   ACE_OSCALL_RETURN (::execvp (file, argv), int, -1);
09363 #endif /* ACE_LACKS_EXEC */
09364 }
09365 
09366 ACE_INLINE FILE *
09367 ACE_OS::fdopen (ACE_HANDLE handle, const ACE_TCHAR *mode)
09368 {
09369   ACE_OS_TRACE ("ACE_OS::fdopen");
09370 # if defined (ACE_HAS_WINCE)
09371   ACE_OSCALL_RETURN (::_wfdopen (handle, mode), FILE*, 0);
09372 # elif defined (ACE_WIN32)
09373   // kernel file handle -> FILE* conversion...
09374   // Options: _O_APPEND, _O_RDONLY and _O_TEXT are lost
09375 
09376   FILE *file = 0;
09377 
09378 #  if defined (ACE_WIN64)
09379   int crt_handle = ::_open_osfhandle (intptr_t (handle), 0);
09380 #  else
09381   int crt_handle = ::_open_osfhandle (long (handle), 0);
09382 #  endif /* ACE_WIN64 */
09383 
09384   if (crt_handle != -1)
09385     {
09386 #   if defined(__BORLANDC__) /* VSB */
09387       file = ::_fdopen (crt_handle, (char *) mode);
09388 #   elif defined (ACE_USES_WCHAR)
09389       file = ::_wfdopen (crt_handle, mode);
09390 #   else
09391       file = ::_fdopen (crt_handle, mode);
09392 #   endif /* __BORLANDC__ */
09393 
09394       if (!file)
09395         {
09396 #   if (defined(__BORLANDC__) && __BORLANDC__ >= 0x0530)
09397           ::_rtl_close (crt_handle);
09398 #   else
09399           ::_close (crt_handle);
09400 #   endif /* (defined(__BORLANDC__) && __BORLANDC__ >= 0x0530) */
09401         }
09402     }
09403 
09404   return file;
09405 # elif defined (ACE_PSOS)
09406   // @@ it may be possible to implement this for pSOS,
09407   // but it isn't obvious how to do this (perhaps via
09408   // f_stat to glean the default volume, and then open_fn ?)
09409   ACE_UNUSED_ARG (handle);
09410   ACE_UNUSED_ARG (mode);
09411   ACE_NOTSUP_RETURN (0);
09412 # else
09413   ACE_OSCALL_RETURN (::fdopen (handle, mode), FILE *, 0);
09414 # endif /* ACE_HAS_WINCE */
09415 }
09416 
09417 ACE_INLINE int
09418 ACE_OS::getrlimit (int resource, struct rlimit *rl)
09419 {
09420   ACE_OS_TRACE ("ACE_OS::getrlimit");
09421 
09422 #if defined (ACE_LACKS_RLIMIT)
09423   ACE_UNUSED_ARG (resource);
09424   ACE_UNUSED_ARG (rl);
09425 
09426   ACE_NOTSUP_RETURN (-1);
09427 #else
09428 # if defined (ACE_HAS_RLIMIT_RESOURCE_ENUM)
09429   ACE_OSCALL_RETURN (::getrlimit ((ACE_HAS_RLIMIT_RESOURCE_ENUM) resource, rl), int, -1);
09430 # else
09431   ACE_OSCALL_RETURN (::getrlimit (resource, rl), int, -1);
09432 # endif /* ACE_HAS_RLIMIT_RESOURCE_ENUM */
09433 #endif /* ACE_LACKS_RLIMIT */
09434 }
09435 
09436 ACE_INLINE int
09437 ACE_OS::setrlimit (int resource, ACE_SETRLIMIT_TYPE *rl)
09438 {
09439   ACE_OS_TRACE ("ACE_OS::setrlimit");
09440 
09441 #if defined (ACE_LACKS_RLIMIT)
09442   ACE_UNUSED_ARG (resource);
09443   ACE_UNUSED_ARG (rl);
09444 
09445   ACE_NOTSUP_RETURN (-1);
09446 #else
09447 # if defined (ACE_HAS_RLIMIT_RESOURCE_ENUM)
09448   ACE_OSCALL_RETURN (::setrlimit ((ACE_HAS_RLIMIT_RESOURCE_ENUM) resource, rl), int, -1);
09449 # else
09450   ACE_OSCALL_RETURN (::setrlimit (resource, rl), int, -1);
09451 # endif /* ACE_HAS_RLIMIT_RESOURCE_ENUM */
09452 #endif /* ACE_LACKS_RLIMIT */
09453 }
09454 
09455 ACE_INLINE int
09456 ACE_OS::socketpair (int domain, int type,
09457                     int protocol, ACE_HANDLE sv[2])
09458 {
09459   ACE_OS_TRACE ("ACE_OS::socketpair");
09460 #if defined (ACE_WIN32) || defined (ACE_LACKS_SOCKETPAIR)
09461   ACE_UNUSED_ARG (domain);
09462   ACE_UNUSED_ARG (type);
09463   ACE_UNUSED_ARG (protocol);
09464   ACE_UNUSED_ARG (sv);
09465 
09466   ACE_NOTSUP_RETURN (-1);
09467 #else
09468   ACE_OSCALL_RETURN (::socketpair (domain, type, protocol, sv),
09469                      int, -1);
09470 #endif /* ACE_WIN32 */
09471 }
09472 
09473 ACE_INLINE ACE_HANDLE
09474 ACE_OS::dup (ACE_HANDLE handle)
09475 {
09476   ACE_OS_TRACE ("ACE_OS::dup");
09477 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
09478   ACE_HANDLE new_fd;
09479   if (::DuplicateHandle(::GetCurrentProcess (),
09480                         handle,
09481                         ::GetCurrentProcess(),
09482                         &new_fd,
09483                         0,
09484                         TRUE,
09485                         DUPLICATE_SAME_ACCESS))
09486     return new_fd;
09487   else
09488     ACE_FAIL_RETURN (ACE_INVALID_HANDLE);
09489   /* NOTREACHED */
09490 #elif defined (VXWORKS) || defined (ACE_PSOS)
09491   ACE_UNUSED_ARG (handle);
09492   ACE_NOTSUP_RETURN (-1);
09493 #elif defined (ACE_HAS_WINCE)
09494   ACE_UNUSED_ARG (handle);
09495   ACE_NOTSUP_RETURN (0);
09496 #else
09497   ACE_OSCALL_RETURN (::dup (handle), ACE_HANDLE, ACE_INVALID_HANDLE);
09498 #endif /* ACE_WIN32 && !ACE_HAS_WINCE */
09499 }
09500 
09501 ACE_INLINE int
09502 ACE_OS::dup2 (ACE_HANDLE oldhandle, ACE_HANDLE newhandle)
09503 {
09504   ACE_OS_TRACE ("ACE_OS::dup2");
09505 #if defined (ACE_WIN32) || defined (VXWORKS) || defined (ACE_PSOS)
09506   // msvcrt has _dup2 ?!
09507   ACE_UNUSED_ARG (oldhandle);
09508   ACE_UNUSED_ARG (newhandle);
09509 
09510   ACE_NOTSUP_RETURN (-1);
09511 #else
09512   ACE_OSCALL_RETURN (::dup2 (oldhandle, newhandle), int, -1);
09513 #endif /* ACE_WIN32 || VXWORKS || ACE_PSOS */
09514 }
09515 
09516 #if defined (ghs) && defined (ACE_HAS_PENTIUM) && !defined (ACE_WIN32)
09517   extern "C" ACE_hrtime_t ACE_gethrtime ();
09518 #endif /* ghs && ACE_HAS_PENTIUM */
09519 
09520 ACE_INLINE ACE_hrtime_t
09521 ACE_OS::gethrtime (const ACE_HRTimer_Op op)
09522 {
09523   ACE_OS_TRACE ("ACE_OS::gethrtime");
09524 #if defined (ACE_HAS_HI_RES_TIMER)
09525   ACE_UNUSED_ARG (op);
09526   return ::gethrtime ();
09527 #elif defined (ACE_HAS_AIX_HI_RES_TIMER)
09528   ACE_UNUSED_ARG (op);
09529   timebasestruct_t tb;
09530 
09531   ::read_real_time(&tb, TIMEBASE_SZ);
09532   ::time_base_to_time(&tb, TIMEBASE_SZ);
09533 
09534   return ACE_hrtime_t(tb.tb_high) * ACE_ONE_SECOND_IN_NSECS + tb.tb_low;
09535 #elif defined (ghs) && defined (ACE_HAS_PENTIUM) && !defined (ACE_WIN32)
09536   ACE_UNUSED_ARG (op);
09537   // Use .obj/gethrtime.o, which was compiled with g++.
09538   return ACE_gethrtime ();
09539 #elif (defined(__KCC) || defined (__GNUG__)) && !defined (__MINGW32__) && defined (ACE_HAS_PENTIUM)
09540   ACE_UNUSED_ARG (op);
09541 
09542 # if defined (ACE_LACKS_LONGLONG_T)
09543   double now;
09544 # else  /* ! ACE_LACKS_LONGLONG_T */
09545   ACE_hrtime_t now;
09546 # endif /* ! ACE_LACKS_LONGLONG_T */
09547 
09548   // See comments about the RDTSC Pentium instruction for the ACE_WIN32
09549   // version of ACE_OS::gethrtime (), below.
09550   //
09551   // Read the high-res tick counter directly into memory variable "now".
09552   // The A constraint signifies a 64-bit int.
09553   asm volatile ("rdtsc" : "=A" (now) : : "memory");
09554 
09555 # if defined (ACE_LACKS_LONGLONG_T)
09556   ACE_UINT32 least, most;
09557   ACE_OS::memcpy (&least, &now, sizeof (ACE_UINT32));
09558   ACE_OS::memcpy (&most, (u_char *) &now + sizeof (ACE_UINT32),
09559                   sizeof (ACE_UINT32));
09560 
09561   ACE_hrtime_t ret (least, most);
09562   return ret;
09563 # else  /* ! ACE_LACKS_LONGLONG_T */
09564   return now;
09565 # endif /* ! ACE_LACKS_LONGLONG_T */
09566 #elif defined (linux) && defined (ACE_HAS_ALPHA_TIMER)
09567   // NOTE:  alphas only have a 32 bit tick (cycle) counter.  The rpcc
09568   // instruction actually reads 64 bits, but the high 32 bits are
09569   // implementation-specific.  Linux and Digital Unix, for example,
09570   // use them for virtual tick counts, i.e., taking into account only
09571   // the time that the process was running.  This information is from
09572   // David Mosberger's article, see comment below.
09573   ACE_UINT32 now;
09574 
09575   // The following statement is based on code published by:
09576   // Mosberger, David, "How to Make Your Applications Fly, Part 1",
09577   // Linux Journal Issue 42, October 1997, page 50.  It reads the
09578   // high-res tick counter directly into the memory variable.
09579   asm volatile ("rpcc %0" : "=r" (now) : : "memory");
09580 
09581   return now;
09582 #elif defined (ACE_WIN32)
09583   ACE_UNUSED_ARG(op);
09584   LARGE_INTEGER freq;
09585 
09586   ::QueryPerformanceCounter (&freq);
09587 
09588 #  if defined (ACE_LACKS_LONGLONG_T)
09589   ACE_UINT64 uint64_freq(freq.u.LowPart, ACE_static_cast (unsigned int, freq.u.HighPart));
09590   return uint64_freq;
09591 #  else
09592   return freq.QuadPart;
09593 #  endif //ACE_LACKS_LONGLONG_T
09594 
09595 #elif defined (CHORUS)
09596   if (op == ACE_OS::ACE_HRTIMER_GETTIME)
09597     {
09598       struct timespec ts;
09599 
09600       ACE_OS::clock_gettime (CLOCK_REALTIME, &ts);
09601 
09602       // Carefully create the return value to avoid arithmetic overflow
09603       // if ACE_hrtime_t is ACE_U_LongLong.
09604       ACE_hrtime_t now = ts.tv_sec;
09605       now *= ACE_U_ONE_SECOND_IN_NSECS;
09606       now += ts.tv_nsec;
09607 
09608       return now;
09609     }
09610   else
09611     {
09612       // Use the sysBench timer on Chorus.  On MVME177, at least, it only
09613       // has 32 bits.  Be careful, because using it disables interrupts!
09614       ACE_UINT32 now;
09615       if (::sysBench (op, (int *) &now) == K_OK)
09616         {
09617           now *= 1000u /* nanoseconds/microsecond */;
09618           return (ACE_hrtime_t) now;
09619         }
09620       else
09621         {
09622           // Something went wrong.  Just return 0.
09623           return (ACE_hrtime_t) 0;
09624         }
09625     }
09626 
09627 #elif defined (ACE_HAS_POWERPC_TIMER) && (defined (ghs) || defined (__GNUG__))
09628   // PowerPC w/ GreenHills or g++.
09629 
09630   ACE_UNUSED_ARG (op);
09631   u_long most;
09632   u_long least;
09633   ACE_OS::readPPCTimeBase (most, least);
09634 #if defined (ACE_LACKS_LONGLONG_T)
09635   return ACE_U_LongLong (least, most);
09636 #else  /* ! ACE_LACKS_LONGLONG_T */
09637   return 0x100000000llu * most  +  least;
09638 #endif /* ! ACE_LACKS_LONGLONG_T */
09639 
09640 #elif defined (ACE_HAS_CLOCK_GETTIME) || defined (ACE_PSOS)
09641   // e.g., VxWorks (besides POWERPC && GreenHills) . . .
09642   ACE_UNUSED_ARG (op);
09643   struct timespec ts;
09644 
09645   ACE_OS::clock_gettime (CLOCK_REALTIME, &ts);
09646 
09647   // Carefully create the return value to avoid arithmetic overflow
09648   // if ACE_hrtime_t is ACE_U_LongLong.
09649   return ACE_static_cast (ACE_hrtime_t, ts.tv_sec) *
09650     ACE_U_ONE_SECOND_IN_NSECS  +  ACE_static_cast (ACE_hrtime_t, ts.tv_nsec);
09651 #else
09652   ACE_UNUSED_ARG (op);
09653   const ACE_Time_Value now = ACE_OS::gettimeofday ();
09654 
09655   // Carefully create the return value to avoid arithmetic overflow
09656   // if ACE_hrtime_t is ACE_U_LongLong.
09657   return (ACE_static_cast (ACE_hrtime_t, now.sec ()) * (ACE_UINT32) 1000000  +
09658           ACE_static_cast (ACE_hrtime_t, now.usec ())) * (ACE_UINT32) 1000;
09659 #endif /* ACE_HAS_HI_RES_TIMER */
09660 }
09661 
09662 ACE_INLINE int
09663 ACE_OS::fdetach (const char *file)
09664 {
09665   ACE_OS_TRACE ("ACE_OS::fdetach");
09666 #if defined (ACE_HAS_STREAM_PIPES)
09667   ACE_OSCALL_RETURN (::fdetach (file), int, -1);
09668 #else
09669   ACE_UNUSED_ARG (file);
09670 
09671   ACE_NOTSUP_RETURN (-1);
09672 #endif /* ACE_HAS_STREAM_PIPES */
09673 }
09674 
09675 ACE_INLINE int
09676 ACE_OS::fattach (int handle, const char *path)
09677 {
09678   ACE_OS_TRACE ("ACE_OS::fattach");
09679 #if defined (ACE_HAS_STREAM_PIPES)
09680   ACE_OSCALL_RETURN (::fattach (handle, path), int, -1);
09681 #else
09682   ACE_UNUSED_ARG (handle);
09683   ACE_UNUSED_ARG (path);
09684 
09685   ACE_NOTSUP_RETURN (-1);
09686 #endif /* ACE_HAS_STREAM_PIPES */
09687 }
09688 
09689 ACE_INLINE pid_t
09690 ACE_OS::fork (void)
09691 {
09692   ACE_OS_TRACE ("ACE_OS::fork");
09693 #if defined (ACE_LACKS_FORK)
09694   ACE_NOTSUP_RETURN (pid_t (-1));
09695 #else
09696   ACE_OSCALL_RETURN (::fork (), pid_t, -1);
09697 #endif /* ACE_LACKS_FORK */
09698 }
09699 
09700 ACE_INLINE int
09701 ACE_OS::getpagesize (void)
09702 {
09703   ACE_OS_TRACE ("ACE_OS::getpagesize");
09704 #if defined (ACE_WIN32) && !defined (ACE_HAS_PHARLAP)
09705   SYSTEM_INFO sys_info;
09706   ::GetSystemInfo (&sys_info);
09707   return (int) sys_info.dwPageSize;
09708 #elif defined (_SC_PAGESIZE)
09709   return (int) ::sysconf (_SC_PAGESIZE);
09710 #elif defined (ACE_HAS_GETPAGESIZE)
09711   return ::getpagesize ();
09712 #else
09713   // Use the default set in config.h
09714   return ACE_PAGE_SIZE;
09715 #endif /* ACE_WIN32 */
09716 }
09717 
09718 ACE_INLINE int
09719 ACE_OS::allocation_granularity (void)
09720 {
09721 #if defined (ACE_WIN32)
09722   SYSTEM_INFO sys_info;
09723   ::GetSystemInfo (&sys_info);
09724   return (int) sys_info.dwAllocationGranularity;
09725 #else
09726   return ACE_OS::getpagesize ();
09727 #endif /* ACE_WIN32 */
09728 }
09729 
09730 ACE_INLINE pid_t
09731 ACE_OS::getpid (void)
09732 {
09733   // ACE_OS_TRACE ("ACE_OS::getpid");
09734 #if defined (ACE_WIN32)
09735   return ::GetCurrentProcessId ();
09736 #elif defined (VXWORKS) || defined (ACE_PSOS)
09737   // getpid() is not supported:  just one process anyways
09738   return 0;
09739 #elif defined (CHORUS)
09740   return (pid_t) (::agetId ());
09741 #else
09742   ACE_OSCALL_RETURN (::getpid (), int, -1);
09743 #endif /* ACE_WIN32 */
09744 }
09745 
09746 ACE_INLINE pid_t
09747 ACE_OS::getpgid (pid_t pid)
09748 {
09749   ACE_OS_TRACE ("ACE_OS::getpgid");
09750 #if defined (ACE_LACKS_GETPGID)
09751   ACE_UNUSED_ARG (pid);
09752   ACE_NOTSUP_RETURN (-1);
09753 #elif defined (VXWORKS) || defined (ACE_PSOS)
09754   // getpgid() is not supported, only one process anyway.
09755   ACE_UNUSED_ARG (pid);
09756   return 0;
09757 #elif defined (linux) && __GLIBC__ > 1 && __GLIBC_MINOR__ >= 0
09758   // getpgid() is from SVR4, which appears to be the reason why GLIBC
09759   // doesn't enable its prototype by default.
09760   // Rather than create our own extern prototype, just use the one
09761   // that is visible (ugh).
09762   ACE_OSCALL_RETURN (::__getpgid (pid), pid_t, -1);
09763 #else
09764   ACE_OSCALL_RETURN (::getpgid (pid), pid_t, -1);
09765 #endif /* ACE_WIN32 */
09766 }
09767 
09768 ACE_INLINE pid_t
09769 ACE_OS::getppid (void)
09770 {
09771   ACE_OS_TRACE ("ACE_OS::getppid");
09772 #if defined (ACE_LACKS_GETPPID)
09773   ACE_NOTSUP_RETURN (-1);
09774 #elif defined (VXWORKS) || defined (ACE_PSOS)
09775   // getppid() is not supported, only one process anyway.
09776   return 0;
09777 #else
09778   ACE_OSCALL_RETURN (::getppid (), pid_t, -1);
09779 #endif /* ACE_LACKS_GETPPID */
09780 }
09781 
09782 ACE_INLINE int
09783 ACE_OS::setpgid (pid_t pid, pid_t pgid)
09784 {
09785   ACE_OS_TRACE ("ACE_OS::setpgid");
09786 #if defined (ACE_LACKS_SETPGID)
09787   ACE_UNUSED_ARG (pid);
09788   ACE_UNUSED_ARG (pgid);
09789   ACE_NOTSUP_RETURN (-1);
09790 #elif defined (VXWORKS) || defined (ACE_PSOS)
09791   // <setpgid> is not supported, only one process anyway.
09792   ACE_UNUSED_ARG (pid);
09793   ACE_UNUSED_ARG (pgid);
09794   return 0;
09795 #else
09796   ACE_OSCALL_RETURN (::setpgid (pid, pgid), int, -1);
09797 #endif /* ACE_LACKS_SETPGID */
09798 }
09799 
09800 ACE_INLINE int
09801 ACE_OS::setreuid (uid_t ruid, uid_t euid)
09802 {
09803   ACE_OS_TRACE ("ACE_OS::setreuid");
09804 #if defined (ACE_LACKS_SETREUID)
09805   ACE_UNUSED_ARG (ruid);
09806   ACE_UNUSED_ARG (euid);
09807   ACE_NOTSUP_RETURN (-1);
09808 #elif defined (VXWORKS) || defined (ACE_PSOS)
09809   // <setpgid> is not supported, only one process anyway.
09810   ACE_UNUSED_ARG (ruid);
09811   ACE_UNUSED_ARG (euid);
09812   return 0;
09813 #else
09814   ACE_OSCALL_RETURN (::setreuid (ruid, euid), int, -1);
09815 #endif /* ACE_WIN32 */
09816 }
09817 
09818 ACE_INLINE int
09819 ACE_OS::setregid (gid_t rgid, gid_t egid)
09820 {
09821   ACE_OS_TRACE ("ACE_OS::setregid");
09822 #if defined (ACE_LACKS_SETREGID)
09823   ACE_UNUSED_ARG (rgid);
09824   ACE_UNUSED_ARG (egid);
09825   ACE_NOTSUP_RETURN (-1);
09826 #elif defined (VXWORKS) || defined (ACE_PSOS)
09827   // <setregid> is not supported, only one process anyway.
09828   ACE_UNUSED_ARG (rgid);
09829   ACE_UNUSED_ARG (egid);
09830   return 0;
09831 #else
09832   ACE_OSCALL_RETURN (::setregid (rgid, egid), int, -1);
09833 #endif /* ACE_WIN32 */
09834 }
09835 
09836 ACE_INLINE off_t
09837 ACE_OS::lseek (ACE_HANDLE handle, off_t offset, int whence)
09838 {
09839   ACE_OS_TRACE ("ACE_OS::lseek");
09840 #if defined (ACE_WIN32)
09841 # if SEEK_SET != FILE_BEGIN || SEEK_CUR != FILE_CURRENT || SEEK_END != FILE_END
09842   //#error Windows NT is evil AND rude!
09843   switch (whence)
09844     {
09845     case SEEK_SET:
09846       whence = FILE_BEGIN;
09847       break;
09848     case SEEK_CUR:
09849       whence = FILE_CURRENT;
09850       break;
09851     case SEEK_END:
09852       whence = FILE_END;
09853       break;
09854     default:
09855       errno = EINVAL;
09856       return ACE_static_cast (off_t, -1); // rather safe than sorry
09857     }
09858 # endif  /* SEEK_SET != FILE_BEGIN || SEEK_CUR != FILE_CURRENT || SEEK_END != FILE_END */
09859   DWORD result = ::SetFilePointer (handle, offset, 0, whence);
09860   if (result == ACE_SYSCALL_FAILED)
09861     ACE_FAIL_RETURN (ACE_static_cast (off_t, -1));
09862   else
09863     return result;
09864 #elif defined (ACE_PSOS)
09865 # if defined (ACE_PSOS_LACKS_PHILE)
09866   ACE_UNUSED_ARG (handle);
09867   ACE_UNUSED_ARG (offset);
09868   ACE_UNUSED_ARG (whence);
09869   ACE_NOTSUP_RETURN (ACE_static_cast (off_t, -1));
09870 # else
09871   unsigned long oldptr, newptr, result;
09872   // seek to the requested position
09873   result = ::lseek_f (handle, whence, offset, &oldptr);
09874   if (result != 0)
09875     {
09876       errno = result;
09877       return ACE_static_cast (off_t, -1);
09878     }
09879   // now do a dummy seek to the current position to obtain the position
09880   result = ::lseek_f (handle, SEEK_CUR, 0, &newptr);
09881   if (result != 0)
09882     {
09883       errno = result;
09884       return ACE_static_cast (off_t, -1);
09885     }
09886   return ACE_static_cast (off_t, newptr);
09887 # endif /* defined (ACE_PSOS_LACKS_PHILE */
09888 #else
09889   ACE_OSCALL_RETURN (::lseek (handle, offset, whence), off_t, -1);
09890 #endif /* ACE_WIN32 */
09891 }
09892 
09893 #if defined (ACE_HAS_LLSEEK) || defined (ACE_HAS_LSEEK64)
09894 ACE_INLINE ACE_LOFF_T
09895 ACE_OS::llseek (ACE_HANDLE handle, ACE_LOFF_T offset, int whence)
09896 {
09897   ACE_OS_TRACE ("ACE_OS::llseek");
09898 
09899 #if ACE_SIZEOF_LONG == 8
09900   /* The native lseek is 64 bit.  Use it. */
09901   return ACE_OS::lseek (handle, offset, whence);
09902 #elif defined (ACE_HAS_LLSEEK) && defined (ACE_HAS_LSEEK64)
09903 # error Either ACE_HAS_LSEEK64 and ACE_HAS_LLSEEK should be defined, not both!
09904 #elif defined (ACE_HAS_LSEEK64)
09905   ACE_OSCALL_RETURN (::lseek64 (handle, offset, whence), ACE_LOFF_T, -1);
09906 #elif defined (ACE_HAS_LLSEEK)
09907   # if defined (ACE_WIN32)
09908   LARGE_INTEGER li;
09909   li.QuadPart = offset;
09910   li.LowPart = ::SetFilePointer (handle, li.LowPart, &li.HighPart, whence);
09911   if (li.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR)
09912     li.QuadPart = -1;
09913   return li.QuadPart;
09914   # else
09915     ACE_OSCALL_RETURN (::llseek (handle, offset, whence), ACE_LOFF_T, -1);
09916   # endif /* WIN32 */
09917 #endif
09918 }
09919 #endif /* ACE_HAS_LLSEEK || ACE_HAS_LSEEK64 */
09920 
09921 ACE_INLINE int
09922 ACE_OS::fseek (FILE *fp, long offset, int whence)
09923 {
09924 # if defined (ACE_WIN32)
09925 #   if SEEK_SET != FILE_BEGIN || SEEK_CUR != FILE_CURRENT || SEEK_END != FILE_END
09926   //#error Windows NT is evil AND rude!
09927   switch (whence)
09928     {
09929     case SEEK_SET:
09930       whence = FILE_BEGIN;
09931       break;
09932     case SEEK_CUR:
09933       whence = FILE_CURRENT;
09934       break;
09935     case SEEK_END:
09936       whence = FILE_END;
09937       break;
09938     default:
09939       errno = EINVAL;
09940       return -1; // rather safe than sorry
09941     }
09942 #   endif  /* SEEK_SET != FILE_BEGIN || SEEK_CUR != FILE_CURRENT || SEEK_END != FILE_END */
09943 # endif   /* ACE_WIN32 */
09944   ACE_OSCALL_RETURN (::fseek (fp, offset, whence), int, -1);
09945 }
09946 
09947 ACE_INLINE long
09948 ACE_OS::ftell (FILE* fp)
09949 {
09950   ACE_OSCALL_RETURN (::ftell (fp), long, -1);
09951 }
09952 
09953 ACE_INLINE int
09954 ACE_OS::fgetpos (FILE* fp, fpos_t* pos)
09955 {
09956   ACE_OSCALL_RETURN (::fgetpos (fp, pos), int, -1);
09957 }
09958 
09959 ACE_INLINE int
09960 ACE_OS::fsetpos (FILE* fp, fpos_t* pos)
09961 {
09962   ACE_OSCALL_RETURN (::fsetpos (fp, pos), int, -1);
09963 }
09964 
09965 ACE_INLINE int
09966 ACE_OS::fgetc (FILE* fp)
09967 {
09968   ACE_OSCALL_RETURN (::fgetc (fp), int, -1);
09969 }
09970 
09971 #if !defined (ACE_LACKS_CLEARERR)
09972 ACE_INLINE void
09973 ACE_OS::clearerr (FILE* fp)
09974 {
09975   ::clearerr(fp);
09976 }
09977 #endif /* !ACE_LACKS_CLEARERR */
09978 
09979 #if defined (ACE_HAS_WCHAR)
09980 
09981 ACE_INLINE wint_t
09982 ACE_OS::fgetwc (FILE* fp)
09983 {
09984 #if defined (ACE_LACKS_FGETWC)
09985   ACE_UNUSED_ARG (fp);
09986   ACE_NOTSUP_RETURN (0);
09987 #else
09988   ACE_OSCALL_RETURN (::fgetwc (fp), wint_t, WEOF);
09989 #endif
09990 }
09991 
09992 ACE_INLINE wint_t
09993 ACE_OS::ungetwc (wint_t c, FILE* fp)
09994 {
09995 #if defined (ACE_LACKS_FGETWC)
09996   ACE_UNUSED_ARG (c);
09997   ACE_UNUSED_ARG (fp);
09998   ACE_NOTSUP_RETURN (0);
09999 #else
10000   ACE_OSCALL_RETURN (::ungetwc (c, fp), wint_t, WEOF);
10001 #endif
10002 }
10003 
10004 #endif /* ACE_HAS_WCHAR */
10005 
10006 ACE_INLINE pid_t
10007 ACE_OS::waitpid (pid_t pid,
10008                  ACE_exitcode *status,
10009                  int wait_options,
10010                  ACE_HANDLE handle)
10011 {
10012   ACE_OS_TRACE ("ACE_OS::waitpid");
10013 #if defined (VXWORKS) || defined (ACE_PSOS)
10014   ACE_UNUSED_ARG (pid);
10015   ACE_UNUSED_ARG (status);
10016   ACE_UNUSED_ARG (wait_options);
10017   ACE_UNUSED_ARG (handle);
10018 
10019   ACE_NOTSUP_RETURN (0);
10020 #elif defined (ACE_WIN32)
10021   int blocking_period = ACE_BIT_ENABLED (wait_options, WNOHANG)
10022     ? 0 /* don't hang */
10023     : INFINITE;
10024 
10025   ACE_HANDLE phandle = handle;
10026 
10027   if (phandle == 0)
10028     {
10029       phandle = ::OpenProcess (SYNCHRONIZE,
10030                                FALSE,
10031                                pid);
10032 
10033       if (phandle == 0)
10034         {
10035           ACE_OS::set_errno_to_last_error ();
10036           return -1;
10037         }
10038     }
10039 
10040   pid_t result = pid;
10041 
10042   // Don't try to get the process exit status if wait failed so we can
10043   // keep the original error code intact.
10044   switch (::WaitForSingleObject (phandle,
10045                                  blocking_period))
10046     {
10047     case WAIT_OBJECT_0:
10048       if (status != 0)
10049         // The error status of <GetExitCodeProcess> is nonetheless
10050         // not tested because we don't know how to return the value.
10051         ::GetExitCodeProcess (phandle,
10052                               status);
10053       break;
10054     case WAIT_TIMEOUT:
10055       errno = ETIME;
10056       result = 0;
10057       break;
10058     default:
10059       ACE_OS::set_errno_to_last_error ();
10060       result = -1;
10061     }
10062   if (handle == 0)
10063     ::CloseHandle (phandle);
10064   return result;
10065 #elif defined (CHORUS)
10066   ACE_UNUSED_ARG (status);
10067   ACE_UNUSED_ARG (wait_options);
10068   ACE_UNUSED_ARG (handle);
10069   ACE_OSCALL_RETURN (::await (&ACE_OS::actorcaps_[pid]),
10070                      pid_t, -1);
10071 #else
10072   ACE_UNUSED_ARG (handle);
10073   ACE_OSCALL_RETURN (::waitpid (pid, status, wait_options),
10074                      pid_t, -1);
10075 #endif /* VXWORKS || ACE_PSOS */
10076 }
10077 
10078 ACE_INLINE pid_t
10079 ACE_OS::wait (pid_t pid,
10080               ACE_exitcode *status,
10081               int wait_options,
10082               ACE_HANDLE handle)
10083 {
10084   ACE_OS_TRACE ("ACE_OS::wait");
10085   return ACE_OS::waitpid (pid,
10086                           status,
10087                           wait_options,
10088                           handle);
10089 }
10090 
10091 ACE_INLINE pid_t
10092 ACE_OS::wait (int *status)
10093 {
10094   ACE_OS_TRACE ("ACE_OS::wait");
10095 #if defined (ACE_WIN32) || defined (VXWORKS) || defined(CHORUS) || defined (ACE_PSOS)
10096   ACE_UNUSED_ARG (status);
10097 
10098   ACE_NOTSUP_RETURN (0);
10099 #else
10100 # if defined (ACE_HAS_UNION_WAIT)
10101   ACE_OSCALL_RETURN (::wait ((union wait *) status), pid_t, -1);
10102 # else
10103   ACE_OSCALL_RETURN (::wait (status), pid_t, -1);
10104 # endif /* ACE_HAS_UNION_WAIT */
10105 #endif /* ACE_WIN32 || VXWORKS || CHORUS || ACE_PSOS */
10106 }
10107 
10108 ACE_INLINE int
10109 ACE_OS::ioctl (ACE_HANDLE handle,
10110                int cmd,
10111                void *val)
10112 {
10113   ACE_OS_TRACE ("ACE_OS::ioctl");
10114 
10115 #if defined (ACE_WIN32)
10116   ACE_SOCKET sock = (ACE_SOCKET) handle;
10117   ACE_SOCKCALL_RETURN (::ioctlsocket (sock, cmd, (u_long *) val), int, -1);
10118 #elif defined (VXWORKS)
10119   ACE_OSCALL_RETURN (::ioctl (handle, cmd, ACE_reinterpret_cast (int, val)),
10120                      int, -1);
10121 #elif defined (ACE_PSOS)
10122   ACE_OSCALL_RETURN (::ioctl (handle, cmd, (char *) val), int, -1);
10123 #elif defined (__CYGWIN32__)
10124   ACE_UNUSED_ARG (handle);
10125    ACE_UNUSED_ARG (cmd);
10126    ACE_UNUSED_ARG (val);
10127    ACE_NOTSUP_RETURN (-1);
10128 #else
10129   ACE_OSCALL_RETURN (::ioctl (handle, cmd, val), int, -1);
10130 #endif /* ACE_WIN32 */
10131 }
10132 
10133 ACE_INLINE int
10134 ACE_OS::kill (pid_t pid, int signum)
10135 {
10136   ACE_OS_TRACE ("ACE_OS::kill");
10137 #if defined (ACE_WIN32) || defined (CHORUS) || defined (ACE_PSOS)
10138   ACE_UNUSED_ARG (pid);
10139   ACE_UNUSED_ARG (signum);
10140   ACE_NOTSUP_RETURN (-1);
10141 #else
10142   ACE_OSCALL_RETURN (::kill (pid, signum), int, -1);
10143 #endif /* ACE_WIN32 || CHORUS || ACE_PSOS */
10144 }
10145 
10146 ACE_INLINE int
10147 ACE_OS::sigaction (int signum,
10148                    const struct sigaction *nsa,
10149                    struct sigaction *osa)
10150 {
10151   ACE_OS_TRACE ("ACE_OS::sigaction");
10152   if (signum == 0)
10153     return 0;
10154 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
10155   struct sigaction sa;
10156 
10157   if (osa == 0)
10158     osa = &sa;
10159 
10160   if (nsa == 0)
10161     {
10162       osa->sa_handler = ::signal (signum, SIG_IGN);
10163       ::signal (signum, osa->sa_handler);
10164     }
10165   else
10166     osa->sa_handler = ::signal (signum, nsa->sa_handler);
10167   return osa->sa_handler == SIG_ERR ? -1 : 0;
10168 #elif defined (CHORUS) || defined (ACE_HAS_WINCE) || defined(ACE_PSOS)
10169   ACE_UNUSED_ARG (signum);
10170   ACE_UNUSED_ARG (nsa);
10171   ACE_UNUSED_ARG (osa);
10172   ACE_NOTSUP_RETURN (-1);
10173 #elif defined (ACE_LACKS_POSIX_PROTOTYPES) || defined (ACE_LACKS_SOME_POSIX_PROTOTYPES)
10174   ACE_OSCALL_RETURN (::sigaction (signum, (struct sigaction*) nsa, osa), int, -1);
10175 #else
10176   ACE_OSCALL_RETURN (::sigaction (signum, nsa, osa), int, -1);
10177 #endif /* ACE_WIN32 !ACE_HAS_WINCE */
10178 }
10179 
10180 ACE_INLINE ACE_TCHAR *
10181 ACE_OS::getcwd (ACE_TCHAR *buf, size_t size)
10182 {
10183   ACE_OS_TRACE ("ACE_OS::getcwd");
10184 #if defined (ACE_PSOS_LACKS_PHILE)
10185   ACE_UNUSED_ARG (buf);
10186   ACE_UNUSED_ARG (size);
10187   ACE_NOTSUP_RETURN ( (char*)-1);
10188 #elif defined (ACE_PSOS)
10189 
10190   static char pathbuf [BUFSIZ];
10191 
10192   // blank the path buffer
10193   ACE_OS::memset (pathbuf, '\0', BUFSIZ);
10194 
10195   // the following was suggested in the documentation for get_fn ()
10196   u_long result;
10197   char cur_dir_name [BUFSIZ] = ".";
10198 
10199   u_long cur_dir = 0, prev_dir = 0;
10200   while ((ACE_OS::strlen (pathbuf) < BUFSIZ) &&
10201          (ACE_OS::strlen (cur_dir_name) < BUFSIZ - ACE_OS::strlen ("/..")))
10202   {
10203     // get the current directory handle
10204     result = ::get_fn (cur_dir_name, &cur_dir);
10205 
10206     // check whether we're at the root: this test is
10207     // really lame, but the get_fn documentation says
10208     // *either* condition indicates you're trying to
10209     // move above the root.
10210     if ((result != 0) || ( cur_dir == prev_dir))
10211     {
10212       break;
10213     }
10214 
10215     // change name to the parent directory
10216     ACE_OS::strcat (cur_dir_name, "/..");
10217 
10218     // open the parent directory
10219     XDIR xdir;
10220     result = ::open_dir (cur_dir_name, &xdir);
10221     if (result != 0)
10222     {
10223       return 0;
10224     }
10225 
10226     // look for an entry that matches the current directory handle
10227     struct dirent dir_entry;
10228     while (1)
10229     {
10230       // get the next directory entry
10231       result = ::read_dir (&xdir, &dir_entry);
10232       if (result != 0)
10233       {
10234         return 0;
10235       }
10236 
10237       // check for a match
10238       if (dir_entry.d_filno == cur_dir)
10239       {
10240         // prefix the previous path with the entry's name and break
10241         if (ACE_OS::strlen (pathbuf) + ACE_OS::strlen (dir_entry.d_name) < BUFSIZ)
10242         {
10243           ACE_OS::strcpy (pathbuf + ACE_OS::strlen (dir_entry.d_name), pathbuf);
10244           ACE_OS::strcpy (pathbuf, dir_entry.d_name);
10245           break;
10246         }
10247         else
10248         {
10249           // we're out of room in the buffer
10250           return 0;
10251         }
10252       }
10253     }
10254 
10255     // close the parent directory
10256     result = ::close_dir (&xdir);
10257     if (result != 0)
10258     {
10259       return 0;
10260     }
10261 
10262     // save the current directory handle as the previous
10263     prev_dir =  cur_dir;
10264   }
10265 
10266   // return the path, if there is one
10267   return (ACE_OS::strlen (pathbuf) > 0) ? pathbuf : (char *) 0;
10268 #elif defined (ACE_HAS_WINCE)
10269   ACE_UNUSED_ARG (buf);
10270   ACE_UNUSED_ARG (size);
10271   ACE_NOTSUP_RETURN (0);
10272 #elif defined (ACE_WIN32)
10273 #  if defined (ACE_USES_WCHAR)
10274   return ::_wgetcwd (buf, ACE_static_cast (int, size));
10275 #  else
10276   return ::getcwd (buf, ACE_static_cast (int, size));
10277 #  endif /* ACE_USES_WCHAR */
10278 #else
10279   ACE_OSCALL_RETURN (::getcwd (buf, size), char *, 0);
10280 #endif /* ACE_PSOS_LACKS_PHILE */
10281 }
10282 
10283 ACE_INLINE int
10284 ACE_OS::sleep (u_int seconds)
10285 {
10286   ACE_OS_TRACE ("ACE_OS::sleep");
10287 #if defined (ACE_WIN32)
10288   ::Sleep (seconds * ACE_ONE_SECOND_IN_MSECS);
10289   return 0;
10290 #if 0
10291 #elif defined (HPUX_10) && defined (ACE_HAS_PTHREADS_DRAFT4)
10292   // On HP-UX 10, _CMA_NOWRAPPERS_ disables the mapping from sleep to cma_sleep
10293   // which makes sleep() put the whole process to sleep, and keeps it from
10294   // noticing pending cancels.  So, in this case, use pthread_delay_np
10295   struct timespec rqtp;
10296   rqtp.tv_sec = seconds;
10297   rqtp.tv_nsec = 0L;
10298   return pthread_delay_np (&rqtp);
10299 #endif /* 0 */
10300 #elif defined (ACE_HAS_CLOCK_GETTIME)
10301   struct timespec rqtp;
10302   // Initializer doesn't work with Green Hills 1.8.7
10303   rqtp.tv_sec = seconds;
10304   rqtp.tv_nsec = 0L;
10305   ACE_OSCALL_RETURN (::nanosleep (&rqtp, 0), int, -1);
10306 #elif defined (ACE_PSOS)
10307   timeval wait;
10308   wait.tv_sec = seconds;
10309   wait.tv_usec = 0;
10310   ACE_OSCALL_RETURN (::select (0, 0, 0, 0, &wait), int, -1);
10311 #else
10312   ACE_OSCALL_RETURN (::sleep (seconds), int, -1);
10313 #endif /* ACE_WIN32 */
10314 }
10315 
10316 ACE_INLINE int
10317 ACE_OS::sleep (const ACE_Time_Value &tv)
10318 {
10319   ACE_OS_TRACE ("ACE_OS::sleep");
10320 #if defined (ACE_WIN32)
10321   ::Sleep (tv.msec ());
10322   return 0;
10323 #else
10324 # if defined (ACE_HAS_NONCONST_SELECT_TIMEVAL)
10325   // Copy the timeval, because this platform doesn't declare the timeval
10326   // as a pointer to const.
10327   timeval tv_copy = tv;
10328   ACE_OSCALL_RETURN (::select (0, 0, 0, 0, &tv_copy), int, -1);
10329 # else  /* ! ACE_HAS_NONCONST_SELECT_TIMEVAL */
10330   const timeval *tvp = tv;
10331   ACE_OSCALL_RETURN (::select (0, 0, 0, 0, tvp), int, -1);
10332 # endif /* ACE_HAS_NONCONST_SELECT_TIMEVAL */
10333 #endif /* ACE_WIN32 */
10334 }
10335 
10336 ACE_INLINE int
10337 ACE_OS::nanosleep (const struct timespec *requested,
10338                    struct timespec *remaining)
10339 {
10340   ACE_OS_TRACE ("ACE_OS::nanosleep");
10341 #if defined (ACE_HAS_CLOCK_GETTIME)
10342   // ::nanosleep () is POSIX 1003.1b.  So is ::clock_gettime ().  So,
10343   // if ACE_HAS_CLOCK_GETTIME is defined, then ::nanosleep () should
10344   // be available on the platform.  On Solaris 2.x, both functions
10345   // require linking with -lposix4.
10346   return ::nanosleep ((ACE_TIMESPEC_PTR) requested, remaining);
10347 #elif defined (ACE_PSOS)
10348 #  if ! defined (ACE_PSOS_DIAB_MIPS)
10349   double ticks = KC_TICKS2SEC * requested->tv_sec +
10350                  ( ACE_static_cast (double, requested->tv_nsec) *
10351                    ACE_static_cast (double, KC_TICKS2SEC) ) /
10352                  ACE_static_cast (double, ACE_ONE_SECOND_IN_NSECS);
10353 
10354   if (ticks > ACE_static_cast (double, ACE_PSOS_Time_t::max_ticks))
10355   {
10356     ticks -= ACE_static_cast (double, ACE_PSOS_Time_t::max_ticks);
10357     remaining->tv_sec = ACE_static_cast (time_t,
10358                                          (ticks /
10359                                           ACE_static_cast (double,
10360                                                            KC_TICKS2SEC)));
10361     ticks -= ACE_static_cast (double, remaining->tv_sec) *
10362              ACE_static_cast (double, KC_TICKS2SEC);
10363 
10364     remaining->tv_nsec =
10365       ACE_static_cast (long,
10366                        (ticks * ACE_static_cast (double,
10367                                                  ACE_ONE_SECOND_IN_NSECS)) /
10368                        ACE_static_cast (double, KC_TICKS2SEC));
10369 
10370     ::tm_wkafter (ACE_PSOS_Time_t::max_ticks);
10371   }
10372   else
10373   {
10374     remaining->tv_sec = 0;
10375     remaining->tv_nsec = 0;
10376     ::tm_wkafter (ACE_static_cast (u_long, ticks));
10377   }
10378 
10379   // tm_wkafter always returns 0
10380 #  endif /* ACE_PSOS_DIAB_MIPS */
10381   return 0;
10382 #else
10383   ACE_UNUSED_ARG (remaining);
10384 
10385   // Convert into seconds and microseconds.
10386 # if ! defined(ACE_HAS_BROKEN_TIMESPEC_MEMBERS)
10387   ACE_Time_Value tv (requested->tv_sec,
10388                      requested->tv_nsec / 1000);
10389 # else
10390   ACE_Time_Value tv (requested->ts_sec,
10391                      requested->ts_nsec / 1000);
10392 # endif /* ACE_HAS_BROKEN_TIMESPEC_MEMBERS */
10393   return ACE_OS::sleep (tv);
10394 #endif /* ACE_HAS_CLOCK_GETTIME */
10395 }
10396 
10397 ACE_INLINE int
10398 ACE_OS::mkdir (const ACE_TCHAR *path, mode_t mode)
10399 {
10400 #if defined (ACE_PSOS_LACKS_PHILE)
10401   ACE_UNUSED_ARG (path);
10402   ACE_UNUSED_ARG (mode);
10403   ACE_NOTSUP_RETURN (-1);
10404 #elif defined (ACE_PSOS)
10405   //The pSOS make_dir fails if the last character is a '/'
10406   int location;
10407   char *phile_path;
10408 
10409   phile_path = (char *)ACE_OS::malloc(strlen(path));
10410   if (phile_path == 0)
10411     {
10412       ACE_OS::printf ("malloc in make_dir failed: [%X]\n",
10413                       errno);
10414       return -1;
10415     }
10416   else
10417     ACE_OS::strcpy (phile_path, path);
10418 
10419   location = ACE_OS::strlen(phile_path);
10420   if(phile_path[location-1] == '/')
10421   {
10422      phile_path[location-1] = 0;
10423   }
10424 
10425   u_long result;
10426   result = ::make_dir ((char *) phile_path, mode);
10427   if (result == 0x2011)  // Directory already exists
10428     {
10429       result = 0;
10430     }
10431   else if (result != 0)
10432     {
10433       result = -1;
10434     }
10435 
10436   ACE_OS::free(phile_path);
10437   return result;
10438 
10439 #elif defined (VXWORKS)
10440   ACE_UNUSED_ARG (mode);
10441   ACE_OSCALL_RETURN (::mkdir ((char *) path), int, -1);
10442 #elif defined (ACE_WIN32) && defined (__IBMCPP__) && (__IBMCPP__ >= 400)
10443   ACE_UNUSED_ARG (mode);
10444   ACE_OSCALL_RETURN (::_mkdir ((char *) path), int, -1);
10445 #elif defined (ACE_HAS_WINCE)
10446   ACE_UNUSED_ARG (mode);
10447   ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::CreateDirectory (path, 0),
10448                                           ace_result_),
10449                         int, -1);
10450 #elif defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
10451   ACE_UNUSED_ARG (mode);
10452   ACE_OSCALL_RETURN (::_wmkdir (path), int, -1);
10453 #elif defined (ACE_WIN32)
10454   ACE_UNUSED_ARG (mode);
10455   ACE_OSCALL_RETURN (::mkdir (path), int, -1);
10456 #else
10457   ACE_OSCALL_RETURN (::mkdir (path, mode), int, -1);
10458 #endif /* ACE_PSOS_LACKS_PHILE */
10459 }
10460 
10461 ACE_INLINE char *
10462 ACE_OS::getenv (const char *symbol)
10463 {
10464   ACE_OS_TRACE ("ACE_OS::getenv");
10465 #if defined (ACE_LACKS_ENV)
10466   ACE_UNUSED_ARG (symbol);
10467   ACE_NOTSUP_RETURN (0);
10468 #elif defined (ACE_PSOS)
10469   ACE_UNUSED_ARG (symbol);
10470   ACE_NOTSUP_RETURN (0);
10471 #else /* ACE_PSOS */
10472   ACE_OSCALL_RETURN (::getenv (symbol), char *, 0);
10473 #endif /* ACE_LACKS_ENV */
10474 }
10475 
10476 #if defined (ACE_HAS_WCHAR) && defined (ACE_WIN32)
10477 ACE_INLINE wchar_t *
10478 ACE_OS::getenv (const wchar_t *symbol)
10479 {
10480 #if defined (ACE_LACKS_ENV)
10481   ACE_UNUSED_ARG (symbol);
10482   ACE_NOTSUP_RETURN (0);
10483 #else
10484   ACE_OSCALL_RETURN (::_wgetenv (symbol), wchar_t *, 0);
10485 #endif /* ACE_LACKS_ENV */
10486 }
10487 #endif /* ACE_HAS_WCHAR && ACE_WIN32 */
10488 
10489 ACE_INLINE int
10490 ACE_OS::putenv (const ACE_TCHAR *string)
10491 {
10492   ACE_OS_TRACE ("ACE_OS::putenv");
10493 #if defined (ACE_HAS_WINCE) || defined (ACE_PSOS)
10494   // WinCE and pSOS don't have the concept of environment variables.
10495   ACE_UNUSED_ARG (string);
10496   ACE_NOTSUP_RETURN (-1);
10497 #elif defined (ACE_LACKS_ENV)
10498   ACE_UNUSED_ARG (string);
10499   ACE_NOTSUP_RETURN (0);
10500 #elif defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
10501   ACE_OSCALL_RETURN (::_wputenv (string), int, -1);
10502 #else /* ! ACE_HAS_WINCE && ! ACE_PSOS */
10503   // VxWorks declares ::putenv with a non-const arg.
10504   ACE_OSCALL_RETURN (::putenv ((char *) string), int, -1);
10505 #endif /* ACE_HAS_WINCE */
10506 }
10507 
10508 ACE_INLINE
10509 ACE_Str_Buf::ACE_Str_Buf (void *b, int l, int max)
10510 {
10511   this->maxlen = max;
10512   this->len = l;
10513   this->buf = (char *) b;
10514 }
10515 
10516 ACE_INLINE
10517 ACE_Str_Buf::ACE_Str_Buf (strbuf &sb)
10518 {
10519   this->maxlen = sb.maxlen;
10520   this->len = sb.len;
10521   this->buf = sb.buf;
10522 }
10523 
10524 ACE_INLINE u_int
10525 ACE_OS::wslen (const WChar *s)
10526 {
10527   u_int len = 0;
10528 
10529   while (*s++ != 0)
10530     len++;
10531 
10532   return len;
10533 }
10534 
10535 ACE_INLINE ACE_OS::WChar *
10536 ACE_OS::wscpy (WChar *dest, const WChar *src)
10537 {
10538   WChar *original_dest = dest;
10539 
10540   while ((*dest++ = *src++) != 0)
10541     continue;
10542 
10543   return original_dest;
10544 }
10545 
10546 ACE_INLINE int
10547 ACE_OS::wscmp (const WChar *s, const WChar *t)
10548 {
10549   const WChar *scan1 = s;
10550   const WChar *scan2 = t;
10551 
10552   while (*scan1 != 0 && *scan1 == *scan2)
10553     {
10554       ++scan1;
10555       ++scan2;
10556     }
10557 
10558   return *scan1 - *scan2;
10559 }
10560 
10561 ACE_INLINE int
10562 ACE_OS::wsncmp (const WChar *s, const WChar *t, size_t len)
10563 {
10564   const WChar *scan1 = s;
10565   const WChar *scan2 = t;
10566 
10567   while (len != 0 && *scan1 != 0 && *scan1 == *scan2)
10568     {
10569       ++scan1;
10570       ++scan2;
10571       --len;
10572     }
10573 
10574   return len == 0 ? 0 : *scan1 - *scan2;
10575 }
10576 
10577 #if defined (ACE_LACKS_COND_T) && defined (ACE_HAS_THREADS)
10578 ACE_INLINE long
10579 ACE_cond_t::waiters (void) const
10580 {
10581   return this->waiters_;
10582 }
10583 #endif /* ACE_LACKS_COND_T && ACE_HAS_THREADS */
10584 
10585 #if 0
10586 ACE_INLINE int
10587 ACE_OS::thr_continue (const ACE_Thread_ID &thr_id)
10588 {
10589   ACE_OS_TRACE ("ACE_OS::thr_continue");
10590   return ACE_OS::thr_continue (thr_id.id ());
10591 }
10592 
10593 ACE_INLINE int
10594 ACE_OS::thr_create (ACE_THR_FUNC func,
10595                     void *args,
10596                     long flags,
10597                     ACE_Thread_ID *thr_id,
10598                     long priority,
10599                     void *stack,
10600                     size_t stacksize);
10601 {
10602   ACE_OS_TRACE ("ACE_OS::thr_create");
10603   ACE_thread_t thread_id;
10604   ACE_hthread_t thread_handle;
10605 
10606   int result = ACE_OS::thr_create (func, args, flags,
10607                                    &thread_id, &thread_handle,
10608                                    priority, stack, stacksize);
10609   if (result == -1)
10610     return -1;
10611   else if (thr_id != 0)
10612     {
10613       thr_id->id (thread_id);
10614       thr_id->handle (thread_handle);
10615       return result;
10616     }
10617 }
10618 
10619 ACE_INLINE int
10620 ACE_OS::thr_getprio (const ACE_Thread_ID &thr_id, int &prio)
10621 {
10622   ACE_OS_TRACE ("ACE_OS::thr_getprio");
10623   return ACE_OS::thr_getprio (thr_id.handle (), prio);
10624 }
10625 
10626 ACE_INLINE int
10627 ACE_OS::thr_join (const ACE_Thread_ID &thr_id, ACE_THR_FUNC_RETURN *status)
10628 {
10629 # if defined (ACE_WIN32)
10630   return ACE_OS::thr_join (thr_id.handle (), status);
10631 # else
10632   return ACE_OS::thr_join (thr_id.id (), status);
10633 # endif /* ACE_WIN32 */
10634 }
10635 
10636 ACE_INLINE int
10637 ACE_OS::thr_cancel (const ACE_Thread_ID &thr_id)
10638 {
10639   return ACE_OS::thr_cancel (thr_id.id ());
10640 }
10641 
10642 ACE_INLINE int
10643 ACE_OS::thr_kill (const ACE_Thread_ID &thr_id, int signum)
10644 {
10645   return ACE_OS::thr_kill (thr_id.id (), signum);
10646 }
10647 
10648 ACE_INLINE ACE_Thread_ID
10649 ACE_OS::thr_self (void)
10650 {
10651   ACE_hthread_t thr_handle;
10652   ACE_OS::thr_self (thr_handle);
10653   ACE_thread_t thr_id = ACE_OS::thr_self ();
10654 
10655   return ACE_Thread_ID (thr_id, thr_handle);
10656 }
10657 
10658 ACE_INLINE int
10659 ACE_OS::thr_setprio (const ACE_Thread_ID &thr_id, int prio)
10660 {
10661   ACE_OS_TRACE ("ACE_OS::thr_setprio");
10662   return ACE_OS::thr_setprio (thr_id.handle (), prio);
10663 }
10664 
10665 ACE_INLINE int
10666 ACE_OS::thr_suspend (const ACE_Thread_ID &thr_id)
10667 {
10668   return ACE_OS::thr_suspend (thr_id.handle ());
10669 }
10670 
10671 #endif /* 0 */
10672 
10673 ACE_INLINE int
10674 ACE_OS::sigaddset (sigset_t *s, int signum)
10675 {
10676   ACE_OS_TRACE ("ACE_OS::sigaddset");
10677 #if defined (ACE_LACKS_SIGSET) || defined (ACE_LACKS_SIGSET_DEFINITIONS)
10678   if (s == 0)
10679     {
10680       errno = EFAULT;
10681       return -1;
10682     }
10683   else if (signum < 1 || signum >= ACE_NSIG)
10684     {
10685       errno = EINVAL;
10686       return -1;                 // Invalid signum, return error
10687     }
10688 #   if defined (ACE_PSOS) && defined (__DIAB) && ! defined(ACE_PSOS_DIAB_MIPS) && !defined (ACE_PSOS_DIAB_PPC)
10689   // treat 0th u_long of sigset_t as high bits,
10690   // and 1st u_long of sigset_t as low bits.
10691   if (signum <= ACE_BITS_PER_ULONG)
10692     s->s[1] |= (1 << (signum - 1));
10693   else
10694     s->s[0] |= (1 << (signum - ACE_BITS_PER_ULONG - 1));
10695 #   else
10696   *s |= (1 << (signum - 1)) ;
10697 #   endif /* defined (ACE_PSOS) && defined (__DIAB) */
10698   return 0 ;
10699 #else
10700   ACE_OSCALL_RETURN (::sigaddset (s, signum), int, -1);
10701 #endif /* ACE_LACKS_SIGSET || ACE_LACKS_SIGSET_DEFINITIONS */
10702 }
10703 
10704 ACE_INLINE int
10705 ACE_OS::sigdelset (sigset_t *s, int signum)
10706 {
10707 #if defined (ACE_LACKS_SIGSET) || defined (ACE_LACKS_SIGSET_DEFINITIONS)
10708   if (s == 0)
10709     {
10710       errno = EFAULT;
10711       return -1;
10712     }
10713   else if (signum < 1 || signum >= ACE_NSIG)
10714     {
10715       errno = EINVAL;
10716       return -1;                 // Invalid signum, return error
10717     }
10718 #   if defined (ACE_PSOS) && defined (__DIAB) && ! defined (ACE_PSOS_DIAB_MIPS) && !defined (ACE_PSOS_DIAB_PPC)
10719   // treat 0th u_long of sigset_t as high bits,
10720   // and 1st u_long of sigset_t as low bits.
10721   if (signum <= ACE_BITS_PER_ULONG)
10722     s->s[1] &= ~(1 << (signum - 1));
10723   else
10724     s->s[0] &= ~(1 << (signum - ACE_BITS_PER_ULONG - 1));
10725 #   else
10726   *s &= ~(1 << (signum - 1)) ;
10727 #   endif /* defined (ACE_PSOS) && defined (__DIAB) */
10728   return 0;
10729 #else
10730   ACE_OSCALL_RETURN (::sigdelset (s, signum), int, -1);
10731 #endif /* ACE_LACKS_SIGSET || ACE_LACKS_SIGSET_DEFINITIONS */
10732 }
10733 
10734 ACE_INLINE int
10735 ACE_OS::sigemptyset (sigset_t *s)
10736 {
10737 #if defined (ACE_LACKS_SIGSET) || defined (ACE_LACKS_SIGSET_DEFINITIONS)
10738   if (s == 0)
10739     {
10740       errno = EFAULT;
10741       return -1;
10742     }
10743 #   if defined (ACE_PSOS) && defined (__DIAB) && ! defined (ACE_PSOS_DIAB_MIPS) && !defined (ACE_PSOS_DIAB_PPC)
10744   s->s[0] = 0;
10745   s->s[1] = 0;
10746 #   else
10747   *s = 0 ;
10748 #   endif /* defined (ACE_PSOS) && defined (__DIAB) */
10749   return 0 ;
10750 #else
10751   ACE_OSCALL_RETURN (::sigemptyset (s), int, -1);
10752 #endif /* ACE_LACKS_SIGSET || ACE_LACKS_SIGSET_DEFINITIONS */
10753 }
10754 
10755 ACE_INLINE int
10756 ACE_OS::sigfillset (sigset_t *s)
10757 {
10758 #if defined (ACE_LACKS_SIGSET) || defined (ACE_LACKS_SIGSET_DEFINITIONS)
10759   if (s == 0)
10760     {
10761       errno = EFAULT;
10762       return -1;
10763     }
10764 #   if defined (ACE_PSOS) && defined (__DIAB) && ! defined (ACE_PSOS_DIAB_MIPS) && !defined (ACE_PSOS_DIAB_PPC)
10765   s->s[0] = ~(u_long) 0;
10766   s->s[1] = ~(u_long) 0;
10767 #   else
10768   *s = ~(sigset_t) 0;
10769 #   endif /* defined (ACE_PSOS) && defined (__DIAB) */
10770   return 0 ;
10771 #else
10772   ACE_OSCALL_RETURN (::sigfillset (s), int, -1);
10773 #endif /* ACE_LACKS_SIGSET || ACE_LACKS_SIGSET_DEFINITIONS */
10774 }
10775 
10776 ACE_INLINE int
10777 ACE_OS::sigismember (sigset_t *s, int signum)
10778 {
10779 #if defined (ACE_LACKS_SIGSET) || defined (ACE_LACKS_SIGSET_DEFINITIONS)
10780   if (s == 0)
10781     {
10782       errno = EFAULT;
10783       return -1;
10784     }
10785   else if (signum < 1 || signum >= ACE_NSIG)
10786     {
10787       errno = EINVAL;
10788       return -1;                 // Invalid signum, return error
10789     }
10790 #   if defined (ACE_PSOS) && defined (__DIAB) && ! defined (ACE_PSOS_DIAB_MIPS) && !defined (ACE_PSOS_DIAB_PPC)
10791   // treat 0th u_long of sigset_t as high bits,
10792   // and 1st u_long of sigset_t as low bits.
10793   if (signum <= ACE_BITS_PER_ULONG)
10794     return ((s->s[1] & (1 << (signum - 1))) != 0);
10795   else
10796     return ((s->s[0] & (1 << (signum - ACE_BITS_PER_ULONG - 1))) != 0);
10797 #   else
10798   return ((*s & (1 << (signum - 1))) != 0) ;
10799 #   endif /* defined (ACE_PSOS) && defined (__DIAB) */
10800 #else
10801 #  if defined (ACE_HAS_SIGISMEMBER_BUG)
10802   if (signum < 1 || signum >= ACE_NSIG)
10803     {
10804       errno = EINVAL;
10805       return -1;                 // Invalid signum, return error
10806     }
10807 #  endif /* ACE_HAS_SIGISMEMBER_BUG */
10808   ACE_OSCALL_RETURN (::sigismember (s, signum), int, -1);
10809 #endif /* ACE_LACKS_SIGSET || ACE_LACKS_SIGSET_DEFINITIONS */
10810 }
10811 
10812 ACE_INLINE int
10813 ACE_OS::sigsuspend (const sigset_t *sigset)
10814 {
10815 #if defined (ACE_HAS_SIGSUSPEND)
10816   sigset_t s;
10817 
10818   if (sigset == 0)
10819     {
10820       sigset = &s;
10821       ACE_OS::sigemptyset (&s);
10822     }
10823   ACE_OSCALL_RETURN (::sigsuspend (sigset), int, -1);
10824 #else
10825   ACE_UNUSED_ARG (sigset);
10826   ACE_NOTSUP_RETURN (-1);
10827 #endif /* ACE_HAS_SIGSUSPEND */
10828 }
10829 
10830 ACE_INLINE int
10831 ACE_OS::sigprocmask (int how, const sigset_t *nsp, sigset_t *osp)
10832 {
10833 #if defined (ACE_LACKS_SIGSET) || defined (ACE_LACKS_SIGSET_DEFINITIONS)
10834   ACE_UNUSED_ARG (how);
10835   ACE_UNUSED_ARG (nsp);
10836   ACE_UNUSED_ARG (osp);
10837   ACE_NOTSUP_RETURN (-1);
10838 #else
10839 # if defined (ACE_LACKS_POSIX_PROTOTYPES)
10840   ACE_OSCALL_RETURN (::sigprocmask (how, (int*) nsp, osp), int, -1);
10841 # else
10842   ACE_OSCALL_RETURN (::sigprocmask (how, nsp, osp), int, -1);
10843 # endif /* ACE_LACKS_POSIX_PROTOTYPES */
10844 #endif /* ACE_LACKS_SIGSET || ACE_LACKS_SIGSET_DEFINITIONS */
10845 }
10846 
10847 ACE_INLINE int
10848 ACE_OS::pthread_sigmask (int how, const sigset_t *nsp, sigset_t *osp)
10849 {
10850 #if defined (ACE_HAS_PTHREADS_STD)  &&  !defined (ACE_LACKS_PTHREAD_SIGMASK)
10851   ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_sigmask (how, nsp, osp),
10852                                        ace_result_),
10853                      int,
10854                      -1);
10855 #else /* !ACE_HAS_PTHREADS_STD && !ACE_LACKS_PTHREAD_SIGMASK */
10856   ACE_UNUSED_ARG (how);
10857   ACE_UNUSED_ARG (nsp);
10858   ACE_UNUSED_ARG (osp);
10859   ACE_NOTSUP_RETURN (-1);
10860 #endif /* ACE_HAS_PTHREADS_STD && !ACE_LACKS_PTHREAD_SIGMASK */
10861 }
10862 
10863 // ****************************************************************
10864 
10865 #if defined (ACE_PSOS)
10866 ACE_INLINE int
10867 isatty (int h)
10868 {
10869   return ACE_OS::isatty (h);
10870 }
10871 #if defined (fileno)
10872 #undef fileno
10873 #endif /* defined (fileno)*/
10874 ACE_INLINE ACE_HANDLE
10875 fileno (FILE *fp)
10876 {
10877   return (ACE_HANDLE) fp;
10878 }
10879 #endif /* defined (ACE_PSOS) */
10880 
10881 ACE_INLINE
10882 ACE_Cleanup::ACE_Cleanup (void)
10883 {
10884 }
10885 
10886 ACE_INLINE void *
10887 ACE_OS::bsearch (const void *key,
10888                  const void *base,
10889                  size_t nel,
10890                  size_t size,
10891                  ACE_COMPARE_FUNC compar)
10892 {
10893 #if !defined (ACE_LACKS_BSEARCH)
10894   return ::bsearch (key, base, nel, size, compar);
10895 #else
10896   ACE_UNUSED_ARG (key);
10897   ACE_UNUSED_ARG (base);
10898   ACE_UNUSED_ARG (nel);
10899   ACE_UNUSED_ARG (size);
10900   ACE_UNUSED_ARG (compar);
10901   ACE_NOTSUP_RETURN (0);
10902 #endif /* ACE_LACKS_BSEARCH */
10903 }
10904 
10905 ACE_INLINE void
10906 ACE_OS::qsort (void *base,
10907                size_t nel,
10908                size_t width,
10909                ACE_COMPARE_FUNC compar)
10910 {
10911 #if !defined (ACE_LACKS_QSORT)
10912   ::qsort (base, nel, width, compar);
10913 #else
10914   ACE_UNUSED_ARG (base);
10915   ACE_UNUSED_ARG (nel);
10916   ACE_UNUSED_ARG (width);
10917   ACE_UNUSED_ARG (compar);
10918 #endif /* !ACE_LACKS_QSORT */
10919 }
10920 
10921 ACE_INLINE int
10922 ACE_OS::setuid (uid_t uid)
10923 {
10924   ACE_OS_TRACE ("ACE_OS::setuid");
10925 #if defined (VXWORKS) || defined (ACE_PSOS)
10926   // setuid() is not supported:  just one user anyways
10927   ACE_UNUSED_ARG (uid);
10928   return 0;
10929 # elif defined (ACE_WIN32) || defined(CHORUS)
10930   ACE_UNUSED_ARG (uid);
10931   ACE_NOTSUP_RETURN (-1);
10932 # else
10933   ACE_OSCALL_RETURN (::setuid (uid), int,  -1);
10934 # endif /* VXWORKS || ACE_PSOS */
10935 }
10936 
10937 ACE_INLINE uid_t
10938 ACE_OS::getuid (void)
10939 {
10940   ACE_OS_TRACE ("ACE_OS::getuid");
10941 #if defined (VXWORKS) || defined (ACE_PSOS)
10942   // getuid() is not supported:  just one user anyways
10943   return 0;
10944 # elif defined (ACE_WIN32) || defined (CHORUS)
10945   ACE_NOTSUP_RETURN (ACE_static_cast (uid_t, -1));
10946 # else
10947   ACE_OSCALL_RETURN (::getuid (), uid_t, (uid_t) -1);
10948 # endif /* VXWORKS || ACE_PSOS */
10949 }
10950 
10951 ACE_INLINE int
10952 ACE_OS::setgid (gid_t gid)
10953 {
10954   ACE_OS_TRACE ("ACE_OS::setgid");
10955 #if defined (VXWORKS) || defined (ACE_PSOS)
10956   // setgid() is not supported:  just one user anyways
10957   ACE_UNUSED_ARG (gid);
10958   return 0;
10959 # elif defined (ACE_WIN32) || defined (CHORUS)
10960   ACE_UNUSED_ARG (gid);
10961   ACE_NOTSUP_RETURN (-1);
10962 # else
10963   ACE_OSCALL_RETURN (::setgid (gid), int,  -1);
10964 # endif /* VXWORKS || ACE_PSOS */
10965 }
10966 
10967 ACE_INLINE gid_t
10968 ACE_OS::getgid (void)
10969 {
10970   ACE_OS_TRACE ("ACE_OS::getgid");
10971 #if defined (VXWORKS) || defined (ACE_PSOS)
10972   // getgid() is not supported:  just one user anyways
10973   return 0;
10974 # elif defined (ACE_WIN32) || defined (CHORUS)
10975   ACE_NOTSUP_RETURN (ACE_static_cast (gid_t, -1));
10976 # else
10977   ACE_OSCALL_RETURN (::getgid (), gid_t, (gid_t) -1);
10978 # endif /* VXWORKS || ACE_PSOS */
10979 }
10980 
10981 ACE_INLINE ACE_EXIT_HOOK
10982 ACE_OS::set_exit_hook (ACE_EXIT_HOOK exit_hook)
10983 {
10984   ACE_EXIT_HOOK old_hook = exit_hook_;
10985   exit_hook_ = exit_hook;
10986   return old_hook;
10987 }
10988 
10989 ACE_INLINE int
10990 ACE_OS::isatty (int handle)
10991 {
10992 #if defined (ACE_LACKS_ISATTY)
10993   ACE_UNUSED_ARG (handle);
10994   return 0;
10995 # elif defined (ACE_WIN32)
10996   ACE_OS_TRACE ("ACE_OS::isatty");
10997   return ::_isatty (handle);
10998 # else
10999   ACE_OS_TRACE ("ACE_OS::isatty");
11000   ACE_OSCALL_RETURN (::isatty (handle), int, -1);
11001 # endif /* defined (ACE_LACKS_ISATTY) */
11002 }
11003 
11004 #if defined (ACE_WIN32)
11005 ACE_INLINE int
11006 ACE_OS::isatty (ACE_HANDLE handle)
11007 {
11008 #if defined (ACE_LACKS_ISATTY)
11009   ACE_UNUSED_ARG (handle);
11010   return 0;
11011 #else
11012 #  if defined (ACE_WIN64)
11013   int fd = ::_open_osfhandle (intptr_t (handle), 0);
11014 #  else
11015   int fd = ::_open_osfhandle (long (handle), 0);
11016 #  endif /* ACE_WIN64 */
11017 
11018   int status = ::_isatty (fd);
11019   ::_close (fd);
11020   return status;
11021 #endif /* ACE_LACKS_ISATTY */
11022 }
11023 
11024 ACE_INLINE void
11025 ACE_OS::fopen_mode_to_open_mode_converter (ACE_TCHAR x, int &hmode)
11026 {
11027     switch (x)
11028       {
11029       case ACE_LIB_TEXT ('r'):
11030         if (ACE_BIT_DISABLED (hmode, _O_RDWR))
11031           {
11032             ACE_CLR_BITS (hmode, _O_WRONLY);
11033             ACE_SET_BITS (hmode, _O_RDONLY);
11034           }
11035         break;
11036       case ACE_LIB_TEXT ('w'):
11037         if (ACE_BIT_DISABLED (hmode, _O_RDWR))
11038           {
11039             ACE_CLR_BITS (hmode, _O_RDONLY);
11040             ACE_SET_BITS (hmode, _O_WRONLY);
11041           }
11042         ACE_SET_BITS (hmode, _O_CREAT | _O_TRUNC);
11043         break;
11044       case ACE_LIB_TEXT ('a'):
11045         if (ACE_BIT_DISABLED (hmode, _O_RDWR))
11046           {
11047             ACE_CLR_BITS (hmode, _O_RDONLY);
11048             ACE_SET_BITS (hmode, _O_WRONLY);
11049           }
11050         ACE_SET_BITS (hmode, _O_CREAT | _O_APPEND);
11051         break;
11052       case ACE_LIB_TEXT ('+'):
11053         ACE_CLR_BITS (hmode, _O_RDONLY | _O_WRONLY);
11054         ACE_SET_BITS (hmode, _O_RDWR);
11055         break;
11056       case ACE_LIB_TEXT ('t'):
11057         ACE_CLR_BITS (hmode, _O_BINARY);
11058         ACE_SET_BITS (hmode, _O_TEXT);
11059         break;
11060       case ACE_LIB_TEXT ('b'):
11061         ACE_CLR_BITS (hmode, _O_TEXT);
11062         ACE_SET_BITS (hmode, _O_BINARY);
11063         break;
11064       }
11065 }
11066 #endif /* ACE_WIN32 */
11067 
11068 // Return a dynamically allocated duplicate of <str>, substituting the
11069 // environment variable if <str[0] == '$'>.  Note that the pointer is
11070 // allocated with <ACE_OS::malloc> and must be freed by
11071 // <ACE_OS::free>.
11072 
11073 ACE_INLINE ACE_TCHAR *
11074 ACE_OS::strenvdup (const ACE_TCHAR *str)
11075 {
11076 #if defined (ACE_HAS_WINCE)
11077   // WinCE doesn't have environment variables so we just skip it.
11078   return ACE_OS::strdup (str);
11079 #elif defined (ACE_LACKS_ENV)
11080   ACE_UNUSED_ARG (str);
11081   ACE_NOTSUP_RETURN (0);
11082 #else
11083   ACE_TCHAR *temp = 0;
11084 
11085   if (str[0] == ACE_LIB_TEXT ('$')
11086       && (temp = ACE_OS::getenv (&str[1])) != 0)
11087     return ACE_OS::strdup (temp);
11088   else
11089     return ACE_OS::strdup (str);
11090 #endif /* ACE_HAS_WINCE */
11091 }
11092 
11093 ACE_INLINE int
11094 ACE_Countdown_Time::start (void)
11095 {
11096   if (this->max_wait_time_ != 0)
11097     {
11098       this->start_time_ = ACE_OS::gettimeofday ();
11099       this->stopped_ = 0;
11100     }
11101   return 0;
11102 }
11103 
11104 ACE_INLINE int
11105 ACE_Countdown_Time::stopped (void) const
11106 {
11107   return stopped_;
11108 }
11109 
11110 ACE_INLINE int
11111 ACE_Countdown_Time::stop (void)
11112 {
11113   if (this->max_wait_time_ != 0 && this->stopped_ == 0)
11114     {
11115       ACE_Time_Value elapsed_time =
11116         ACE_OS::gettimeofday () - this->start_time_;
11117 
11118       if (*this->max_wait_time_ > elapsed_time)
11119         *this->max_wait_time_ -= elapsed_time;
11120       else
11121         {
11122           // Used all of timeout.
11123           *this->max_wait_time_ = ACE_Time_Value::zero;
11124           // errno = ETIME;
11125         }
11126       this->stopped_ = 1;
11127     }
11128   return 0;
11129 }
11130 
11131 ACE_INLINE int
11132 ACE_Countdown_Time::update (void)
11133 {
11134   return this->stop () == 0 && this->start ();
11135 }
11136 
11137 #if defined (ACE_WIN32)
11138 ACE_INLINE const OSVERSIONINFO &
11139 ACE_OS::get_win32_versioninfo ()
11140 {
11141   return ACE_OS::win32_versioninfo_;
11142 }
11143 
11144 ACE_INLINE HINSTANCE
11145 ACE_OS::get_win32_resource_module ()
11146 {
11147   return ACE_OS::win32_resource_module_;
11148 }
11149 
11150 ACE_INLINE void
11151 ACE_OS::set_win32_resource_module (HINSTANCE instance)
11152 {
11153   ACE_OS::win32_resource_module_ = instance;
11154 }
11155 #endif /* ACE_WIN32 */
11156 
11157 #if defined (ACE_HAS_WINCE)
11158 ACE_INLINE int
11159 ACE_CE_ARGV::argc()
11160 {
11161     return ce_argc_;
11162 }
11163 
11164 ACE_INLINE ACE_TCHAR** const
11165 ACE_CE_ARGV::argv()
11166 {
11167     return ce_argv_;
11168 }
11169 #endif  // ACE_HAS_WINCE

Generated on Mon Jun 16 11:20:43 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002