Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/ports/SkOSFile_stdio.cpp

Issue 384903002: Add file access modes to sk_exists. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Better comment. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ports/SkOSFile_posix.cpp ('k') | src/ports/SkOSFile_win.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « src/ports/SkOSFile_posix.cpp ('k') | src/ports/SkOSFile_win.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698