| 1155 | } |
| 1156 | |
| 1157 | String Utility::FormatErrorNumber(int code) { |
| 1158 | std::ostringstream msgbuf; |
| 1159 | |
| 1160 | #ifdef _WIN32 |
| 1161 | char *message; |
| 1162 | String result = "Unknown error."; |
| 1163 | |
| 1164 | DWORD rc = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 1165 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, code, 0, (char *)&message, |
| 1166 | 0, nullptr); |
| 1167 | |
| 1168 | if (rc != 0) { |
| 1169 | result = String(message); |
| 1170 | LocalFree(message); |
| 1171 | |
| 1172 | /* remove trailing new-line characters */ |
| 1173 | boost::algorithm::trim_right(result); |
| 1174 | } |
| 1175 | |
| 1176 | msgbuf << code << ", \"" << result << "\""; |
| 1177 | #else |
| 1178 | msgbuf << strerror(code); |
| 1179 | #endif |
| 1180 | return msgbuf.str(); |
| 1181 | } |
| 1182 | |
| 1183 | String Utility::EscapeShellCmd(const String& s) |
| 1184 | { |