diff options
author | Jim Ingham <jingham@apple.com> | 2011-02-08 23:24:09 +0000 |
---|---|---|
committer | Jim Ingham <jingham@apple.com> | 2011-02-08 23:24:09 +0000 |
commit | 843630781afec188174fe6b7f5b9c44e13a6449e (patch) | |
tree | 0e912e6a8a3b908bc75028c00256680f31a3b41c /lldb/source/Host/common/FileSpec.cpp | |
parent | 03feace9d00d15854dcaf7f2edffd1e200beb16e (diff) | |
download | bcm5719-llvm-843630781afec188174fe6b7f5b9c44e13a6449e.tar.gz bcm5719-llvm-843630781afec188174fe6b7f5b9c44e13a6449e.zip |
Add FileSpec::ResolvePartialUsername, and use it in CommandCompletions to isolate pwd.h in the Host layer.
llvm-svn: 125135
Diffstat (limited to 'lldb/source/Host/common/FileSpec.cpp')
-rw-r--r-- | lldb/source/Host/common/FileSpec.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp index 2b6c86a7f49..ea50cb9a2eb 100644 --- a/lldb/source/Host/common/FileSpec.cpp +++ b/lldb/source/Host/common/FileSpec.cpp @@ -145,6 +145,41 @@ FileSpec::ResolveUsername (const char *src_path, char *dst_path, size_t dst_len) } size_t +FileSpec::ResolvePartialUsername (const char *partial_name, StringList &matches) +{ +#ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER + size_t extant_entries = matches.GetSize(); + + setpwent(); + struct passwd *user_entry; + const char *name_start = partial_name + 1; + std::set<std::string> name_list; + + while ((user_entry = getpwent()) != NULL) + { + if (strstr(user_entry->pw_name, name_start) == user_entry->pw_name) + { + std::string tmp_buf("~"); + tmp_buf.append(user_entry->pw_name); + tmp_buf.push_back('/'); + name_list.insert(tmp_buf); + } + } + std::set<std::string>::iterator pos, end = name_list.end(); + for (pos = name_list.begin(); pos != end; pos++) + { + matches.AppendString((*pos).c_str()); + } + return matches.GetSize() - extant_entries; +#else + // Resolving home directories is not supported, just copy the path... + return 0; +#endif // #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER +} + + + +size_t FileSpec::Resolve (const char *src_path, char *dst_path, size_t dst_len) { if (src_path == NULL || src_path[0] == '\0') |