Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions elisp/private/tools/system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,19 +493,17 @@ absl::StatusOr<NativeString> ToNative(

#ifndef _WIN32
static absl::StatusOr<FileName> WorkingDirectory() {
struct Free {
void operator()(char* const absl_nonnull p) const { std::free(p); }
};
// Assume that we always run on an OS that allocates a buffer when passed a
// null pointer.
const absl_nullable std::unique_ptr<char, Free> ptr(getcwd(nullptr, 0));
char* const absl_nullable ptr = getcwd(nullptr, 0);
if (ptr == nullptr) return ErrnoStatus("getcwd", nullptr, 0);
const absl::Cleanup cleanup = [ptr] { std::free(ptr); };
// See the Linux man page for getcwd(3) why this can happen.
if (*ptr != '/') {
return absl::NotFoundError(absl::StrCat("Current working directory ",
ptr.get(), " is unreachable"));
return absl::NotFoundError(
absl::StrFormat("Current working directory %s is unreachable", ptr));
}
return FileName::FromString(ptr.get());
return FileName::FromString(ptr);
}
#endif

Expand Down