Skip to content

Commit

Permalink
Implement get_own_executable_path for SunOS (dotnet#36514)
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 authored May 15, 2020
1 parent f758569 commit c96b6a8
Showing 1 changed file with 34 additions and 1 deletion.
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);
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

0 comments on commit c96b6a8

Please sign in to comment.