forked from OSchip/llvm-project
Don't use libc's "char *basename(char *)" or "char *dirname(char *)" as they are not thread safe.
I switched the lldb_private::FileSpec code over to use "llvm::StringRef llvm::sys::path::filename(llvm::StringRef)" for basename() and "llvm::StringRef llvm::sys::path::parent_path(llvm::StringRef)" for dirname(). <rdar://problem/16870083> llvm-svn: 209917
This commit is contained in:
parent
82560a91a5
commit
6bc8739e57
|
@ -324,40 +324,14 @@ FileSpec::SetFile (const char *pathname, bool resolve)
|
||||||
|
|
||||||
if (path_fit)
|
if (path_fit)
|
||||||
{
|
{
|
||||||
char *filename = ::basename (resolved_path);
|
llvm::StringRef resolve_path_ref(resolved_path);
|
||||||
if (filename)
|
llvm::StringRef filename_ref = llvm::sys::path::filename(resolve_path_ref);
|
||||||
|
if (!filename_ref.empty())
|
||||||
{
|
{
|
||||||
m_filename.SetCString (filename);
|
m_filename.SetString (filename_ref);
|
||||||
// Truncate the basename off the end of the resolved path
|
llvm::StringRef directory_ref = llvm::sys::path::parent_path(resolve_path_ref);
|
||||||
|
if (!directory_ref.empty())
|
||||||
// Only attempt to get the dirname if it looks like we have a path
|
m_directory.SetString(directory_ref);
|
||||||
if (strchr(resolved_path, '/')
|
|
||||||
#ifdef _WIN32
|
|
||||||
|| strchr(resolved_path, '\\')
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
|
||||||
char *directory = ::dirname (resolved_path);
|
|
||||||
|
|
||||||
// Make sure we didn't get our directory resolved to "." without having
|
|
||||||
// specified
|
|
||||||
if (directory)
|
|
||||||
m_directory.SetCString(directory);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
char *last_resolved_path_slash = strrchr(resolved_path, '/');
|
|
||||||
#ifdef _WIN32
|
|
||||||
char* last_resolved_path_slash_windows = strrchr(resolved_path, '\\');
|
|
||||||
if (last_resolved_path_slash_windows > last_resolved_path_slash)
|
|
||||||
last_resolved_path_slash = last_resolved_path_slash_windows;
|
|
||||||
#endif
|
|
||||||
if (last_resolved_path_slash)
|
|
||||||
{
|
|
||||||
*last_resolved_path_slash = '\0';
|
|
||||||
m_directory.SetCString(resolved_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_directory.SetCString(resolved_path);
|
m_directory.SetCString(resolved_path);
|
||||||
|
@ -572,7 +546,6 @@ FileSpec::ResolveExecutableLocation ()
|
||||||
const std::string file_str (file_cstr);
|
const std::string file_str (file_cstr);
|
||||||
std::string path = llvm::sys::FindProgramByName (file_str);
|
std::string path = llvm::sys::FindProgramByName (file_str);
|
||||||
llvm::StringRef dir_ref = llvm::sys::path::parent_path(path);
|
llvm::StringRef dir_ref = llvm::sys::path::parent_path(path);
|
||||||
//llvm::StringRef dir_ref = path.getDirname();
|
|
||||||
if (!dir_ref.empty())
|
if (!dir_ref.empty())
|
||||||
{
|
{
|
||||||
// FindProgramByName returns "." if it can't find the file.
|
// FindProgramByName returns "." if it can't find the file.
|
||||||
|
|
Loading…
Reference in New Issue