42 if(stat(process.c_str(), &sts) == -1 && errno == ENOENT)
50 char* cargs[args.size()+2];
51 cargs[0] = (
char*)process.c_str();
52 for(
uint i=1;i<=args.size();++i)
53 cargs[i] = (
char*)args[i-1].c_str();
54 cargs[args.size()+1] =
nullptr;
56 if(execv(process.c_str(), cargs) == -1)
87 if(getcwd(cwd,
sizeof(cwd)) !=
nullptr) {
96 return system(
stdext::format(
"/bin/cp '%s' '%s'", from, to).c_str()) == 0;
102 return (stat(file.c_str(), &buffer) == 0);
107 if(unlink(file.c_str()) == 0)
115 if(stat(file.c_str(), &attrib) == 0)
116 return attrib.st_mtime;
122 if(url.find(
"http://") == std::string::npos)
123 url.insert(0,
"http://");
130 std::ifstream in(
"/proc/cpuinfo");
131 while(getline(in, line)) {
133 std::string first = strs[0];
134 std::string second = strs[1];
137 if(strs.size() == 2 && first ==
"model name")
140 return std::string();
146 std::ifstream in(
"/proc/meminfo");
147 while(getline(in, line)) {
149 std::string first = strs[0];
150 std::string second = strs[1];
153 if(strs.size() == 2 && first ==
"MemTotal")
154 return stdext::unsafe_cast<double>(second.substr(0, second.length() - 3)) * 1000.0;
162 std::ifstream in(
"/etc/issue");
163 if(getline(in, line)) {
164 std::size_t end = line.find(
'\\');
165 std::string res = line.substr(0, end);
169 return std::string();
174 std::stringstream ss;
176 ss <<
"\nC++ stack traceback:";
178 ss <<
"\n\t[C++]: " << where;
180 void* buffer[maxDepth + level + 1];
181 int numLevels = backtrace(buffer, maxDepth + level + 1);
182 char **tracebackBuffer = backtrace_symbols(buffer, numLevels);
183 if(tracebackBuffer) {
184 for(
int i = 1 + level; i < numLevels; i++) {
185 std::string line = tracebackBuffer[i];
186 if(line.find(
"__libc_start_main") != std::string::npos)
188 std::size_t demanglePos = line.find(
"(_Z");
189 if(demanglePos != std::string::npos) {
191 int len = std::min(line.find_first_of(
"+", demanglePos), line.find_first_of(
")", demanglePos)) - demanglePos;
192 std::string funcName = line.substr(demanglePos, len);
195 ss <<
"\n\t" << line;
197 free(tracebackBuffer);