diff options
-rw-r--r-- | ChangeLog-99b | 13 | ||||
-rw-r--r-- | ace/ARGV.cpp | 52 | ||||
-rw-r--r-- | ace/OS.cpp | 77 | ||||
-rw-r--r-- | ace/OS.h | 3 |
4 files changed, 81 insertions, 64 deletions
diff --git a/ChangeLog-99b b/ChangeLog-99b index 371bc3f7b19..be5f5035c4a 100644 --- a/ChangeLog-99b +++ b/ChangeLog-99b @@ -5,16 +5,17 @@ Thu Feb 18 21:10:45 1999 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu> ACE_OS::strenvdup(). * ace/ACE.cpp: Implemented ACE::strenvdup() using - ACE_OS::strenvdup(). + ACE_OS::strenvdup(). * ace/OS: Move the implementation of strenvdup() from ACE to - ACE_OS to remove another dependency from the OS wrappers. + ACE_OS to remove another dependency from the OS wrappers. - * ace/ARGV.cpp (string_to_argv): Rewrote this method to use the - new ACE_OS::string_to_argv(). + * ace/ARGV.cpp: Rewrote the ACE_ARGV::string_to_argv() and + ACE_ARGV::argv_to_string() methods to use the new + ACE_OS::string_to_argv() and ACE_OS::argv_to_string(). - * ace/OS.h: Added a string_to_argv() method to ACE_OS to remove - the dependency on ACE_ARGV. + * ace/OS.h: Added string_to_argv() and argv_to_string() methods to + ACE_OS to remove the dependency on ACE_ARGV. Thu Feb 18 19:21:03 1999 James CE Johnson <jcej@chiroptera.tragus.org> diff --git a/ace/ARGV.cpp b/ace/ARGV.cpp index 43b8535bcf8..73460c87b44 100644 --- a/ace/ARGV.cpp +++ b/ace/ARGV.cpp @@ -49,57 +49,7 @@ ACE_ARGV::string_to_argv (void) int ACE_ARGV::argv_to_string (ASYS_TCHAR **argv, ASYS_TCHAR *&buf) { - if (argv == 0 || argv[0] == 0) - return 0; - - int buf_len = 0; - - // Determine the length of the buffer. - - for (int i = 0; argv[i] != 0; i++) - { - ASYS_TCHAR *temp; - - // Account for environment variables. - if (this->substitute_env_args_ - && (argv[i][0] == '$' - && (temp = ACE_OS::getenv (&argv[i][1])) != 0)) - buf_len += ACE_OS::strlen (temp); - else - buf_len += ACE_OS::strlen (argv[i]); - - // Add one for the extra space between each string. - buf_len++; - } - - // Step through all argv params and copy each one into buf; separate - // each param with white space. - - ACE_NEW_RETURN (buf, ASYS_TCHAR[buf_len + 1],0); - - // initial null charater to make it a null string. - buf[0] = '\0'; - ASYS_TCHAR *end = buf; - int j; - - for (j = 0; argv[j] != 0; j++) - { - ASYS_TCHAR *temp; - - // Account for environment variables. - if (this->substitute_env_args_ - && (argv[j][0] == '$' - && (temp = ACE_OS::getenv (&argv[j][1])) != 0)) - end = ACE::strecpy (end, temp); - else - end = ACE::strecpy (end, argv[j]); - - // Replace the null char that strecpy put there with white space. - *(end-1) = ' '; - } - // Null terminate the string. - *end = '\0'; - return j;// the number of arguments. + return ACE_OS::argv_to_string (argv, buf); } ACE_ARGV::ACE_ARGV (const ASYS_TCHAR buf[], diff --git a/ace/OS.cpp b/ace/OS.cpp index e5040bc759d..3e4a44e99a2 100644 --- a/ace/OS.cpp +++ b/ace/OS.cpp @@ -3487,6 +3487,69 @@ ACE_OS::thr_key_detach (void *inst) } int +ACE_OS::argv_to_string (ASYS_TCHAR **argv, + ASYS_TCHAR *&buf, + int substitute_env_args) +{ + if (argv == 0 || argv[0] == 0) + return 0; + + int buf_len = 0; + + // Determine the length of the buffer. + + for (int i = 0; argv[i] != 0; i++) + { + ASYS_TCHAR *temp; + + // Account for environment variables. + if (substitute_env_args + && (argv[i][0] == '$' + && (temp = ACE_OS::getenv (&argv[i][1])) != 0)) + buf_len += ACE_OS::strlen (temp); + else + buf_len += ACE_OS::strlen (argv[i]); + + // Add one for the extra space between each string. + buf_len++; + } + + // Step through all argv params and copy each one into buf; separate + // each param with white space. + + ACE_NEW_RETURN (buf, + ASYS_TCHAR[buf_len + 1], + 0); + + // Initial null charater to make it a null string. + buf[0] = '\0'; + ASYS_TCHAR *end = buf; + int j; + + for (j = 0; argv[j] != 0; j++) + { + ASYS_TCHAR *temp; + + // Account for environment variables. + if (substitute_env_args + && (argv[j][0] == '$' + && (temp = ACE_OS::getenv (&argv[j][1])) != 0)) + end = ACE::strecpy (end, temp); + else + end = ACE::strecpy (end, argv[j]); + + // Replace the null char that strecpy put there with white + // space. + end[-1] = ' '; + } + + // Null terminate the string. + *end = '\0'; + // The number of arguments. + return j; +} + +int ACE_OS::string_to_argv (ASYS_TCHAR *buf, size_t &argc, ASYS_TCHAR **&argv, @@ -3621,9 +3684,9 @@ pid_t ACE_OS::fork_exec (ASYS_TCHAR *argv[]) { # if defined (ACE_WIN32) - ACE_TCHAR *buf = ACE_OS::string_to_argv (argv); + ASYS_TCHAR *buf; - if (buf != 0) + if (ACE_OS::argv_to_string (argv, buf) != -1) { PROCESS_INFORMATION process_info; # if !defined (ACE_HAS_WINCE) @@ -3638,8 +3701,7 @@ ACE_OS::fork_exec (ASYS_TCHAR *argv[]) 0, // No process attributes. 0, // No thread attributes. TRUE, // Allow handle inheritance. - 0, /* CREATE_NEW_CONSOLE */ - // Don't create a new console window. + 0, // Don't create a new console window. 0, // No environment. 0, // No current directory. &startup_info, @@ -3650,8 +3712,7 @@ ACE_OS::fork_exec (ASYS_TCHAR *argv[]) 0, // No process attributes. 0, // No thread attributes. FALSE, // Can's inherit handles on CE - 0, /* CREATE_NEW_CONSOLE */ - // Don't create a new console window. + 0, // Don't create a new console window. 0, // No environment. 0, // No current directory. 0, // Can't use startup info on CE @@ -3662,6 +3723,7 @@ ACE_OS::fork_exec (ASYS_TCHAR *argv[]) ACE_OS::close (process_info.hThread); ACE_OS::close (process_info.hProcess); // Return new process id. + delete [] buf; return process_info.dwProcessId; } } @@ -3682,7 +3744,8 @@ ACE_OS::fork_exec (ASYS_TCHAR *argv[]) // Child process. if (ACE_OS::execv (argv[0], argv) == -1) { - ACE_ERROR ((LM_ERROR, "%p Exec failed\n")); + ACE_ERROR ((LM_ERROR, + "%p Exec failed\n")); // If the execv fails, this child needs to exit. ACE_OS::exit (errno); @@ -4459,6 +4459,9 @@ public: static int getopt (int argc, char *const *argv, const char *optstring); + static int argv_to_string (ASYS_TCHAR **argv, + ASYS_TCHAR *&buf, + int substitute_env_args = 1); static int string_to_argv (ASYS_TCHAR *buf, size_t &argc, ASYS_TCHAR **&argv, |