MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / Dirname

Function Dirname

Bcore/src/main/cpp/android-base/file.cpp:319–342  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

317}
318
319std::string Dirname(const std::string& path) {
320 // Copy path because dirname may modify the string passed in.
321 std::string result(path);
322
323#if !defined(__BIONIC__)
324 // Use lock because dirname() may write to a process global and return a
325 // pointer to that. Note that this locking strategy only works if all other
326 // callers to dirname in the process also grab this same lock, but its
327 // better than nothing. Bionic's dirname returns a thread-local buffer.
328 static std::mutex& dirname_lock = *new std::mutex();
329 std::lock_guard<std::mutex> lock(dirname_lock);
330#endif
331
332 // Note that if std::string uses copy-on-write strings, &str[0] will cause
333 // the copy to be made, so there is no chance of us accidentally writing to
334 // the storage for 'path'.
335 char* parent = dirname(&result[0]);
336
337 // In case dirname returned a pointer to a process global, copy that string
338 // before leaving the lock.
339 result.assign(parent);
340
341 return result;
342}
343
344} // namespace base
345} // namespace android_lkchan

Callers 1

GetExecutableDirectoryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected