Skip to content

Commit

Permalink
Add helper to get exit status of command
Browse files Browse the repository at this point in the history
  • Loading branch information
AGWA committed Feb 7, 2015
1 parent c850d65 commit fc583c7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions util-unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ int exec_command_with_input (const std::vector<std::string>& command, const char
return status;
}

bool successful_exit (int status)
int exit_status (int wait_status)
{
return status != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0;
return wait_status != -1 && WIFEXITED(wait_status) ? WEXITSTATUS(wait_status) : -1;
}

void touch_file (const std::string& filename)
Expand Down
4 changes: 2 additions & 2 deletions util-win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ int exec_command_with_input (const std::vector<std::string>& command, const char
return exit_code;
}

bool successful_exit (int status)
int exit_status (int status)
{
return status == 0;
return status;
}

void touch_file (const std::string& filename)
Expand Down
3 changes: 2 additions & 1 deletion util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ std::string our_exe_path ();
int exec_command (const std::vector<std::string>&);
int exec_command (const std::vector<std::string>&, std::ostream& output);
int exec_command_with_input (const std::vector<std::string>&, const char* p, size_t len);
bool successful_exit (int status);
int exit_status (int wait_status); // returns -1 if process did not exit (but was signaled, etc.)
inline bool successful_exit (int wait_status) { return exit_status(wait_status) == 0; }
void touch_file (const std::string&);
void remove_file (const std::string&);
std::string escape_shell_arg (const std::string&);
Expand Down

0 comments on commit fc583c7

Please sign in to comment.