add globbing util function

R=djsollen@google.com

Review URL: https://codereview.chromium.org/17881002

git-svn-id: http://skia.googlecode.com/svn/trunk@9774 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/skpdiff/skpdiff_util.cpp b/experimental/skpdiff/skpdiff_util.cpp
index 285e04c..3a36a12 100644
--- a/experimental/skpdiff/skpdiff_util.cpp
+++ b/experimental/skpdiff/skpdiff_util.cpp
@@ -7,6 +7,7 @@
 
 #include <time.h>
 #include <dirent.h>
+#include <glob.h>
 #include "SkOSFile.h"
 #include "skpdiff_util.h"
 
@@ -90,5 +91,27 @@
         }
     }
 
+    closedir(dir);
+
+    return true;
+}
+
+bool glob_files(const char globPattern[], SkTArray<SkString>* entries) {
+    // TODO Make sure this works on windows. This may require use of FindNextFile windows function.
+    glob_t globBuffer;
+    if (glob(globPattern, 0, NULL, &globBuffer) != 0) {
+        return false;
+    }
+
+    // Note these paths are in sorted order by default according to http://linux.die.net/man/3/glob
+    // Check under the flag GLOB_NOSORT
+    char** paths = globBuffer.gl_pathv;
+    while(NULL != *paths) {
+        entries->push_back(SkString(*paths));
+        paths++;
+    }
+
+    globfree(&globBuffer);
+
     return true;
 }