Update libtest
[m6w6/libmemcached] / libtest / cmdline.cc
index b03b60d861c8c56f26acb266724eb17bc0a7cba3..1233f5140f02f2a6f6c274eae1c7382249bdd0c3 100644 (file)
@@ -84,7 +84,7 @@ namespace {
   {
     std::stringstream arg_buffer;
 
-    for (size_t x= 0; x < argc; x++)
+    for (size_t x= 0; x < argc; ++x)
     {
       arg_buffer << built_argv[x] << " ";
     }
@@ -96,7 +96,7 @@ namespace {
   {
     std::stringstream arg_buffer;
 
-    for (char** ptr= argv; *ptr; ptr++)
+    for (char** ptr= argv; *ptr; ++ptr)
     {
       arg_buffer << *ptr << " ";
     }
@@ -183,9 +183,9 @@ Application::error_t Application::run(const char *args[])
   posix_spawn_file_actions_t file_actions;
   posix_spawn_file_actions_init(&file_actions);
 
-  stdin_fd.dup_for_spawn(Application::Pipe::READ, file_actions);
-  stdout_fd.dup_for_spawn(Application::Pipe::WRITE, file_actions);
-  stderr_fd.dup_for_spawn(Application::Pipe::WRITE, file_actions);
+  stdin_fd.dup_for_spawn(file_actions);
+  stdout_fd.dup_for_spawn(file_actions);
+  stderr_fd.dup_for_spawn(file_actions);
 
   posix_spawnattr_t spawnattr;
   posix_spawnattr_init(&spawnattr);
@@ -526,7 +526,7 @@ bool Application::Pipe::read(libtest::vchar_t& arg)
 
     data_was_read= true;
     arg.reserve(read_length +1);
-    for (size_t x= 0; x < read_length; x++)
+    for (size_t x= 0; x < read_length; ++x)
     {
       arg.push_back(buffer[x]);
     }
@@ -593,13 +593,20 @@ void Application::Pipe::cloexec()
 
 Application::Pipe::~Pipe()
 {
-  close(READ);
-  close(WRITE);
+  if (_pipe_fd[0] != -1)
+  {
+    ::close(_pipe_fd[0]);
+  }
+
+  if (_pipe_fd[1] != -1)
+  {
+    ::close(_pipe_fd[1]);
+  }
 }
 
-void Application::Pipe::dup_for_spawn(const close_t& arg, posix_spawn_file_actions_t& file_actions)
+void Application::Pipe::dup_for_spawn(posix_spawn_file_actions_t& file_actions)
 {
-  int type= int(arg);
+  int type= STDIN_FILENO == _std_fd ? 0 : 1;
 
   int ret;
   if ((ret= posix_spawn_file_actions_adddup2(&file_actions, _pipe_fd[type], _std_fd )) < 0)
@@ -621,7 +628,6 @@ void Application::Pipe::close(const close_t& arg)
 
   if (_open[type])
   {
-    int ret;
     if (::close(_pipe_fd[type]) == -1)
     {
       Error << "close(" << strerror(errno) << ")";
@@ -662,7 +668,7 @@ void Application::create_argv(const char *args[])
     _argc+= 1;
   }
 
-  for (Options::const_iterator iter= _options.begin(); iter != _options.end(); iter++)
+  for (Options::const_iterator iter= _options.begin(); iter != _options.end(); ++iter)
   {
     _argc++;
     if ((*iter).second.empty() == false)
@@ -764,9 +770,9 @@ std::string Application::arguments()
 {
   std::stringstream arg_buffer;
 
-  for (size_t x= 1 + _use_libtool ? 2 : 0;
+  for (size_t x= (1 +_use_libtool) ? 2 : 0;
        x < _argc and built_argv[x];
-       x++)
+       ++x)
   {
     arg_buffer << built_argv[x] << " ";
   }
@@ -778,7 +784,7 @@ void Application::delete_argv()
 {
   if (built_argv)
   {
-    for (size_t x= 0; x < _argc; x++)
+    for (size_t x= 0; x < _argc; ++x)
     {
       if (built_argv[x])
       {