MCPcopy Create free account
hub / github.com/CppMicroServices/CppMicroServices / InitCurrentWorkingDirectory

Function InitCurrentWorkingDirectory

util/src/FileSystem.cpp:170–205  ·  view source on GitHub ↗

no reason to export this function... only used to initialize static local variable in GetCurrentWorkingDirectory.

Source from the content-addressed store, hash-verified

168 // no reason to export this function... only used to initialize static local variable in
169 // GetCurrentWorkingDirectory.
170 std::string
171 InitCurrentWorkingDirectory()
172 {
173#ifdef US_PLATFORM_WINDOWS
174 DWORD bufSize = ::GetCurrentDirectoryW(0, NULL);
175 if (bufSize == 0)
176 {
177 bufSize = 1;
178 }
179 std::vector<wchar_t> buf(bufSize, L'\0');
180 if (::GetCurrentDirectoryW(bufSize, buf.data()) != 0)
181 {
182 return util::ToUTF8String(buf.data());
183 }
184#else
185 errno = 0; // reset errno to zero in case it was set to some other
186 // value before this call.
187 for (std::size_t bufSize = PATH_MAX;
188 (0 == errno) || (ERANGE == errno); // break out of the loop if any error other than
189 // ERANGE occurs. In the case of ERANGE, we
190 // double the bufSize and try again.
191 bufSize
192 *= 2)
193 {
194 std::vector<char> buf(bufSize, '\0');
195 char const* rval = getcwd(buf.data(), bufSize);
196 if (rval != nullptr)
197 {
198 // if we get here, getcwd returned non-null and therefore rval points to the correct
199 // results. Return those results.
200 return std::string(rval);
201 }
202 }
203#endif
204 return std::string();
205 }
206 const std::string s_CurrentWorkingDir = InitCurrentWorkingDirectory();
207
208 } // anonymous namespace

Callers 1

FileSystem.cppFile · 0.85

Calls 1

ToUTF8StringFunction · 0.85

Tested by

no test coverage detected