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

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

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 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_stdio.cpp ('k') | src/ports/SkRemotableFontMgr_win_dw.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 2013 Google Inc. 2 * Copyright 2013 Google Inc.
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 "SkTFitsIn.h" 10 #include "SkTFitsIn.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 }; 72 };
73 typedef SkAutoNullKernelHandle SkAutoWinMMap; 73 typedef SkAutoNullKernelHandle SkAutoWinMMap;
74 74
75 void sk_fmunmap(const void* addr, size_t) { 75 void sk_fmunmap(const void* addr, size_t) {
76 UnmapViewOfFile(addr); 76 UnmapViewOfFile(addr);
77 } 77 }
78 78
79 void* sk_fdmmap(int fileno, size_t* length) { 79 void* sk_fdmmap(int fileno, size_t* length) {
80 HANDLE file = (HANDLE)_get_osfhandle(fileno); 80 HANDLE file = (HANDLE)_get_osfhandle(fileno);
81 if (INVALID_HANDLE_VALUE == file) { 81 if (INVALID_HANDLE_VALUE == file) {
82 return NULL; 82 return nullptr;
83 } 83 }
84 84
85 LARGE_INTEGER fileSize; 85 LARGE_INTEGER fileSize;
86 if (0 == GetFileSizeEx(file, &fileSize)) { 86 if (0 == GetFileSizeEx(file, &fileSize)) {
87 //TODO: use SK_TRACEHR(GetLastError(), "Could not get file size.") to re port. 87 //TODO: use SK_TRACEHR(GetLastError(), "Could not get file size.") to re port.
88 return NULL; 88 return nullptr;
89 } 89 }
90 if (!SkTFitsIn<size_t>(fileSize.QuadPart)) { 90 if (!SkTFitsIn<size_t>(fileSize.QuadPart)) {
91 return NULL; 91 return nullptr;
92 } 92 }
93 93
94 SkAutoWinMMap mmap(CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL)) ; 94 SkAutoWinMMap mmap(CreateFileMapping(file, nullptr, PAGE_READONLY, 0, 0, nul lptr));
95 if (!mmap.isValid()) { 95 if (!mmap.isValid()) {
96 //TODO: use SK_TRACEHR(GetLastError(), "Could not create file mapping.") to report. 96 //TODO: use SK_TRACEHR(GetLastError(), "Could not create file mapping.") to report.
97 return NULL; 97 return nullptr;
98 } 98 }
99 99
100 // Eventually call UnmapViewOfFile 100 // Eventually call UnmapViewOfFile
101 void* addr = MapViewOfFile(mmap, FILE_MAP_READ, 0, 0, 0); 101 void* addr = MapViewOfFile(mmap, FILE_MAP_READ, 0, 0, 0);
102 if (NULL == addr) { 102 if (nullptr == addr) {
103 //TODO: use SK_TRACEHR(GetLastError(), "Could not map view of file.") to report. 103 //TODO: use SK_TRACEHR(GetLastError(), "Could not map view of file.") to report.
104 return NULL; 104 return nullptr;
105 } 105 }
106 106
107 *length = static_cast<size_t>(fileSize.QuadPart); 107 *length = static_cast<size_t>(fileSize.QuadPart);
108 return addr; 108 return addr;
109 } 109 }
110 110
111 int sk_fileno(SkFILE* f) { 111 int sk_fileno(SkFILE* f) {
112 return _fileno((FILE*)f); 112 return _fileno((FILE*)f);
113 } 113 }
114 114
115 void* sk_fmmap(SkFILE* f, size_t* length) { 115 void* sk_fmmap(SkFILE* f, size_t* length) {
116 int fileno = sk_fileno(f); 116 int fileno = sk_fileno(f);
117 if (fileno < 0) { 117 if (fileno < 0) {
118 return NULL; 118 return nullptr;
119 } 119 }
120 120
121 return sk_fdmmap(fileno, length); 121 return sk_fdmmap(fileno, length);
122 } 122 }
123 123
124 //////////////////////////////////////////////////////////////////////////// 124 ////////////////////////////////////////////////////////////////////////////
125 125
126 struct SkOSFileIterData { 126 struct SkOSFileIterData {
127 SkOSFileIterData() : fHandle(0), fPath16(NULL) { } 127 SkOSFileIterData() : fHandle(0), fPath16(nullptr) { }
128 HANDLE fHandle; 128 HANDLE fHandle;
129 uint16_t* fPath16; 129 uint16_t* fPath16;
130 }; 130 };
131 static_assert(sizeof(SkOSFileIterData) <= SkOSFile::Iter::kStorageSize, "not_eno ugh_space"); 131 static_assert(sizeof(SkOSFileIterData) <= SkOSFile::Iter::kStorageSize, "not_eno ugh_space");
132 132
133 static uint16_t* concat_to_16(const char src[], const char suffix[]) { 133 static uint16_t* concat_to_16(const char src[], const char suffix[]) {
134 size_t i, len = strlen(src); 134 size_t i, len = strlen(src);
135 size_t len2 = 3 + (suffix ? strlen(suffix) : 0); 135 size_t len2 = 3 + (suffix ? strlen(suffix) : 0);
136 uint16_t* dst = (uint16_t*)sk_malloc_throw((len + len2) * sizeof(uint16_t)); 136 uint16_t* dst = (uint16_t*)sk_malloc_throw((len + len2) * sizeof(uint16_t));
137 137
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 170 }
171 self.~SkOSFileIterData(); 171 self.~SkOSFileIterData();
172 } 172 }
173 173
174 void SkOSFile::Iter::reset(const char path[], const char suffix[]) { 174 void SkOSFile::Iter::reset(const char path[], const char suffix[]) {
175 SkOSFileIterData& self = *static_cast<SkOSFileIterData*>(fSelf.get()); 175 SkOSFileIterData& self = *static_cast<SkOSFileIterData*>(fSelf.get());
176 if (self.fHandle) { 176 if (self.fHandle) {
177 ::FindClose(self.fHandle); 177 ::FindClose(self.fHandle);
178 self.fHandle = 0; 178 self.fHandle = 0;
179 } 179 }
180 if (NULL == path) { 180 if (nullptr == path) {
181 path = ""; 181 path = "";
182 } 182 }
183 183
184 sk_free(self.fPath16); 184 sk_free(self.fPath16);
185 self.fPath16 = concat_to_16(path, suffix); 185 self.fPath16 = concat_to_16(path, suffix);
186 } 186 }
187 187
188 static bool is_magic_dir(const uint16_t dir[]) { 188 static bool is_magic_dir(const uint16_t dir[]) {
189 // return true for "." and ".." 189 // return true for "." and ".."
190 return dir[0] == '.' && (dir[1] == 0 || (dir[1] == '.' && dir[2] == 0)); 190 return dir[0] == '.' && (dir[1] == 0 || (dir[1] == '.' && dir[2] == 0));
191 } 191 }
192 192
193 static bool get_the_file(HANDLE handle, SkString* name, WIN32_FIND_DATAW* dataPt r, bool getDir) { 193 static bool get_the_file(HANDLE handle, SkString* name, WIN32_FIND_DATAW* dataPt r, bool getDir) {
194 WIN32_FIND_DATAW data; 194 WIN32_FIND_DATAW data;
195 195
196 if (NULL == dataPtr) { 196 if (nullptr == dataPtr) {
197 if (::FindNextFileW(handle, &data)) 197 if (::FindNextFileW(handle, &data))
198 dataPtr = &data; 198 dataPtr = &data;
199 else 199 else
200 return false; 200 return false;
201 } 201 }
202 202
203 for (;;) { 203 for (;;) {
204 if (getDir) { 204 if (getDir) {
205 if ((dataPtr->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && 205 if ((dataPtr->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
206 !is_magic_dir((uint16_t*)dataPtr->cFileName)) 206 !is_magic_dir((uint16_t*)dataPtr->cFileName))
(...skipping 12 matching lines...) Expand all
219 // if we get here, we've found a file/dir 219 // if we get here, we've found a file/dir
220 if (name) { 220 if (name) {
221 name->setUTF16((uint16_t*)dataPtr->cFileName); 221 name->setUTF16((uint16_t*)dataPtr->cFileName);
222 } 222 }
223 return true; 223 return true;
224 } 224 }
225 225
226 bool SkOSFile::Iter::next(SkString* name, bool getDir) { 226 bool SkOSFile::Iter::next(SkString* name, bool getDir) {
227 SkOSFileIterData& self = *static_cast<SkOSFileIterData*>(fSelf.get()); 227 SkOSFileIterData& self = *static_cast<SkOSFileIterData*>(fSelf.get());
228 WIN32_FIND_DATAW data; 228 WIN32_FIND_DATAW data;
229 WIN32_FIND_DATAW* dataPtr = NULL; 229 WIN32_FIND_DATAW* dataPtr = nullptr;
230 230
231 if (self.fHandle == 0) { // our first time 231 if (self.fHandle == 0) { // our first time
232 if (self.fPath16 == NULL || *self.fPath16 == 0) { // check for no path 232 if (self.fPath16 == nullptr || *self.fPath16 == 0) { // check for no pa th
233 return false; 233 return false;
234 } 234 }
235 235
236 self.fHandle = ::FindFirstFileW((LPCWSTR)self.fPath16, &data); 236 self.fHandle = ::FindFirstFileW((LPCWSTR)self.fPath16, &data);
237 if (self.fHandle != 0 && self.fHandle != (HANDLE)~0) { 237 if (self.fHandle != 0 && self.fHandle != (HANDLE)~0) {
238 dataPtr = &data; 238 dataPtr = &data;
239 } 239 }
240 } 240 }
241 return self.fHandle != (HANDLE)~0 && get_the_file(self.fHandle, name, dataPt r, getDir); 241 return self.fHandle != (HANDLE)~0 && get_the_file(self.fHandle, name, dataPt r, getDir);
242 } 242 }
OLDNEW
« no previous file with comments | « src/ports/SkOSFile_stdio.cpp ('k') | src/ports/SkRemotableFontMgr_win_dw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698