aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar zachr@google.com <zachr@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-26 18:55:36 +0000
committerGravatar zachr@google.com <zachr@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-26 18:55:36 +0000
commit18bbba9a9ae3c9c434ac2159bac0b4296ae7f213 (patch)
tree28fba3ff427ae785247d21c886177af2a42bfba7
parent131d4ee0eabf7b7ddb5ccf0744edb4b449226773 (diff)
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
-rw-r--r--experimental/skpdiff/skpdiff_util.cpp23
-rw-r--r--experimental/skpdiff/skpdiff_util.h8
2 files changed, 31 insertions, 0 deletions
diff --git a/experimental/skpdiff/skpdiff_util.cpp b/experimental/skpdiff/skpdiff_util.cpp
index 285e04c063..3a36a12dbf 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 @@ bool get_directory(const char path[], SkTArray<SkString>* entries) {
}
}
+ 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;
}
diff --git a/experimental/skpdiff/skpdiff_util.h b/experimental/skpdiff/skpdiff_util.h
index 34fa8f3e00..d98175e038 100644
--- a/experimental/skpdiff/skpdiff_util.h
+++ b/experimental/skpdiff/skpdiff_util.h
@@ -34,5 +34,13 @@ double get_seconds();
*/
bool get_directory(const char path[], SkTArray<SkString>* entries);
+/**
+ * Gets the files that match the specified pattern in sorted order.
+ * @param globPattern The pattern to use. Patterns must be valid paths, optionally with wildcards (*)
+ * @param entries An array to return the results into
+ * @return True on success, false otherwise
+ */
+bool glob_files(const char globPattern[], SkTArray<SkString>* entries);
+
#endif