MCPcopy Create free account
hub / github.com/apache/arrow / ResolveCurrentExecutable

Method ResolveCurrentExecutable

cpp/src/arrow/testing/process.cc:275–309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

273
274#ifdef BOOST_PROCESS_AVAILABLE
275 Result<filesystem::path> ResolveCurrentExecutable() {
276 // See https://stackoverflow.com/a/1024937/10194 for various
277 // platform-specific recipes.
278
279 filesystem::path path;
280 boost::system::error_code error_code;
281
282# if defined(__linux__)
283 path = filesystem::canonical("/proc/self/exe", error_code);
284# elif defined(__FreeBSD__)
285 path = filesystem::canonical("/proc/curproc/file", error_code);
286# elif defined(__APPLE__)
287 char buf[PATH_MAX + 1];
288 uint32_t bufsize = sizeof(buf);
289 if (_NSGetExecutablePath(buf, &bufsize) < 0) {
290 return Status::Invalid("Can't resolve current exe: path too large");
291 }
292 path = filesystem::canonical(buf, error_code);
293# elif defined(_WIN32)
294 char buf[MAX_PATH + 1];
295 if (!GetModuleFileNameA(NULL, buf, sizeof(buf))) {
296 return Status::Invalid("Can't get executable file path");
297 }
298 path = filesystem::canonical(buf, error_code);
299# else
300 ARROW_UNUSED(error_code);
301 return Status::NotImplemented("Not available on this system");
302# endif
303 if (error_code) {
304 // XXX fold this into the Status class?
305 return Status::IOError("Can't resolve current exe: ", error_code.message());
306 } else {
307 return path;
308 }
309 }
310
311# ifdef BOOST_PROCESS_USE_V2
312 Status ExecuteV2() {

Callers

nothing calls this directly

Calls 3

IOErrorFunction · 0.85
InvalidFunction · 0.50
NotImplementedFunction · 0.50

Tested by

no test coverage detected