diff options
author | Ed Maste <emaste@FreeBSD.org> | 2015-07-03 16:57:06 +0000 |
---|---|---|
committer | Ed Maste <emaste@FreeBSD.org> | 2015-07-03 16:57:06 +0000 |
commit | 5e95aa85bb660d45e9905ef1d7180b2678280660 (patch) | |
tree | 3c2e41c3be19b7fc7666ed45a5f91ec3b6e35f2a /source/Host/posix/HostProcessPosix.cpp | |
parent | 12bd4897ff0678fa663e09d78ebc22dd255ceb86 (diff) |
Diffstat (limited to 'source/Host/posix/HostProcessPosix.cpp')
-rw-r--r-- | source/Host/posix/HostProcessPosix.cpp | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/source/Host/posix/HostProcessPosix.cpp b/source/Host/posix/HostProcessPosix.cpp index 8e19add048ee..5761a79da27f 100644 --- a/source/Host/posix/HostProcessPosix.cpp +++ b/source/Host/posix/HostProcessPosix.cpp @@ -69,28 +69,25 @@ Error HostProcessPosix::GetMainModule(FileSpec &file_spec) const // Use special code here because proc/[pid]/exe is a symbolic link. char link_path[PATH_MAX]; - char exe_path[PATH_MAX] = ""; - if (snprintf (link_path, PATH_MAX, "/proc/%" PRIu64 "/exe", m_process) <= 0) + if (snprintf(link_path, PATH_MAX, "/proc/%" PRIu64 "/exe", m_process) != 1) { error.SetErrorString("Unable to build /proc/<pid>/exe string"); return error; } - error = FileSystem::Readlink(link_path, exe_path, llvm::array_lengthof(exe_path)); + error = FileSystem::Readlink(FileSpec{link_path, false}, file_spec); if (!error.Success()) return error; - const ssize_t len = strlen(exe_path); // If the binary has been deleted, the link name has " (deleted)" appended. // Remove if there. - static const ssize_t deleted_len = strlen(" (deleted)"); - if (len > deleted_len && - !strcmp(exe_path + len - deleted_len, " (deleted)")) + if (file_spec.GetFilename().GetStringRef().endswith(" (deleted)")) { - exe_path[len - deleted_len] = 0; + const char *filename = file_spec.GetFilename().GetCString(); + static const size_t deleted_len = strlen(" (deleted)"); + const size_t len = file_spec.GetFilename().GetLength(); + file_spec.GetFilename().SetCStringWithLength(filename, len - deleted_len); } - - file_spec.SetFile(exe_path, false); return error; } |