diff options
author | epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-29 16:42:11 +0000 |
---|---|---|
committer | epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-29 16:42:11 +0000 |
commit | e8ebeb1f8fde6525bbab988c6090a5d3ab19855b (patch) | |
tree | 5e7185a6bcfe4a99bca383a649d303e525b3fd07 /src/ports | |
parent | 549c93ef979aeb4dcb65b3d0fca4b58e8ab62227 (diff) |
Add option to gm: write out images into a hierarchy, rather than a flat set of files
BUG=https://code.google.com/p/skia/issues/detail?id=743
Review URL: https://codereview.appspot.com/6810047
git-svn-id: http://skia.googlecode.com/svn/trunk@6167 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/ports')
-rw-r--r-- | src/ports/SkOSFile_stdio.cpp | 54 |
1 files changed, 53 insertions, 1 deletions
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; + } +} |