Make `cuttlefish::CurrentDirectory()` safe to run in deleted directories.
Before this would trigger a segmentation fault as `getcwd()` can return
NULL.
Test: m -j
Bug: 228294703
Change-Id: I13d60a981d5abcaf75a5e47ccc8e747df7afd5be
diff --git a/common/libs/utils/files.cpp b/common/libs/utils/files.cpp
index 71475d2..c1b1778 100644
--- a/common/libs/utils/files.cpp
+++ b/common/libs/utils/files.cpp
@@ -225,6 +225,10 @@
std::string CurrentDirectory() {
char* path = getcwd(nullptr, 0);
+ if (path == nullptr) {
+ PLOG(ERROR) << "`getcwd(nullptr, 0)` failed";
+ return "";
+ }
std::string ret(path);
free(path);
return ret;