-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauxlib.cpp
More file actions
63 lines (54 loc) · 1.43 KB
/
auxlib.cpp
File metadata and controls
63 lines (54 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <cassert>
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
using namespace std;
#include "auxlib.h"
string exec::name_;
int exec::status_ = EXIT_SUCCESS;
void exec::name (const char* argv0) {
name_ = basename (argv0);
cout << boolalpha;
cerr << boolalpha;
}
const string& exec::name() {
assert (exec::name_ != "");
return name_;
}
void exec::status (int status) {
assert (exec::name_ != "");
if (status_ < status) status_ = status;
}
ostream& exec::error() {
assert (exec::name_ != "");
exec::status (EXIT_FAILURE);
return cerr << exec::name() << ": ";
}
fatal_error::fatal_error (const string& what): runtime_error (what) {
exec::status (EXIT_FAILURE);
}
ostream& operator<< (ostream& out, wait_status wait) {
int status = wait.status;
if (WIFSIGNALED (status)) {
out << "Terminated: " << strsignal (WTERMSIG (status));
#ifdef WCOREDUMP
if (WCOREDUMP (status)) out << " (core dumped)";
#endif
return out;
}
if (WIFEXITED (status)) {
return out << "Exit " << WEXITSTATUS (status);
}
if (WIFSTOPPED (status)) {
return out << "Stopped: " << strsignal (WSTOPSIG (status));
}
if (WIFCONTINUED (status)) {
return out << "Continued";
}
return out << "Unknown status {"
<< (status >> 8 & 0xFF) << ","
<< (status >> 7 & 1) << ","
<< (status & 0x7F) << "}";
}