MCPcopy Create free account
hub / github.com/catboost/catboost / GetExecPathImpl

Function GetExecPathImpl

util/system/execpath.cpp:94–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92#endif
93
94static TString GetExecPathImpl() {
95#if defined(_solaris_)
96 return execname();
97#elif defined(_darwin_)
98 TTempBuf execNameBuf;
99 for (size_t i = 0; i < 2; ++i) {
100 std::remove_pointer_t<TFunctionArg<decltype(_NSGetExecutablePath), 1>> bufsize = execNameBuf.Size();
101 int r = _NSGetExecutablePath(execNameBuf.Data(), &bufsize);
102 if (r == 0) {
103 return execNameBuf.Data();
104 } else if (r == -1) {
105 execNameBuf = TTempBuf(bufsize);
106 }
107 }
108 ythrow yexception() << "GetExecPathImpl() failed";
109#elif defined(_win_)
110 TTempBuf execNameBuf;
111 for (;;) {
112 DWORD r = GetModuleFileName(nullptr, execNameBuf.Data(), execNameBuf.Size());
113 if (r == execNameBuf.Size()) {
114 execNameBuf = TTempBuf(execNameBuf.Size() * 2);
115 } else if (r == 0) {
116 ythrow yexception() << "GetExecPathImpl() failed: " << LastSystemErrorText();
117 } else {
118 return execNameBuf.Data();
119 }
120 }
121#elif defined(_linux_) || defined(_cygwin_)
122 TString path("/proc/self/exe");
123 return NFs::ReadLink(path);
124// TODO(yoda): check if the filename ends with " (deleted)"
125#elif defined(_freebsd_)
126 TString execPath = FreeBSDGetExecPath();
127 if (GoodPath(execPath)) {
128 return execPath;
129 }
130 if (FreeBSDGuessExecPath(FreeBSDGetArgv0(), execPath)) {
131 return execPath;
132 }
133 if (FreeBSDGuessExecPath(getenv("_"), execPath)) {
134 return execPath;
135 }
136 if (FreeBSDGuessExecBasePath(getenv("PWD"), execPath)) {
137 return execPath;
138 }
139 if (FreeBSDGuessExecBasePath(NFs::CurrentWorkingDirectory(), execPath)) {
140 return execPath;
141 }
142
143 ythrow yexception() << "can not resolve exec path";
144#else
145 #error dont know how to implement GetExecPath on this platform
146#endif
147}
148
149static bool GetPersistentExecPathImpl(TString& to) {
150#if defined(_solaris_)

Callers 1

TExecPathsHolderMethod · 0.85

Calls 9

TTempBufClass · 0.85
FreeBSDGetExecPathFunction · 0.85
GoodPathFunction · 0.85
FreeBSDGuessExecPathFunction · 0.85
FreeBSDGetArgv0Function · 0.85
FreeBSDGuessExecBasePathFunction · 0.85
LastSystemErrorTextFunction · 0.70
SizeMethod · 0.45
DataMethod · 0.45

Tested by

no test coverage detected