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 "SkOSFile.h" | 8 #include "SkOSFile.h" |
9 | 9 |
10 #include "SkTFitsIn.h" | 10 #include "SkTFitsIn.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } | 43 } |
44 | 44 |
45 bool sk_fidentical(SkFILE* a, SkFILE* b) { | 45 bool sk_fidentical(SkFILE* a, SkFILE* b) { |
46 SkFILEID aID, bID; | 46 SkFILEID aID, bID; |
47 return sk_ino(a, &aID) && sk_ino(b, &bID) | 47 return sk_ino(a, &aID) && sk_ino(b, &bID) |
48 && aID.fLsbSize == bID.fLsbSize | 48 && aID.fLsbSize == bID.fLsbSize |
49 && aID.fMsbSize == bID.fMsbSize | 49 && aID.fMsbSize == bID.fMsbSize |
50 && aID.fVolume == bID.fVolume; | 50 && aID.fVolume == bID.fVolume; |
51 } | 51 } |
52 | 52 |
53 template <typename HandleType, HandleType InvalidValue, BOOL (WINAPI * Close)(Ha
ndleType)> | 53 class SkAutoNullKernelHandle : SkNoncopyable { |
54 class SkAutoTHandle : SkNoncopyable { | |
55 public: | 54 public: |
56 SkAutoTHandle(HandleType handle) : fHandle(handle) { } | 55 SkAutoNullKernelHandle(const HANDLE handle) : fHandle(handle) { } |
57 ~SkAutoTHandle() { Close(fHandle); } | 56 ~SkAutoNullKernelHandle() { CloseHandle(fHandle); } |
58 operator HandleType() { return fHandle; } | 57 operator HANDLE() const { return fHandle; } |
59 bool isValid() { return InvalidValue != fHandle; } | 58 bool isValid() const { return NULL != fHandle; } |
60 private: | 59 private: |
61 HandleType fHandle; | 60 HANDLE fHandle; |
62 }; | 61 }; |
63 typedef SkAutoTHandle<HANDLE, INVALID_HANDLE_VALUE, CloseHandle> SkAutoWinFile; | 62 typedef SkAutoNullKernelHandle SkAutoWinMMap; |
64 typedef SkAutoTHandle<HANDLE, NULL, CloseHandle> SkAutoWinMMap; | |
65 | 63 |
66 void sk_fmunmap(const void* addr, size_t) { | 64 void sk_fmunmap(const void* addr, size_t) { |
67 UnmapViewOfFile(addr); | 65 UnmapViewOfFile(addr); |
68 } | 66 } |
69 | 67 |
70 void* sk_fdmmap(int fileno, size_t* length) { | 68 void* sk_fdmmap(int fileno, size_t* length) { |
71 HANDLE file = (HANDLE)_get_osfhandle(fileno); | 69 HANDLE file = (HANDLE)_get_osfhandle(fileno); |
72 if (INVALID_HANDLE_VALUE == file) { | 70 if (INVALID_HANDLE_VALUE == file) { |
73 return NULL; | 71 return NULL; |
74 } | 72 } |
(...skipping 29 matching lines...) Expand all Loading... |
104 } | 102 } |
105 | 103 |
106 void* sk_fmmap(SkFILE* f, size_t* length) { | 104 void* sk_fmmap(SkFILE* f, size_t* length) { |
107 int fileno = sk_fileno(f); | 105 int fileno = sk_fileno(f); |
108 if (fileno < 0) { | 106 if (fileno < 0) { |
109 return NULL; | 107 return NULL; |
110 } | 108 } |
111 | 109 |
112 return sk_fdmmap(fileno, length); | 110 return sk_fdmmap(fileno, length); |
113 } | 111 } |
OLD | NEW |