Add FileSpec::ResolvePartialUsername, and use it in CommandCompletions to isolate pwd.h in the Host layer.

git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@125135 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Host/common/FileSpec.cpp b/source/Host/common/FileSpec.cpp
index 2b6c86a..ea50cb9 100644
--- a/source/Host/common/FileSpec.cpp
+++ b/source/Host/common/FileSpec.cpp
@@ -145,6 +145,41 @@
 }
 
 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')