From 843630781afec188174fe6b7f5b9c44e13a6449e Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Tue, 8 Feb 2011 23:24:09 +0000 Subject: Add FileSpec::ResolvePartialUsername, and use it in CommandCompletions to isolate pwd.h in the Host layer. llvm-svn: 125135 --- lldb/source/Host/common/FileSpec.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'lldb/source/Host/common/FileSpec.cpp') 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 @@ -144,6 +144,41 @@ FileSpec::ResolveUsername (const char *src_path, char *dst_path, size_t dst_len) #endif // #ifdef LLDB_CONFIG_TILDE_RESOLVES_TO_USER } +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 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::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) { -- cgit v1.2.3