OLD | NEW |
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 "SkTypes.h" | 8 #include "SkTypes.h" |
9 #if defined(SK_BUILD_FOR_WIN32) | 9 #if defined(SK_BUILD_FOR_WIN32) |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 return (0 == _access(path, mode)); | 27 return (0 == _access(path, mode)); |
28 } | 28 } |
29 | 29 |
30 typedef struct { | 30 typedef struct { |
31 ULONGLONG fVolume; | 31 ULONGLONG fVolume; |
32 ULONGLONG fLsbSize; | 32 ULONGLONG fLsbSize; |
33 ULONGLONG fMsbSize; | 33 ULONGLONG fMsbSize; |
34 } SkFILEID; | 34 } SkFILEID; |
35 | 35 |
36 static bool sk_ino(SkFILE* f, SkFILEID* id) { | 36 static bool sk_ino(FILE* f, SkFILEID* id) { |
37 int fileno = _fileno((FILE*)f); | 37 int fileno = _fileno((FILE*)f); |
38 if (fileno < 0) { | 38 if (fileno < 0) { |
39 return false; | 39 return false; |
40 } | 40 } |
41 | 41 |
42 HANDLE file = (HANDLE)_get_osfhandle(fileno); | 42 HANDLE file = (HANDLE)_get_osfhandle(fileno); |
43 if (INVALID_HANDLE_VALUE == file) { | 43 if (INVALID_HANDLE_VALUE == file) { |
44 return false; | 44 return false; |
45 } | 45 } |
46 | 46 |
47 //TODO: call GetFileInformationByHandleEx on Vista and later with FileIdInfo
. | 47 //TODO: call GetFileInformationByHandleEx on Vista and later with FileIdInfo
. |
48 BY_HANDLE_FILE_INFORMATION info; | 48 BY_HANDLE_FILE_INFORMATION info; |
49 if (0 == GetFileInformationByHandle(file, &info)) { | 49 if (0 == GetFileInformationByHandle(file, &info)) { |
50 return false; | 50 return false; |
51 } | 51 } |
52 id->fVolume = info.dwVolumeSerialNumber; | 52 id->fVolume = info.dwVolumeSerialNumber; |
53 id->fLsbSize = info.nFileIndexLow + (((ULONGLONG)info.nFileIndexHigh) << 32)
; | 53 id->fLsbSize = info.nFileIndexLow + (((ULONGLONG)info.nFileIndexHigh) << 32)
; |
54 id->fMsbSize = 0; | 54 id->fMsbSize = 0; |
55 | 55 |
56 return true; | 56 return true; |
57 } | 57 } |
58 | 58 |
59 bool sk_fidentical(SkFILE* a, SkFILE* b) { | 59 bool sk_fidentical(FILE* a, FILE* b) { |
60 SkFILEID aID, bID; | 60 SkFILEID aID, bID; |
61 return sk_ino(a, &aID) && sk_ino(b, &bID) | 61 return sk_ino(a, &aID) && sk_ino(b, &bID) |
62 && aID.fLsbSize == bID.fLsbSize | 62 && aID.fLsbSize == bID.fLsbSize |
63 && aID.fMsbSize == bID.fMsbSize | 63 && aID.fMsbSize == bID.fMsbSize |
64 && aID.fVolume == bID.fVolume; | 64 && aID.fVolume == bID.fVolume; |
65 } | 65 } |
66 | 66 |
67 class SkAutoNullKernelHandle : SkNoncopyable { | 67 class SkAutoNullKernelHandle : SkNoncopyable { |
68 public: | 68 public: |
69 SkAutoNullKernelHandle(const HANDLE handle) : fHandle(handle) { } | 69 SkAutoNullKernelHandle(const HANDLE handle) : fHandle(handle) { } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 void* addr = MapViewOfFile(mmap, FILE_MAP_READ, 0, 0, 0); | 104 void* addr = MapViewOfFile(mmap, FILE_MAP_READ, 0, 0, 0); |
105 if (nullptr == addr) { | 105 if (nullptr == addr) { |
106 //TODO: use SK_TRACEHR(GetLastError(), "Could not map view of file.") to
report. | 106 //TODO: use SK_TRACEHR(GetLastError(), "Could not map view of file.") to
report. |
107 return nullptr; | 107 return nullptr; |
108 } | 108 } |
109 | 109 |
110 *length = static_cast<size_t>(fileSize.QuadPart); | 110 *length = static_cast<size_t>(fileSize.QuadPart); |
111 return addr; | 111 return addr; |
112 } | 112 } |
113 | 113 |
114 int sk_fileno(SkFILE* f) { | 114 int sk_fileno(FILE* f) { |
115 return _fileno((FILE*)f); | 115 return _fileno((FILE*)f); |
116 } | 116 } |
117 | 117 |
118 void* sk_fmmap(SkFILE* f, size_t* length) { | 118 void* sk_fmmap(FILE* f, size_t* length) { |
119 int fileno = sk_fileno(f); | 119 int fileno = sk_fileno(f); |
120 if (fileno < 0) { | 120 if (fileno < 0) { |
121 return nullptr; | 121 return nullptr; |
122 } | 122 } |
123 | 123 |
124 return sk_fdmmap(fileno, length); | 124 return sk_fdmmap(fileno, length); |
125 } | 125 } |
126 | 126 |
127 //////////////////////////////////////////////////////////////////////////// | 127 //////////////////////////////////////////////////////////////////////////// |
128 | 128 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 238 |
239 self.fHandle = ::FindFirstFileW((LPCWSTR)self.fPath16, &data); | 239 self.fHandle = ::FindFirstFileW((LPCWSTR)self.fPath16, &data); |
240 if (self.fHandle != 0 && self.fHandle != (HANDLE)~0) { | 240 if (self.fHandle != 0 && self.fHandle != (HANDLE)~0) { |
241 dataPtr = &data; | 241 dataPtr = &data; |
242 } | 242 } |
243 } | 243 } |
244 return self.fHandle != (HANDLE)~0 && get_the_file(self.fHandle, name, dataPt
r, getDir); | 244 return self.fHandle != (HANDLE)~0 && get_the_file(self.fHandle, name, dataPt
r, getDir); |
245 } | 245 } |
246 | 246 |
247 #endif//defined(SK_BUILD_FOR_WIN32) | 247 #endif//defined(SK_BUILD_FOR_WIN32) |
OLD | NEW |