Subversion Repositories Games.Chess Giants

Rev

Rev 174 | Rev 177 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 174 Rev 175
Line 57... Line 57...
57
   else if (wcschr (command_pathname, L' ') != NULL)
57
   else if (wcschr (command_pathname, L' ') != NULL)
58
      *wcschr (command_pathname, L' ') = 0;
58
      *wcschr (command_pathname, L' ') = 0;
59
 
59
 
60
   // build the bidirectional I/O pipe
60
   // build the bidirectional I/O pipe
61
   pipe = (pipe_t *) malloc (sizeof (pipe_t));
61
   pipe = (pipe_t *) malloc (sizeof (pipe_t));
-
 
62
   memset (pipe, 0, sizeof (pipe_t));
62
   memset (&security_attributes, 0, sizeof (security_attributes)); // prepare the pipes' security attributes
63
   memset (&security_attributes, 0, sizeof (security_attributes)); // prepare the pipes' security attributes
63
   security_attributes.nLength = sizeof (SECURITY_ATTRIBUTES);
64
   security_attributes.nLength = sizeof (SECURITY_ATTRIBUTES);
64
   security_attributes.bInheritHandle = true; // set the bInheritHandle flag so pipe handles are inherited
65
   security_attributes.bInheritHandle = true; // set the bInheritHandle flag so pipe handles are inherited
65
   hStdIO[0][0] = hStdIO[0][1] = hStdIO[1][0] = hStdIO[1][1] = NULL;
66
   hStdIO[0][0] = hStdIO[0][1] = hStdIO[1][0] = hStdIO[1][1] = NULL;
66
   CreatePipe (&hStdIO[ME_TO_IT][RD], &hStdIO[ME_TO_IT][WR], &security_attributes, 0); // create a pipe for the child process's stdin
67
   CreatePipe (&hStdIO[ME_TO_IT][RD], &hStdIO[ME_TO_IT][WR], &security_attributes, 0); // create a pipe for the child process's stdin
Line 157... Line 158...
157
{
158
{
158
   // wrapper around ioctl() on pipes for systems that don't have it
159
   // wrapper around ioctl() on pipes for systems that don't have it
159
 
160
 
160
#ifdef _WIN32
161
#ifdef _WIN32
161
   DWORD exit_code;
162
   DWORD exit_code;
-
 
163
   DWORD handle_flags;
-
 
164
   if (((pipe_t *) stream)->procinfo.hProcess == 0)
-
 
165
      return (1); // if the child process has not been fully started yet, assume the pipe is still alive
-
 
166
   else if (((pipe_t *) stream)->procinfo.hProcess == INVALID_HANDLE_VALUE)
-
 
167
      return (0); // if the child process handle has been explicitly marked invalid, assume it's already dead
-
 
168
   else if (GetHandleInformation (((pipe_t *) stream)->procinfo.hProcess, &handle_flags) == 0)
-
 
169
   {
-
 
170
      ((pipe_t *) stream)->procinfo.hProcess = INVALID_HANDLE_VALUE;
-
 
171
      return (0); // if the process handle is no longer valid but its handle is not marked as such, assume the child is dead
-
 
172
   }
162
   return (GetExitCodeProcess (((pipe_t *) stream)->procinfo.hProcess, &exit_code) && (exit_code == STILL_ACTIVE));
173
   else if (GetExitCodeProcess (((pipe_t *) stream)->procinfo.hProcess, &exit_code) == 0)
-
 
174
      return (1); // if GetExitCodeProcess() failed, *conservatively* assume the child is still alive
-
 
175
   return (exit_code == STILL_ACTIVE);
163
#else // !_WIN32
176
#else // !_WIN32
164
   return (1); // UNIX doesn't provide a portable way for this
177
   return (1); // UNIX doesn't provide a portable way for this
165
#endif // _WIN32
178
#endif // _WIN32
166
}
179
}
167
 
180