MCPcopy Create free account
hub / github.com/ddnet/ddnet / FindBinaryDirectory

Method FindBinaryDirectory

src/engine/shared/storage.cpp:362–402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

360 }
361
362 void FindBinaryDirectory(const char *pArgv0)
363 {
364#if defined(BINARY_DIR)
365 str_copy(m_aBinarydir, BINARY_DIR, sizeof(m_aBinarydir));
366 return;
367#endif
368
369 if(fs_executable_path(m_aBinarydir, sizeof(m_aBinarydir)) == 0)
370 {
371 fs_parent_dir(m_aBinarydir);
372 return;
373 }
374
375 // check for usable path in argv[0]
376 {
377 unsigned int Pos = ~0U;
378 for(unsigned i = 0; pArgv0[i]; i++)
379 if(pArgv0[i] == '/' || pArgv0[i] == '\\')
380 Pos = i;
381
382 if(Pos < IO_MAX_PATH_LENGTH)
383 {
384 char aBuf[IO_MAX_PATH_LENGTH];
385 str_copy(m_aBinarydir, pArgv0, Pos + 1);
386 str_format(aBuf, sizeof(aBuf), "%s/" PLAT_SERVER_EXEC, m_aBinarydir);
387 if(fs_is_file(aBuf))
388 {
389 return;
390 }
391 // Also look for client binary. (see https://github.com/ddnet/ddnet/issues/11418)
392 str_format(aBuf, sizeof(aBuf), "%s/" PLAT_CLIENT_EXEC, m_aBinarydir);
393 if(fs_is_file(aBuf))
394 {
395 return;
396 }
397 }
398 }
399
400 // no binary directory found, use $PATH on Posix, $PWD on Windows
401 m_aBinarydir[0] = '\0';
402 }
403
404 int NumPaths() const override
405 {

Callers

nothing calls this directly

Calls 5

fs_executable_pathFunction · 0.85
fs_parent_dirFunction · 0.85
str_formatFunction · 0.85
fs_is_fileFunction · 0.85
str_copyFunction · 0.50

Tested by

no test coverage detected