Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement get_own_executable_path for SunOS #36514

Merged
merged 1 commit into from
May 15, 2020
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
35 changes: 34 additions & 1 deletion src/installer/corehost/cli/hostmisc/pal.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
#define DT_LNK 10
#endif

#ifdef __linux__
#define PAL_CWD_SIZE 0
#elif defined(MAXPATHLEN)
#define PAL_CWD_SIZE MAXPATHLEN
#elif defined(PATH_MAX)
#define PAL_CWD_SIZE PATH_MAX
#else
#error "Don't know how to obtain max path on this platform"
#endif

pal::string_t pal::to_lower(const pal::string_t& in)
{
pal::string_t ret = in;
Expand Down Expand Up @@ -118,7 +128,7 @@ void* pal::mmap_copy_on_write(const string_t& path, size_t* length)
bool pal::getcwd(pal::string_t* recv)
{
recv->clear();
pal::char_t* buf = ::getcwd(nullptr, 0);
pal::char_t* buf = ::getcwd(nullptr, PAL_CWD_SIZE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity I've tested the getcwd(NULL, 0) on macOS and it works fine, despite the doc saying something else. But since it is an undocumented behavior, changing it for macOS too makes sense.

if (buf == nullptr)
{
if (errno == ENOENT)
Expand All @@ -129,6 +139,7 @@ bool pal::getcwd(pal::string_t* recv)
trace::error(_X("getcwd() failed: %s"), strerror(errno));
return false;
}

recv->assign(buf);
::free(buf);
return true;
Expand Down Expand Up @@ -768,6 +779,28 @@ bool pal::get_own_executable_path(pal::string_t* recv)
}
return false;
}
#elif defined(__sun)
bool pal::get_own_executable_path(pal::string_t* recv)
{
const char *path;
if ((path = getexecname()) == NULL)
{
return false;
}
else if (*path != '/')
{
if (!getcwd(recv))
{
return false;
}

recv->append("/").append(path);
return true;
}

recv->assign(path);
return true;
}
#else
bool pal::get_own_executable_path(pal::string_t* recv)
{
Expand Down