MCPcopy Create free account
hub / github.com/acl-dev/acl / get_cwd

Method get_cwd

lib_acl_cpp/src/stdlib/scan_dir.cpp:244–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

242}
243
244bool 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;

Callers

nothing calls this directly

Calls 1

last_serrorFunction · 0.70

Tested by

no test coverage detected