OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkOSFile.h" | 8 #include "SkOSFile.h" |
9 | 9 |
10 #include <errno.h> | 10 #include <errno.h> |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <sys/stat.h> | 12 #include <sys/stat.h> |
13 #include <sys/types.h> | 13 #include <sys/types.h> |
14 | 14 |
15 #ifdef _WIN32 | 15 #ifdef _WIN32 |
16 #include <direct.h> | 16 #include <direct.h> |
17 #include <io.h> | 17 #include <io.h> |
18 #else | |
19 #include <unistd.h> | |
20 #endif | 18 #endif |
21 | 19 |
22 SkFILE* sk_fopen(const char path[], SkFILE_Flags flags) { | 20 SkFILE* sk_fopen(const char path[], SkFILE_Flags flags) { |
23 char perm[4]; | 21 char perm[4]; |
24 char* p = perm; | 22 char* p = perm; |
25 | 23 |
26 if (flags & kRead_SkFILE_Flag) { | 24 if (flags & kRead_SkFILE_Flag) { |
27 *p++ = 'r'; | 25 *p++ = 'r'; |
28 } | 26 } |
29 if (flags & kWrite_SkFILE_Flag) { | 27 if (flags & kWrite_SkFILE_Flag) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 return 0; | 114 return 0; |
117 } | 115 } |
118 return curr; | 116 return curr; |
119 } | 117 } |
120 | 118 |
121 void sk_fclose(SkFILE* f) { | 119 void sk_fclose(SkFILE* f) { |
122 SkASSERT(f); | 120 SkASSERT(f); |
123 ::fclose((FILE*)f); | 121 ::fclose((FILE*)f); |
124 } | 122 } |
125 | 123 |
126 bool sk_exists(const char *path) { | |
127 #ifdef _WIN32 | |
128 return (0 == _access(path, 0)); | |
129 #else | |
130 return (0 == access(path, 0)); | |
131 #endif | |
132 } | |
133 | |
134 bool sk_isdir(const char *path) { | 124 bool sk_isdir(const char *path) { |
135 struct stat status; | 125 struct stat status; |
136 if (0 != stat(path, &status)) { | 126 if (0 != stat(path, &status)) { |
137 return false; | 127 return false; |
138 } | 128 } |
139 return SkToBool(status.st_mode & S_IFDIR); | 129 return SkToBool(status.st_mode & S_IFDIR); |
140 } | 130 } |
141 | 131 |
142 bool sk_mkdir(const char* path) { | 132 bool sk_mkdir(const char* path) { |
143 if (sk_isdir(path)) { | 133 if (sk_isdir(path)) { |
(...skipping 12 matching lines...) Expand all Loading... |
156 #else | 146 #else |
157 retval = mkdir(path, 0777); | 147 retval = mkdir(path, 0777); |
158 #endif | 148 #endif |
159 if (0 == retval) { | 149 if (0 == retval) { |
160 return true; | 150 return true; |
161 } else { | 151 } else { |
162 fprintf(stderr, "sk_mkdir: error %d creating dir '%s'\n", errno, path); | 152 fprintf(stderr, "sk_mkdir: error %d creating dir '%s'\n", errno, path); |
163 return false; | 153 return false; |
164 } | 154 } |
165 } | 155 } |
OLD | NEW |