| 242 | } |
| 243 | |
| 244 | bool scan_dir::get_cwd(string& out) |
| 245 | { |
| 246 | |
| 247 | #ifndef MAX_PATH |
| 248 | #define MAX_PATH 1024 |
| 249 | #endif |
| 250 | char buf[MAX_PATH]; |
| 251 | |
| 252 | #ifdef ACL_WINDOWS |
| 253 | if (::GetCurrentDirectory(MAX_PATH, buf) == 0) { |
| 254 | logger_error("can't get process path: %s", last_serror()); |
| 255 | return false; |
| 256 | } |
| 257 | #else |
| 258 | if (::getcwd(buf, sizeof(buf)) == NULL) { |
| 259 | logger_error("can't get process path: %s", last_serror()); |
| 260 | return false; |
| 261 | } |
| 262 | #endif // ACL_WINDOWS |
| 263 | |
| 264 | // xxx: can this happen ? |
| 265 | if (buf[0] == 0) { |
| 266 | return false; |
| 267 | } |
| 268 | |
| 269 | // ȥ��β���� '/' |
| 270 | char* end = buf + strlen(buf) - 1; |
| 271 | while (end > buf) { |
| 272 | #ifdef ACL_WINDOWS |
| 273 | if (*end == '/' || *end == '\\') { |
| 274 | end--; |
| 275 | } |
| 276 | #else |
| 277 | if (*end == '/') { |
| 278 | end--; |
| 279 | } |
| 280 | #endif |
| 281 | else { |
| 282 | break; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | out = buf; |
| 287 | return true; |
nothing calls this directly
no test coverage detected