2 #include "ace/OS_NS_sys_utsname.h"
3 #include "ace/OS_NS_string.h"
4 #include "ace/OS_NS_errno.h"
5 #include "ace/OS_NS_macros.h"
6 #include "ace/OS_NS_fcntl.h"
7 #include "ace/Default_Constants.h"
8 #include "ace/OS_Memory.h"
9 #include "ace/Truncate.h"
11 #if defined (ACE_HAS_CLOCK_GETTIME)
12 # include "ace/os_include/os_time.h"
13 #endif /* ACE_HAS_CLOCK_GETTIME */
15 #if defined (ACE_LACKS_ACCESS)
16 # include "ace/OS_NS_stdio.h"
17 #endif /* ACE_LACKS_ACCESS */
19 #if defined (ACE_VXWORKS) && (ACE_VXWORKS <= 0x690)
20 # if defined (__RTP__)
21 # include "ace/os_include/os_strings.h"
23 # include "ace/os_include/os_string.h"
28 # include "ace/MQX_Filesystem.h"
31 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
34 ACE_OS::access (const char *path, int amode)
36 ACE_OS_TRACE ("ACE_OS::access");
37 #if defined (ACE_LACKS_ACCESS)
38 ACE_UNUSED_ARG (path);
39 ACE_UNUSED_ARG (amode);
40 ACE_NOTSUP_RETURN (-1);
41 #elif defined(ACE_WIN32)
42 // Windows doesn't support checking X_OK(6)
43 # if defined (ACE_ACCESS_EQUIVALENT)
44 return ACE_ACCESS_EQUIVALENT (path, amode & 6);
46 return ::access (path, amode & 6);
49 return ::access (path, amode);
50 #endif /* ACE_LACKS_ACCESS */
54 #if defined (ACE_HAS_WCHAR)
56 ACE_OS::access (const wchar_t *path, int amode)
58 #if defined (ACE_WIN32)
59 return ::_waccess (path, amode);
61 return ACE_OS::access (ACE_Wide_To_Ascii (path).char_rep (), amode);
62 #endif /* ACE_WIN32 */
64 #endif /* ACE_HAS_WCHAR */
67 ACE_OS::alarm (u_int secs)
69 ACE_OS_TRACE ("ACE_OS::alarm");
70 #if defined (ACE_LACKS_ALARM)
71 ACE_UNUSED_ARG (secs);
72 ACE_NOTSUP_RETURN (0);
74 return ::alarm (secs);
75 #endif /* ACE_LACKS_ALARM */
79 ACE_OS::getpagesize ()
81 ACE_OS_TRACE ("ACE_OS::getpagesize");
82 #if defined (ACE_WIN32)
84 ::GetSystemInfo (&sys_info);
85 return (long) sys_info.dwPageSize;
86 #elif defined (_SC_PAGESIZE)
87 return ::sysconf (_SC_PAGESIZE);
88 #elif defined (ACE_HAS_GETPAGESIZE)
89 return ::getpagesize ();
91 // Use the default set in config.h
93 #endif /* ACE_WIN32 */
97 ACE_OS::allocation_granularity ()
99 #if defined (ACE_WIN32)
100 SYSTEM_INFO sys_info;
101 ::GetSystemInfo (&sys_info);
102 return sys_info.dwAllocationGranularity;
104 return ACE_OS::getpagesize ();
105 #endif /* ACE_WIN32 */
109 ACE_OS::chdir (const char *path)
111 ACE_OS_TRACE ("ACE_OS::chdir");
112 #if defined (ACE_CHDIR_EQUIVALENT)
113 return ACE_CHDIR_EQUIVALENT (path);
115 return ::chdir (path);
116 #endif /* ACE_CHDIR_EQUIVALENT */
119 #if defined (ACE_HAS_WCHAR)
121 ACE_OS::chdir (const wchar_t *path)
123 #if defined (ACE_WIN32)
124 return ::_wchdir (path);
125 #else /* ACE_WIN32 */
126 return ACE_OS::chdir (ACE_Wide_To_Ascii (path).char_rep ());
127 #endif /* ACE_WIN32 */
129 #endif /* ACE_HAS_WCHAR */
132 ACE_OS::rmdir (const char *path)
134 #if defined (ACE_RMDIR_EQUIVALENT)
135 return ACE_RMDIR_EQUIVALENT (path);
137 return ::rmdir (path);
138 #endif /* ACE_WIN32 */
141 #if defined (ACE_HAS_WCHAR)
143 ACE_OS::rmdir (const wchar_t *path)
145 #if defined (ACE_WIN32)
146 return ::_wrmdir (path);
148 ACE_Wide_To_Ascii n_path (path);
149 return ACE_OS::rmdir (n_path.char_rep ());
150 #endif /* ACE_WIN32 */
152 #endif /* ACE_HAS_WCHAR */
154 // @todo: which 4 and why??? dhinton
155 // NOTE: The following four function definitions must appear before
156 // ACE_OS::sema_init ().
159 ACE_OS::close (ACE_HANDLE handle)
161 ACE_OS_TRACE ("ACE_OS::close");
162 #if defined (ACE_WIN32)
163 ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::CloseHandle (handle), ace_result_), int, -1);
164 #elif defined (ACE_MQX)
165 return MQX_Filesystem::inst ().close (handle);
167 return ::close (handle);
168 #endif /* ACE_WIN32 */
171 ACE_INLINE ACE_HANDLE
172 ACE_OS::dup (ACE_HANDLE handle)
174 ACE_OS_TRACE ("ACE_OS::dup");
175 #if defined (ACE_LACKS_DUP)
176 ACE_UNUSED_ARG (handle);
177 ACE_NOTSUP_RETURN (ACE_INVALID_HANDLE);
178 #elif defined (ACE_WIN32)
180 if (::DuplicateHandle(::GetCurrentProcess (),
182 ::GetCurrentProcess(),
186 DUPLICATE_SAME_ACCESS))
189 ACE_FAIL_RETURN (ACE_INVALID_HANDLE);
192 return ::dup (handle);
193 #endif /* ACE_LACKS_DUP */
196 ACE_INLINE ACE_HANDLE
197 ACE_OS::dup(ACE_HANDLE handle, pid_t pid)
199 ACE_OS_TRACE("ACE_OS::dup");
200 #if defined (ACE_LACKS_DUP)
201 ACE_UNUSED_ARG (handle);
202 ACE_UNUSED_ARG (pid);
203 ACE_NOTSUP_RETURN (ACE_INVALID_HANDLE);
204 #elif defined (ACE_WIN32)
206 ACE_HANDLE hTargetProcess = ::OpenProcess (PROCESS_DUP_HANDLE,
209 if(::DuplicateHandle(::GetCurrentProcess (),
215 DUPLICATE_SAME_ACCESS))
217 ::CloseHandle (hTargetProcess);
221 ACE_FAIL_RETURN (ACE_INVALID_HANDLE);
224 ACE_UNUSED_ARG (pid);
225 return ::dup(handle);
226 #endif /* ACE_LACKS_DUP */
230 ACE_OS::dup2 (ACE_HANDLE oldhandle, ACE_HANDLE newhandle)
232 ACE_OS_TRACE ("ACE_OS::dup2");
233 #if defined (ACE_LACKS_DUP2)
234 // msvcrt has _dup2 ?!
235 ACE_UNUSED_ARG (oldhandle);
236 ACE_UNUSED_ARG (newhandle);
237 ACE_NOTSUP_RETURN (-1);
239 return ::dup2 (oldhandle, newhandle);
240 #endif /* ACE_LACKS_DUP2 */
244 ACE_OS::execv (const char *path,
247 ACE_OS_TRACE ("ACE_OS::execv");
248 #if defined (ACE_LACKS_EXEC)
249 ACE_UNUSED_ARG (path);
250 ACE_UNUSED_ARG (argv);
252 ACE_NOTSUP_RETURN (-1);
253 #elif defined (ACE_WIN32)
254 # if defined (__BORLANDC__)
255 return ::execv (path, argv);
256 # elif defined (__MINGW32__)
257 return ::_execv (path, (char *const *) argv);
259 // Why this odd-looking code? If execv() returns at all, it's an error.
260 // Windows defines this as returning an intptr_t rather than a simple int,
261 // and the conversion triggers compile warnings. So just return -1 if
263 ::_execv (path, (const char *const *) argv);
265 # endif /* __BORLANDC__ */
267 return ::execv (path, argv);
268 #endif /* ACE_LACKS_EXEC */
272 ACE_OS::execve (const char *path,
276 ACE_OS_TRACE ("ACE_OS::execve");
277 #if defined (ACE_LACKS_EXEC)
278 ACE_UNUSED_ARG (path);
279 ACE_UNUSED_ARG (argv);
280 ACE_UNUSED_ARG (envp);
282 ACE_NOTSUP_RETURN (-1);
283 #elif defined (ACE_WIN32)
284 # if defined (__BORLANDC__)
285 return ::execve (path, argv, envp);
286 # elif defined (__MINGW32__)
287 return ::_execve (path, (char *const *) argv, (char *const *) envp);
289 // Why this odd-looking code? If execv() returns at all, it's an error.
290 // Windows defines this as returning an intptr_t rather than a simple int,
291 // and the conversion triggers compile warnings. So just return -1 if
293 ::_execve (path, (const char *const *) argv, (const char *const *) envp);
295 # endif /* __BORLANDC__ */
297 return ::execve (path, argv, envp);
298 #endif /* ACE_LACKS_EXEC */
302 ACE_OS::execvp (const char *file,
305 ACE_OS_TRACE ("ACE_OS::execvp");
306 #if defined (ACE_LACKS_EXEC) || defined (ACE_LACKS_EXECVP)
307 ACE_UNUSED_ARG (file);
308 ACE_UNUSED_ARG (argv);
310 ACE_NOTSUP_RETURN (-1);
311 #elif defined (ACE_WIN32)
312 # if defined (__BORLANDC__)
313 return ::execvp (file, argv);
314 # elif defined (__MINGW32__)
315 return ::_execvp (file, (char *const *) argv);
317 // Why this odd-looking code? If execv() returns at all, it's an error.
318 // Windows defines this as returning an intptr_t rather than a simple int,
319 // and the conversion triggers compile warnings. So just return -1 if
321 ::_execvp (file, (const char *const *) argv);
323 # endif /* __BORLANDC__ */
325 return ::execvp (file, argv);
326 #endif /* ACE_LACKS_EXEC */
332 ACE_OS_TRACE ("ACE_OS::fork");
333 #if defined (ACE_LACKS_FORK)
334 ACE_NOTSUP_RETURN (pid_t (-1));
337 #endif /* ACE_LACKS_FORK */
341 ACE_OS::fsync (ACE_HANDLE handle)
343 ACE_OS_TRACE ("ACE_OS::fsync");
344 # if defined (ACE_LACKS_FSYNC)
345 ACE_UNUSED_ARG (handle);
346 ACE_NOTSUP_RETURN (-1);
347 # elif defined (ACE_WIN32)
348 ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::FlushFileBuffers (handle), ace_result_), int, -1);
350 return ::fsync (handle);
351 # endif /* ACE_LACKS_FSYNC */
355 ACE_OS::ftruncate (ACE_HANDLE handle, ACE_OFF_T offset)
357 ACE_OS_TRACE ("ACE_OS::ftruncate");
358 #if defined (ACE_WIN32)
360 loff.QuadPart = offset;
361 if (::SetFilePointerEx (handle, loff, 0, FILE_BEGIN))
362 ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::SetEndOfFile (handle), ace_result_), int, -1);
364 ACE_FAIL_RETURN (-1);
365 #elif defined (ACE_LACKS_FTRUNCATE)
366 ACE_NOTSUP_RETURN (-1);
368 return ::ftruncate (handle, offset);
369 #endif /* ACE_WIN32 */
373 ACE_OS::getcwd (char *buf, size_t size)
375 ACE_OS_TRACE ("ACE_OS::getcwd");
376 #if defined (ACE_GETCWD_EQUIVALENT)
377 return ACE_GETCWD_EQUIVALENT (buf, static_cast<int> (size));
378 #elif defined (ACE_WIN32)
379 return ::getcwd (buf, static_cast<int> (size));
381 return ::getcwd (buf, size);
382 #endif /* ACE_LACKS_GETCWD */
385 #if defined (ACE_HAS_WCHAR)
387 ACE_OS::getcwd (wchar_t *buf, size_t size)
389 # if defined (ACE_WIN32)
390 return ::_wgetcwd (buf, static_cast<int> (size));
392 char *narrow_buf = new char[size];
394 result = ACE_OS::getcwd (narrow_buf, size);
395 ACE_Ascii_To_Wide wide_buf (result);
396 delete [] narrow_buf;
398 ACE_OS::strsncpy (buf, wide_buf.wchar_rep (), size);
399 return result == 0 ? 0 : buf;
400 # endif /* ACE_WIN32 */
402 #endif /* ACE_HAS_WCHAR */
407 ACE_OS_TRACE ("ACE_OS::getgid");
408 #if defined (ACE_LACKS_GETGID)
409 ACE_NOTSUP_RETURN (static_cast<gid_t> (-1));
412 # endif /* ACE_LACKS_GETGID */
418 ACE_OS_TRACE ("ACE_OS::getegid");
419 #if defined (ACE_LACKS_GETEGID)
420 ACE_NOTSUP_RETURN (static_cast<gid_t> (-1));
423 # endif /* ACE_LACKS_GETEGID */
427 ACE_OS::getopt (int argc, char *const *argv, const char *optstring)
429 ACE_OS_TRACE ("ACE_OS::getopt");
430 #if defined (ACE_LACKS_GETOPT)
431 ACE_UNUSED_ARG (argc);
432 ACE_UNUSED_ARG (argv);
433 ACE_UNUSED_ARG (optstring);
434 ACE_NOTSUP_RETURN (-1);
436 return ::getopt (argc, argv, optstring);
437 # endif /* ACE_LACKS_GETOPT */
441 ACE_OS::getpgid (pid_t pid)
443 ACE_OS_TRACE ("ACE_OS::getpgid");
444 #if defined (ACE_LACKS_GETPGID)
445 ACE_UNUSED_ARG (pid);
446 ACE_NOTSUP_RETURN (-1);
447 #elif defined (ACE_LINUX) && __GLIBC__ > 1 && __GLIBC_MINOR__ >= 0
448 // getpgid() is from SVR4, which appears to be the reason why GLIBC
449 // doesn't enable its prototype by default.
450 // Rather than create our own extern prototype, just use the one
451 // that is visible (ugh).
452 return ::__getpgid (pid);
454 return ::getpgid (pid);
455 #endif /* ACE_LACKS_GETPGID */
461 // ACE_OS_TRACE ("ACE_OS::getpid");
462 #if defined (ACE_LACKS_GETPID)
463 ACE_NOTSUP_RETURN (-1);
464 #elif defined (ACE_WIN32)
465 return ::GetCurrentProcessId ();
468 #endif /* ACE_LACKS_GETPID */
474 ACE_OS_TRACE ("ACE_OS::getppid");
475 #if defined (ACE_LACKS_GETPPID)
476 ACE_NOTSUP_RETURN (-1);
479 #endif /* ACE_LACKS_GETPPID */
485 ACE_OS_TRACE ("ACE_OS::getuid");
486 #if defined (ACE_LACKS_GETUID)
487 ACE_NOTSUP_RETURN (static_cast<uid_t> (-1));
490 # endif /* ACE_LACKS_GETUID*/
496 ACE_OS_TRACE ("ACE_OS::geteuid");
497 #if defined (ACE_LACKS_GETEUID)
498 ACE_NOTSUP_RETURN (static_cast<uid_t> (-1));
501 # endif /* ACE_LACKS_GETEUID */
505 ACE_OS::hostname (char name[], size_t maxnamelen)
507 ACE_OS_TRACE ("ACE_OS::hostname");
508 #if defined (ACE_VXWORKS)
509 return ::gethostname (name, maxnamelen);
510 #elif defined (ACE_WIN32)
511 if (::gethostname (name, ACE_Utils::truncate_cast<int> (maxnamelen)) == 0)
517 ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (::GetComputerNameA (name,
518 LPDWORD (&maxnamelen)),
519 ace_result_), int, -1);
521 #elif defined (ACE_MQX)
522 const int enet_device = 0;
523 IPCFG_IP_ADDRESS_DATA ip_data;
524 if (ipcfg_get_ip (enet_device, &ip_data))
526 ACE_OS::snprintf(name, maxnamelen, "%d.%d.%d.%d", IPBYTES(ip_data.ip));
530 #elif defined (ACE_LACKS_GETHOSTNAME)
531 ACE_NOTSUP_RETURN (-1);
532 #else /* ACE_VXWORKS */
533 ACE_utsname host_info;
535 if (ACE_OS::uname (&host_info) == -1)
539 ACE_OS::strsncpy (name, host_info.nodename, maxnamelen);
542 #endif /* ACE_VXWORKS */
545 #if defined (ACE_HAS_WCHAR)
547 ACE_OS::hostname (wchar_t name[], size_t maxnamelen)
549 #if defined (ACE_WIN32)
550 ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (GetComputerNameW (name,
551 LPDWORD (&maxnamelen)),
552 ace_result_), int, -1);
553 #else /* ACE_WIN32 */
554 // Emulate using the char version
557 ACE_NEW_RETURN (char_name, char[maxnamelen], -1);
559 int result = ACE_OS::hostname(char_name, maxnamelen);
560 ACE_OS::strcpy (name, ACE_Ascii_To_Wide (char_name).wchar_rep ());
564 #endif /* ACE_WIN32 */
566 #endif /* ACE_HAS_WCHAR */
569 ACE_OS::isatty (int handle)
571 ACE_OS_TRACE ("ACE_OS::isatty");
572 #if defined (ACE_LACKS_ISATTY)
573 ACE_UNUSED_ARG (handle);
575 # elif defined (ACE_WIN32)
576 return ::_isatty (handle);
578 return ::isatty (handle);
579 # endif /* ACE_LACKS_ISATTY */
582 #if defined (ACE_WIN32)
584 ACE_OS::isatty (ACE_HANDLE handle)
586 #if defined (ACE_LACKS_ISATTY)
587 ACE_UNUSED_ARG (handle);
590 int const fd = ::_open_osfhandle (intptr_t (handle), 0);
594 status = ::_isatty (fd);
598 #endif /* ACE_LACKS_ISATTY */
601 #endif /* ACE_WIN32 */
604 ACE_OS::lseek (ACE_HANDLE handle, ACE_OFF_T offset, int whence)
606 ACE_OS_TRACE ("ACE_OS::lseek");
607 #if defined (ACE_WIN32)
608 # if SEEK_SET != FILE_BEGIN || SEEK_CUR != FILE_CURRENT || SEEK_END != FILE_END
609 //#error Windows NT is evil AND rude!
616 whence = FILE_CURRENT;
623 return static_cast<ACE_OFF_T> (-1); // rather safe than sorry
625 # endif /* SEEK_SET != FILE_BEGIN || SEEK_CUR != FILE_CURRENT || SEEK_END != FILE_END */
626 LONG low_offset = ACE_LOW_PART(offset);
627 LONG high_offset = ACE_HIGH_PART(offset);
629 ::SetFilePointer (handle, low_offset, &high_offset, whence);
630 if (result == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
631 ACE_FAIL_RETURN (static_cast<ACE_OFF_T> (-1));
634 #elif defined (ACE_MQX)
638 whence = IO_SEEK_SET;
641 whence = IO_SEEK_CUR;
644 whence = IO_SEEK_END;
648 return static_cast<ACE_OFF_T> (-1);
650 return static_cast<ACE_OFF_T> (MQX_Filesystem::inst ().lseek (handle, offset, whence));
652 return ::lseek (handle, offset, whence);
653 #endif /* ACE_WIN32 */
656 #if defined (ACE_HAS_LLSEEK) || defined (ACE_HAS_LSEEK64)
657 ACE_INLINE ACE_LOFF_T
658 ACE_OS::llseek (ACE_HANDLE handle, ACE_LOFF_T offset, int whence)
660 ACE_OS_TRACE ("ACE_OS::llseek");
662 #if ACE_SIZEOF_LONG == 8
663 /* The native lseek is 64 bit. Use it. */
664 return ACE_OS::lseek (handle, offset, whence);
665 #elif defined (ACE_HAS_LLSEEK) && defined (ACE_HAS_LSEEK64)
666 # error Either ACE_HAS_LSEEK64 and ACE_HAS_LLSEEK should be defined, not both!
667 #elif defined (ACE_HAS_LSEEK64)
668 return ::lseek64 (handle, offset, whence);
669 #elif defined (ACE_HAS_LLSEEK)
670 # if defined (ACE_WIN32)
671 LARGE_INTEGER distance, new_file_pointer;
673 distance.QuadPart = offset;
676 (::SetFilePointerEx (handle, distance, &new_file_pointer, whence)
677 ? new_file_pointer.QuadPart
678 : static_cast<ACE_LOFF_T> (-1));
680 return ::llseek (handle, offset, whence);
684 #endif /* ACE_HAS_LLSEEK || ACE_HAS_LSEEK64 */
687 ACE_OS::read (ACE_HANDLE handle, void *buf, size_t len)
689 ACE_OS_TRACE ("ACE_OS::read");
690 #if defined (ACE_WIN32)
692 if (::ReadFile (handle, buf, static_cast<DWORD> (len), &ok_len, 0))
693 return (ssize_t) ok_len;
695 ACE_FAIL_RETURN (-1);
697 #elif defined (ACE_MQX)
698 return MQX_Filesystem::inst ().read (handle, reinterpret_cast<unsigned char *> (buf), len);
704 # if defined (ACE_HAS_CHARPTR_SOCKOPT)
705 ACE_OSCALL (::read (handle, static_cast <char *> (buf), len), ssize_t, result);
707 ACE_OSCALL (::read (handle, buf, len), ssize_t, result);
708 # endif /* ACE_HAS_CHARPTR_SOCKOPT */
710 # if !(defined (EAGAIN) && defined (EWOULDBLOCK) && EAGAIN == EWOULDBLOCK)
711 // Optimize this code out if we can detect that EAGAIN ==
712 // EWOULDBLOCK at compile time. If we cannot detect equality at
713 // compile-time (e.g. if EAGAIN or EWOULDBLOCK are not preprocessor
714 // macros) perform the check at run-time. The goal is to avoid two
715 // TSS accesses in the _REENTRANT case when EAGAIN == EWOULDBLOCK.
717 # if !defined (EAGAIN) || !defined (EWOULDBLOCK)
718 && EAGAIN != EWOULDBLOCK
719 # endif /* !EAGAIN || !EWOULDBLOCK */
724 # endif /* EAGAIN != EWOULDBLOCK*/
727 #endif /* ACE_WIN32 */
731 ACE_OS::read (ACE_HANDLE handle, void *buf, size_t len,
732 ACE_OVERLAPPED *overlapped)
734 ACE_OS_TRACE ("ACE_OS::read");
735 #if defined (ACE_WIN32)
737 DWORD short_len = static_cast<DWORD> (len);
738 if (::ReadFile (handle, buf, short_len, &ok_len, overlapped))
739 return (ssize_t) ok_len;
741 ACE_FAIL_RETURN (-1);
743 ACE_UNUSED_ARG (overlapped);
744 return ACE_OS::read (handle, buf, len);
745 #endif /* ACE_WIN32 */
749 ACE_OS::readlink (const char *path, char *buf, size_t bufsiz)
751 ACE_OS_TRACE ("ACE_OS::readlink");
752 # if defined (ACE_LACKS_READLINK)
753 ACE_UNUSED_ARG (path);
754 ACE_UNUSED_ARG (buf);
755 ACE_UNUSED_ARG (bufsiz);
756 ACE_NOTSUP_RETURN (-1);
757 # elif defined(ACE_HAS_NONCONST_READLINK)
758 return ::readlink (const_cast <char *>(path), buf, bufsiz);
760 return ::readlink (path, buf, bufsiz);
761 # endif /* ACE_LACKS_READLINK */
765 ACE_OS::pipe (ACE_HANDLE fds[])
767 ACE_OS_TRACE ("ACE_OS::pipe");
768 # if defined (ACE_LACKS_PIPE)
769 ACE_UNUSED_ARG (fds);
770 ACE_NOTSUP_RETURN (-1);
771 # elif defined (ACE_WIN32)
772 ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL
773 (::CreatePipe (&fds[0], &fds[1], 0, 0),
774 ace_result_), int, -1);
777 # endif /* ACE_LACKS_PIPE */
781 ACE_OS::sbrk (intptr_t brk)
783 #if defined (ACE_LACKS_SBRK)
784 ACE_UNUSED_ARG (brk);
785 ACE_NOTSUP_RETURN (0);
788 #endif /* ACE_LACKS_SBRK */
792 ACE_OS::setgid (gid_t gid)
794 ACE_OS_TRACE ("ACE_OS::setgid");
795 #if defined (ACE_LACKS_SETGID)
796 ACE_UNUSED_ARG (gid);
797 ACE_NOTSUP_RETURN (-1);
799 return ::setgid (gid);
800 # endif /* ACE_LACKS_SETGID */
804 ACE_OS::setegid (gid_t gid)
806 ACE_OS_TRACE ("ACE_OS::setegid");
807 #if defined (ACE_LACKS_SETEGID)
808 ACE_UNUSED_ARG (gid);
809 ACE_NOTSUP_RETURN (-1);
811 return ::setegid (gid);
812 # endif /* ACE_LACKS_SETEGID */
816 ACE_OS::setpgid (pid_t pid, pid_t pgid)
818 ACE_OS_TRACE ("ACE_OS::setpgid");
819 #if defined (ACE_LACKS_SETPGID)
820 ACE_UNUSED_ARG (pid);
821 ACE_UNUSED_ARG (pgid);
822 ACE_NOTSUP_RETURN (-1);
824 return ::setpgid (pid, pgid);
825 #endif /* ACE_LACKS_SETPGID */
829 ACE_OS::setregid (gid_t rgid, gid_t egid)
831 ACE_OS_TRACE ("ACE_OS::setregid");
832 #if defined (ACE_LACKS_SETREGID)
833 ACE_UNUSED_ARG (rgid);
834 ACE_UNUSED_ARG (egid);
835 ACE_NOTSUP_RETURN (-1);
837 return ::setregid (rgid, egid);
838 #endif /* ACE_LACKS_SETREGID */
842 ACE_OS::setreuid (uid_t ruid, uid_t euid)
844 ACE_OS_TRACE ("ACE_OS::setreuid");
845 #if defined (ACE_LACKS_SETREUID)
846 ACE_UNUSED_ARG (ruid);
847 ACE_UNUSED_ARG (euid);
848 ACE_NOTSUP_RETURN (-1);
850 return ::setreuid (ruid, euid);
851 #endif /* ACE_LACKS_SETREUID */
857 ACE_OS_TRACE ("ACE_OS::setsid");
858 #if defined (ACE_LACKS_SETSID)
859 ACE_NOTSUP_RETURN (-1);
862 # endif /* ACE_LACKS_SETSID */
866 ACE_OS::setuid (uid_t uid)
868 ACE_OS_TRACE ("ACE_OS::setuid");
869 #if defined (ACE_LACKS_SETUID)
870 ACE_UNUSED_ARG (uid);
871 ACE_NOTSUP_RETURN (-1);
873 return ::setuid (uid);
874 # endif /* ACE_LACKS_SETUID */
878 ACE_OS::seteuid (uid_t uid)
880 ACE_OS_TRACE ("ACE_OS::seteuid");
881 #if defined (ACE_LACKS_SETEUID)
882 ACE_UNUSED_ARG (uid);
883 ACE_NOTSUP_RETURN (-1);
885 return ::seteuid (uid);
886 # endif /* ACE_LACKS_SETEUID */
890 ACE_OS::sleep (u_int seconds)
892 ACE_OS_TRACE ("ACE_OS::sleep");
893 #if defined (ACE_HAS_CLOCK_GETTIME)
894 struct timespec rqtp;
895 // Initializer doesn't work with Green Hills 1.8.7
896 rqtp.tv_sec = seconds;
898 //FUZZ: disable check_for_lack_ACE_OS
899 return ::nanosleep (&rqtp, 0);
900 //FUZZ: enable check_for_lack_ACE_OS
901 #elif defined (ACE_LACKS_SLEEP)
902 ACE_UNUSED_ARG (seconds);
903 ACE_NOTSUP_RETURN (-1);
904 #elif defined (ACE_WIN32)
905 ::Sleep (seconds * ACE_ONE_SECOND_IN_MSECS);
907 #elif defined (ACE_MQX)
908 _time_delay (seconds * ACE_ONE_SECOND_IN_MSECS);
911 return ::sleep (seconds);
912 #endif /* ACE_WIN32 */
916 ACE_OS::sleep (const ACE_Time_Value &tv)
918 ACE_OS_TRACE ("ACE_OS::sleep");
919 #if defined (ACE_WIN32)
920 ::Sleep (tv.msec ());
922 #elif defined (ACE_MQX)
923 _time_delay (tv.msec ());
925 #elif defined (ACE_HAS_CLOCK_GETTIME)
926 timespec_t rqtp = tv;
927 //FUZZ: disable check_for_lack_ACE_OS
928 return ::nanosleep (&rqtp, 0);
929 //FUZZ: enable check_for_lack_ACE_OS
931 # if defined (ACE_HAS_NONCONST_SELECT_TIMEVAL)
932 // Copy the timeval, because this platform doesn't declare the timeval
933 // as a pointer to const.
934 timeval tv_copy = tv;
935 //FUZZ: disable check_for_lack_ACE_OS
936 return ::select (0, 0, 0, 0, &tv_copy);
937 //FUZZ: enable check_for_lack_ACE_OS
938 # else /* ! ACE_HAS_NONCONST_SELECT_TIMEVAL */
939 const timeval *tvp = tv;
940 //FUZZ: disable check_for_lack_ACE_OS
941 return ::select (0, 0, 0, 0, tvp);
942 //FUZZ: enable check_for_lack_ACE_OS
943 # endif /* ACE_HAS_NONCONST_SELECT_TIMEVAL */
944 #endif /* ACE_WIN32 */
948 ACE_OS::swab (const void *src,
952 #if defined (ACE_LACKS_SWAB)
953 // ------------------------------------------------------------
954 // The following copyright notice applies to the swab()
955 // implementation within this "ACE_LACKS_SWAB" block of code.
956 // ------------------------------------------------------------
958 Copyright (c) 1994-2006 Red Hat, Inc. All rights reserved.
960 This copyrighted material is made available to anyone wishing to
961 use, modify, copy, or redistribute it subject to the terms and
962 conditions of the BSD License. This program is distributed in
963 the hope that it will be useful, but WITHOUT ANY WARRANTY
964 expressed or implied, including the implied warranties of
965 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of
966 this license is available at
967 http://www.opensource.org/licenses. Any Red Hat trademarks that
968 are incorporated in the source code or documentation are not
969 subject to the BSD License and may only be used or replicated with
970 the express permission of Red Hat, Inc.
973 const char *from = static_cast<const char*> (src);
974 char *to = static_cast<char *> (dest);
976 for (ptr = 1; ptr < length; ptr += 2)
979 char q = from[ptr-1];
983 if (ptr == length) /* I.e., if length is odd, */
984 to[ptr-1] = 0; /* then pad with a NUL. */
985 #elif defined (ACE_HAS_NONCONST_SWAB)
986 const char *tmp = static_cast<const char*> (src);
987 char *from = const_cast<char *> (tmp);
988 char *to = static_cast<char *> (dest);
989 # if defined (ACE_HAS_INT_SWAB)
990 int ilength = ACE_Utils::truncate_cast<int> (length);
991 # if defined (ACE_SWAB_EQUIVALENT)
992 ACE_SWAB_EQUIVALENT (from, to, ilength);
994 ::swab (from, to, ilength);
997 ::swab (from, to, length);
998 # endif /* ACE_HAS_INT_SWAB */
999 #elif defined (ACE_HAS_CONST_CHAR_SWAB)
1000 const char *from = static_cast<const char*> (src);
1001 char *to = static_cast<char *> (dest);
1002 ::swab (from, to, length);
1004 ::swab (src, dest, length);
1005 #endif /* ACE_LACKS_SWAB */
1010 ACE_OS::sysconf (int name)
1012 ACE_OS_TRACE ("ACE_OS::sysconf");
1013 #if defined (ACE_LACKS_SYSCONF)
1014 ACE_UNUSED_ARG (name);
1015 ACE_NOTSUP_RETURN (-1);
1017 return ::sysconf (name);
1018 #endif /* ACE_LACKS_SYSCONF */
1022 ACE_OS::sysinfo (int /*cmd*/, char * /*buf*/, long /*count*/)
1024 ACE_OS_TRACE ("ACE_OS::sysinfo");
1025 ACE_NOTSUP_RETURN (0);
1029 ACE_OS::truncate (const ACE_TCHAR *filename,
1032 ACE_OS_TRACE ("ACE_OS::truncate");
1033 #if defined (ACE_WIN32)
1034 ACE_HANDLE handle = ACE_OS::open (filename, O_WRONLY, ACE_DEFAULT_FILE_PERMS);
1036 LARGE_INTEGER loffset;
1037 loffset.QuadPart = offset;
1039 if (handle == ACE_INVALID_HANDLE)
1041 ACE_FAIL_RETURN (-1);
1043 else if (::SetFilePointerEx (handle, loffset, 0, FILE_BEGIN))
1045 BOOL result = ::SetEndOfFile (handle);
1046 ::CloseHandle (handle);
1047 ACE_WIN32CALL_RETURN (ACE_ADAPT_RETVAL (result, ace_result_), int, -1);
1051 ::CloseHandle (handle);
1052 ACE_FAIL_RETURN (-1);
1055 #elif !defined (ACE_LACKS_TRUNCATE)
1056 return ::truncate (ACE_TEXT_ALWAYS_CHAR (filename), offset);
1058 ACE_UNUSED_ARG (filename);
1059 ACE_UNUSED_ARG (offset);
1060 ACE_NOTSUP_RETURN (-1);
1061 #endif /* ACE_WIN32 */
1064 ACE_INLINE useconds_t
1065 ACE_OS::ualarm (useconds_t usecs, useconds_t interval)
1067 ACE_OS_TRACE ("ACE_OS::ualarm");
1069 #if defined (ACE_HAS_UALARM)
1070 return ::ualarm (usecs, interval);
1071 #elif !defined (ACE_LACKS_UNIX_SIGNALS) && !defined (ACE_LACKS_ALARM)
1072 ACE_UNUSED_ARG (interval);
1073 # if defined (ACE_VXWORKS) && ACE_VXWORKS >= 0x690 && defined (_WRS_CONFIG_LP64)
1074 return ::alarm (static_cast<unsigned int> (usecs * ACE_ONE_SECOND_IN_USECS));
1076 return ::alarm (usecs * ACE_ONE_SECOND_IN_USECS);
1079 ACE_UNUSED_ARG (usecs);
1080 ACE_UNUSED_ARG (interval);
1081 ACE_NOTSUP_RETURN (0);
1082 #endif /* ACE_HAS_UALARM */
1085 ACE_INLINE useconds_t
1086 ACE_OS::ualarm (const ACE_Time_Value &tv,
1087 const ACE_Time_Value &tv_interval)
1089 ACE_OS_TRACE ("ACE_OS::ualarm");
1091 #if defined (ACE_HAS_UALARM)
1092 useconds_t usecs = (tv.sec () * ACE_ONE_SECOND_IN_USECS) + tv.usec ();
1093 useconds_t interval =
1094 (tv_interval.sec () * ACE_ONE_SECOND_IN_USECS) + tv_interval.usec ();
1095 return ::ualarm (usecs, interval);
1096 #elif !defined (ACE_LACKS_UNIX_SIGNALS) && !defined (ACE_LACKS_ALARM)
1097 ACE_UNUSED_ARG (tv_interval);
1098 # if defined (ACE_VXWORKS) && ACE_VXWORKS >= 0x690 && defined (_WRS_CONFIG_LP64)
1099 return ::alarm (static_cast<unsigned int> (tv.sec ()));
1101 return ::alarm (tv.sec ());
1104 ACE_UNUSED_ARG (tv_interval);
1105 ACE_UNUSED_ARG (tv);
1106 ACE_NOTSUP_RETURN (0);
1107 #endif /* ACE_HAS_UALARM */
1111 ACE_OS::unlink (const char *path)
1113 ACE_OS_TRACE ("ACE_OS::unlink");
1114 #if defined (ACE_LACKS_UNLINK)
1115 ACE_UNUSED_ARG (path);
1116 ACE_NOTSUP_RETURN (-1);
1117 #elif defined (ACE_UNLINK_EQUIVALENT)
1118 return ACE_UNLINK_EQUIVALENT (path);
1120 return ::unlink (path);
1121 #endif /* ACE_LACKS_UNLINK */
1124 #if defined (ACE_HAS_WCHAR)
1126 ACE_OS::unlink (const wchar_t *path)
1128 ACE_OS_TRACE ("ACE_OS::unlink");
1129 # if defined (ACE_WIN32)
1130 return ::_wunlink (path);
1132 ACE_Wide_To_Ascii npath (path);
1133 return ACE_OS::unlink (npath.char_rep ());
1134 # endif /* ACE_WIN32 */
1136 #endif /* ACE_HAS_WCHAR */
1139 ACE_OS::write (ACE_HANDLE handle, const void *buf, size_t nbyte)
1141 ACE_OS_TRACE ("ACE_OS::write");
1142 #if defined (ACE_WIN32)
1143 DWORD bytes_written; // This is set to 0 byte WriteFile.
1145 // Strictly correctly, we should loop writing all the data if more
1146 // than a DWORD length can hold.
1147 DWORD short_nbyte = static_cast<DWORD> (nbyte);
1148 if (::WriteFile (handle, buf, short_nbyte, &bytes_written, 0))
1149 return (ssize_t) bytes_written;
1151 ACE_FAIL_RETURN (-1);
1152 #elif defined (ACE_MQX)
1153 return MQX_Filesystem::inst ().write (handle, reinterpret_cast<const unsigned char *> (buf), nbyte);
1155 # if defined (ACE_HAS_CHARPTR_SOCKOPT)
1156 return ::write (handle, static_cast <char *> (const_cast <void *> (buf)), nbyte);
1158 return ::write (handle, buf, nbyte);
1159 # endif /* ACE_HAS_CHARPTR_SOCKOPT */
1160 #endif /* ACE_WIN32 */
1164 ACE_OS::write (ACE_HANDLE handle,
1167 ACE_OVERLAPPED *overlapped)
1169 ACE_OS_TRACE ("ACE_OS::write");
1170 #if defined (ACE_WIN32)
1171 DWORD bytes_written; // This is set to 0 byte WriteFile.
1173 DWORD short_nbyte = static_cast<DWORD> (nbyte);
1174 if (::WriteFile (handle, buf, short_nbyte, &bytes_written, overlapped))
1175 return (ssize_t) bytes_written;
1177 ACE_FAIL_RETURN (-1);
1179 ACE_UNUSED_ARG (overlapped);
1180 return ACE_OS::write (handle, buf, nbyte);
1181 #endif /* ACE_WIN32 */
1184 ACE_END_VERSIONED_NAMESPACE_DECL