diff options
Diffstat (limited to 'ace/OS_NS_unistd.cpp')
-rw-r--r-- | ace/OS_NS_unistd.cpp | 189 |
1 files changed, 31 insertions, 158 deletions
diff --git a/ace/OS_NS_unistd.cpp b/ace/OS_NS_unistd.cpp index e23686974c7..5bddc627589 100644 --- a/ace/OS_NS_unistd.cpp +++ b/ace/OS_NS_unistd.cpp @@ -1,3 +1,4 @@ +// -*- C++ -*- // $Id$ #include "ace/OS_NS_unistd.h" @@ -16,7 +17,11 @@ ACE_RCSID(ace, OS_NS_unistd, "$Id$") #include "ace/OS_NS_Thread.h" #include "ace/Object_Manager_Base.h" #include "ace/os_include/sys/os_pstat.h" -#include "ace/os_include/sys/os_sysctl.h" + +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) +// for sysctl(), used by ACE_OS::num_processors() +#include <sys/sysctl.h> +#endif #if defined (ACE_NEEDS_FTRUNCATE) extern "C" int @@ -34,8 +39,6 @@ ftruncate (ACE_HANDLE handle, long len) /*****************************************************************************/ -ACE_BEGIN_VERSIONED_NAMESPACE_DECL - int ACE_OS::argv_to_string (ACE_TCHAR **argv, ACE_TCHAR *&buf, @@ -54,7 +57,7 @@ ACE_OS::argv_to_string (ACE_TCHAR **argv, // Account for environment variables. if (substitute_env_args && argv[i][0] == ACE_LIB_TEXT ('$')) { -# if defined (ACE_WIN32) || !defined (ACE_HAS_WCHAR) +# if defined (ACE_WIN32) ACE_TCHAR *temp = 0; // Win32 is the only platform with a wide-char ACE_OS::getenv(). if ((temp = ACE_OS::getenv (&argv[i][1])) != 0) @@ -62,17 +65,17 @@ ACE_OS::argv_to_string (ACE_TCHAR **argv, else buf_len += ACE_OS::strlen (argv[i]); # else - // This is an ACE_HAS_WCHAR platform and not ACE_WIN32. + // This is not ACE_WIN32. // Convert the env variable name for getenv(), then add // the length of the returned char *string. Later, when we // actually use the returned env variable value, convert it // as well. - char *ctemp = ACE_OS::getenv (ACE_TEXT_ALWAYS_CHAR (&argv[i][1])); + char *ctemp = ACE_OS::getenv (ACE_TEXT_TO_CHAR_IN (&argv[i][1])); if (ctemp == 0) buf_len += ACE_OS::strlen (argv[i]); else buf_len += ACE_OS::strlen (ctemp); -# endif /* ACE_WIN32 || !ACE_HAS_WCHAR */ +# endif /* ACE_WIN32 */ } else #endif /* ACE_LACKS_ENV */ @@ -101,7 +104,7 @@ ACE_OS::argv_to_string (ACE_TCHAR **argv, // Account for environment variables. if (substitute_env_args && argv[j][0] == ACE_LIB_TEXT ('$')) { -# if defined (ACE_WIN32) || !defined (ACE_HAS_WCHAR) +# if defined (ACE_WIN32) // Win32 is the only platform with a wide-char ACE_OS::getenv(). ACE_TCHAR *temp = ACE_OS::getenv (&argv[j][1]); if (temp != 0) @@ -109,15 +112,15 @@ ACE_OS::argv_to_string (ACE_TCHAR **argv, else end = ACE_OS::strecpy (end, argv[j]); # else - // This is an ACE_HAS_WCHAR platform and not ACE_WIN32. + // This is not ACE_WIN32. // Convert the env variable name for getenv(), then convert // the returned char *string back to wchar_t. - char *ctemp = ACE_OS::getenv (ACE_TEXT_ALWAYS_CHAR (&argv[j][1])); + char *ctemp = ACE_OS::getenv (ACE_TEXT_TO_CHAR_IN (&argv[j][1])); if (ctemp == 0) end = ACE_OS::strecpy (end, argv[j]); else - end = ACE_OS::strecpy (end, ACE_TEXT_CHAR_TO_TCHAR (ctemp)); -# endif /* ACE_WIN32 || !ACE_HAS_WCHAR */ + end = ACE_OS::strecpy (end, ACE_TEXT_TO_TCHAR_IN (ctemp)); +# endif /* ACE_WIN32 */ } else #endif /* ACE_LACKS_ENV */ @@ -248,7 +251,7 @@ ACE_OS::fork_exec (ACE_TCHAR *argv[]) // narrow char strings for execv(). char **cargv; int arg_count; -# endif /* ACE_HAS_WCHAR */ +# endif /* ACE_USES_WCHAR */ switch (result) { @@ -267,7 +270,7 @@ ACE_OS::fork_exec (ACE_TCHAR *argv[]) --arg_count; // Back to 0-indexed cargv[arg_count] = 0; while (--arg_count >= 0) - cargv[arg_count] = ACE_Wide_To_Ascii::convert (argv[arg_count]); + cargv[arg_count] = ACE_TEXT_TO_CHAR_OUT(argv[arg_count]); // memory allocated! // Don't worry about freeing the cargv or the strings it points to. // Either the process will be replaced, or we'll exit. if (ACE_OS::execv (cargv[0], cargv) == -1) @@ -282,7 +285,7 @@ ACE_OS::fork_exec (ACE_TCHAR *argv[]) // If the execv fails, this child needs to exit. ACE_OS::exit (errno); } -# endif /* ACE_HAS_WCHAR */ +# endif /* ACE_USES_WCHAR */ default: // Server process. The fork succeeded. @@ -298,17 +301,17 @@ ACE_OS::num_processors (void) #if defined (ACE_HAS_PHARLAP) return 1; -#elif defined (ACE_WIN32) +#elif defined (ACE_WIN32) || defined (ACE_WIN64) SYSTEM_INFO sys_info; ::GetSystemInfo (&sys_info); return sys_info.dwNumberOfProcessors; -#elif defined (_SC_NPROCESSORS_CONF) +#elif defined (linux) || defined (sun) || defined (DIGITAL_UNIX) || defined (CYGWIN32) return ::sysconf (_SC_NPROCESSORS_CONF); -#elif defined (ACE_HAS_SYSCTL) +#elif defined(__FreeBSD__) || defined (__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) int num_processors; int mib[2] = { CTL_HW, HW_NCPU }; size_t len = sizeof (num_processors); - + sysctl(mib, 2, &num_processors, &len, NULL, 0); return num_processors; #else @@ -323,25 +326,25 @@ ACE_OS::num_processors_online (void) #if defined (ACE_HAS_PHARLAP) return 1; -#elif defined (ACE_WIN32) +#elif defined (ACE_WIN32) || defined (ACE_WIN64) SYSTEM_INFO sys_info; ::GetSystemInfo (&sys_info); return sys_info.dwNumberOfProcessors; -#elif defined (_SC_NPROCESSORS_ONLN) +#elif defined (linux) || defined (sun) || defined (DIGITAL_UNIX) || defined (CYGWIN32) return ::sysconf (_SC_NPROCESSORS_ONLN); -#elif defined (ACE_HAS_SYSCTL) - int num_processors; - int mib[2] = { CTL_HW, HW_NCPU }; - size_t len = sizeof (num_processors); - - sysctl(mib, 2, &num_processors, &len, NULL, 0); - return num_processors; #elif defined (__hpux) struct pst_dynamic psd; if (::pstat_getdynamic (&psd, sizeof (psd), (size_t) 1, 0) != -1) return psd.psd_proc_cnt; else return -1; +#elif defined(__FreeBSD__) || defined (__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) + int num_processors; + int mib[2] = { CTL_HW, HW_NCPU }; + size_t len = sizeof (num_processors); + + sysctl(mib, 2, &num_processors, &len, NULL, 0); + return num_processors; #else ACE_NOTSUP_RETURN (-1); #endif @@ -616,135 +619,6 @@ ACE_OS::pwrite (ACE_HANDLE handle, # endif /* ACE_HAD_P_READ_WRITE */ } -int -ACE_OS::string_to_argv (ACE_TCHAR *buf, - int &argc, - ACE_TCHAR **&argv, - int substitute_env_args) -{ - // Reset the number of arguments - argc = 0; - - if (buf == 0) - return -1; - - ACE_TCHAR *cp = buf; - - // First pass: count arguments. - - // '#' is the start-comment token.. - while (*cp != ACE_LIB_TEXT ('\0') && *cp != ACE_LIB_TEXT ('#')) - { - // Skip whitespace.. - while (ACE_OS::ace_isspace (*cp)) - cp++; - - // Increment count and move to next whitespace.. - if (*cp != ACE_LIB_TEXT ('\0')) - argc++; - - while (*cp != ACE_LIB_TEXT ('\0') && !ACE_OS::ace_isspace (*cp)) - { - // Grok quotes.... - if (*cp == ACE_LIB_TEXT ('\'') || *cp == ACE_LIB_TEXT ('"')) - { - ACE_TCHAR quote = *cp; - - // Scan past the string.. - for (cp++; *cp != ACE_LIB_TEXT ('\0') && *cp != quote; cp++) - continue; - - // '\0' implies unmatched quote.. - if (*cp == ACE_LIB_TEXT ('\0')) - { - argc--; - break; - } - else - cp++; - } - else - cp++; - } - } - - // Second pass: copy arguments. - ACE_TCHAR arg[ACE_DEFAULT_ARGV_BUFSIZ]; - ACE_TCHAR *argp = arg; - - // Make sure that the buffer we're copying into is always large - // enough. - if (cp - buf >= ACE_DEFAULT_ARGV_BUFSIZ) - ACE_NEW_RETURN (argp, - ACE_TCHAR[cp - buf + 1], - -1); - - // Make a new argv vector of argc + 1 elements. - ACE_NEW_RETURN (argv, - ACE_TCHAR *[argc + 1], - -1); - - ACE_TCHAR *ptr = buf; - - for (int i = 0; i < argc; i++) - { - // Skip whitespace.. - while (ACE_OS::ace_isspace (*ptr)) - ptr++; - - // Copy next argument and move to next whitespace.. - cp = argp; - while (*ptr != ACE_LIB_TEXT ('\0') && !ACE_OS::ace_isspace (*ptr)) - if (*ptr == ACE_LIB_TEXT ('\'') || *ptr == ACE_LIB_TEXT ('"')) - { - ACE_TCHAR quote = *ptr++; - - while (*ptr != ACE_LIB_TEXT ('\0') && *ptr != quote) - *cp++ = *ptr++; - - if (*ptr == quote) - ptr++; - } - else - *cp++ = *ptr++; - - *cp = ACE_LIB_TEXT ('\0'); - -#if !defined (ACE_LACKS_ENV) - // Check for environment variable substitution here. - if (substitute_env_args) { - argv[i] = ACE_OS::strenvdup(argp); - - if (argv[i] == 0) - { - if (argp != arg) - delete [] argp; - errno = ENOMEM; - return -1; - } - } - else -#endif /* ACE_LACKS_ENV */ - { - argv[i] = ACE_OS::strdup(argp); - - if (argv[i] == 0) - { - if (argp != arg) - delete [] argp; - errno = ENOMEM; - return -1; - } - } - } - - if (argp != arg) - delete [] argp; - - argv[argc] = 0; - return 0; -} - // Write <len> bytes from <buf> to <handle> (uses the <write> // system call on UNIX and the <WriteFile> call on Win32). @@ -773,4 +647,3 @@ ACE_OS::write_n (ACE_HANDLE handle, return bytes_transferred; } -ACE_END_VERSIONED_NAMESPACE_DECL |