aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-29 16:42:11 +0000
committerGravatar epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-29 16:42:11 +0000
commite8ebeb1f8fde6525bbab988c6090a5d3ab19855b (patch)
tree5e7185a6bcfe4a99bca383a649d303e525b3fd07 /src
parent549c93ef979aeb4dcb65b3d0fca4b58e8ab62227 (diff)
Add option to gm: write out images into a hierarchy, rather than a flat set of files
Diffstat (limited to 'src')
-rw-r--r--src/core/SkString.cpp19
-rw-r--r--src/ports/SkOSFile_stdio.cpp54
2 files changed, 67 insertions, 6 deletions
diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp
index fee614cc03..5d1b8ceea3 100644
--- a/src/core/SkString.cpp
+++ b/src/core/SkString.cpp
@@ -36,13 +36,23 @@ static const size_t kBufferSize = 512;
///////////////////////////////////////////////////////////////////////////////
-bool SkStrEndsWith(const char string[], const char suffix[]) {
+bool SkStrEndsWith(const char string[], const char suffixStr[]) {
SkASSERT(string);
- SkASSERT(suffix);
+ SkASSERT(suffixStr);
size_t strLen = strlen(string);
- size_t suffixLen = strlen(suffix);
+ size_t suffixLen = strlen(suffixStr);
return strLen >= suffixLen &&
- !strncmp(string + strLen - suffixLen, suffix, suffixLen);
+ !strncmp(string + strLen - suffixLen, suffixStr, suffixLen);
+}
+
+bool SkStrEndsWith(const char string[], const char suffixChar) {
+ SkASSERT(string);
+ size_t strLen = strlen(string);
+ if (0 == strLen) {
+ return false;
+ } else {
+ return (suffixChar == string[strLen-1]);
+ }
}
int SkStrStartsWithOneOf(const char string[], const char prefixes[]) {
@@ -602,4 +612,3 @@ SkString SkStringPrintf(const char* format, ...) {
#undef VSNPRINTF
#undef SNPRINTF
-
diff --git a/src/ports/SkOSFile_stdio.cpp b/src/ports/SkOSFile_stdio.cpp
index 1254394431..6c825b4cb6 100644
--- a/src/ports/SkOSFile_stdio.cpp
+++ b/src/ports/SkOSFile_stdio.cpp
@@ -9,8 +9,17 @@
#include "SkOSFile.h"
-#include <stdio.h>
#include <errno.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#ifdef _WIN32
+#include <direct.h>
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
SkFILE* sk_fopen(const char path[], SkFILE_Flags flags)
{
@@ -98,3 +107,46 @@ void sk_fclose(SkFILE* f)
::fclose((FILE*)f);
}
+bool sk_exists(const char *path)
+{
+#ifdef _WIN32
+ return (0 == _access(path, 0));
+#else
+ return (0 == access(path, 0));
+#endif
+}
+
+bool sk_isdir(const char *path)
+{
+ struct stat status;
+ if (0 != stat(path, &status)) {
+ return false;
+ }
+ return (status.st_mode & S_IFDIR);
+}
+
+bool sk_mkdir(const char* path)
+{
+ if (sk_isdir(path)) {
+ return true;
+ }
+ if (sk_exists(path)) {
+ fprintf(stderr,
+ "sk_mkdir: path '%s' already exists but is not a directory\n",
+ path);
+ return false;
+ }
+
+ int retval;
+#ifdef _WIN32
+ retval = _mkdir(path);
+#else
+ retval = mkdir(path, 0777);
+#endif
+ if (0 == retval) {
+ return true;
+ } else {
+ fprintf(stderr, "sk_mkdir: error %d creating dir '%s'\n", errno, path);
+ return false;
+ }
+}