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 #include "SkString.h" | 9 #include "SkString.h" |
10 #include "SkTFitsIn.h" | 10 #include "SkTFitsIn.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 mode |= W_OK; | 28 mode |= W_OK; |
29 } | 29 } |
30 return (0 == access(path, mode)); | 30 return (0 == access(path, mode)); |
31 } | 31 } |
32 | 32 |
33 typedef struct { | 33 typedef struct { |
34 dev_t dev; | 34 dev_t dev; |
35 ino_t ino; | 35 ino_t ino; |
36 } SkFILEID; | 36 } SkFILEID; |
37 | 37 |
38 static bool sk_ino(SkFILE* a, SkFILEID* id) { | 38 static bool sk_ino(FILE* a, SkFILEID* id) { |
39 int fd = fileno((FILE*)a); | 39 int fd = fileno(a); |
40 if (fd < 0) { | 40 if (fd < 0) { |
41 return 0; | 41 return 0; |
42 } | 42 } |
43 struct stat status; | 43 struct stat status; |
44 if (0 != fstat(fd, &status)) { | 44 if (0 != fstat(fd, &status)) { |
45 return 0; | 45 return 0; |
46 } | 46 } |
47 id->dev = status.st_dev; | 47 id->dev = status.st_dev; |
48 id->ino = status.st_ino; | 48 id->ino = status.st_ino; |
49 return true; | 49 return true; |
50 } | 50 } |
51 | 51 |
52 bool sk_fidentical(SkFILE* a, SkFILE* b) { | 52 bool sk_fidentical(FILE* a, FILE* b) { |
53 SkFILEID aID, bID; | 53 SkFILEID aID, bID; |
54 return sk_ino(a, &aID) && sk_ino(b, &bID) | 54 return sk_ino(a, &aID) && sk_ino(b, &bID) |
55 && aID.ino == bID.ino | 55 && aID.ino == bID.ino |
56 && aID.dev == bID.dev; | 56 && aID.dev == bID.dev; |
57 } | 57 } |
58 | 58 |
59 void sk_fmunmap(const void* addr, size_t length) { | 59 void sk_fmunmap(const void* addr, size_t length) { |
60 munmap(const_cast<void*>(addr), length); | 60 munmap(const_cast<void*>(addr), length); |
61 } | 61 } |
62 | 62 |
(...skipping 12 matching lines...) Expand all Loading... |
75 | 75 |
76 void* addr = mmap(nullptr, fileSize, PROT_READ, MAP_PRIVATE, fd, 0); | 76 void* addr = mmap(nullptr, fileSize, PROT_READ, MAP_PRIVATE, fd, 0); |
77 if (MAP_FAILED == addr) { | 77 if (MAP_FAILED == addr) { |
78 return nullptr; | 78 return nullptr; |
79 } | 79 } |
80 | 80 |
81 *size = fileSize; | 81 *size = fileSize; |
82 return addr; | 82 return addr; |
83 } | 83 } |
84 | 84 |
85 int sk_fileno(SkFILE* f) { | 85 int sk_fileno(FILE* f) { |
86 return fileno((FILE*)f); | 86 return fileno(f); |
87 } | 87 } |
88 | 88 |
89 void* sk_fmmap(SkFILE* f, size_t* size) { | 89 void* sk_fmmap(FILE* f, size_t* size) { |
90 int fd = sk_fileno(f); | 90 int fd = sk_fileno(f); |
91 if (fd < 0) { | 91 if (fd < 0) { |
92 return nullptr; | 92 return nullptr; |
93 } | 93 } |
94 | 94 |
95 return sk_fdmmap(fd, size); | 95 return sk_fdmmap(fd, size); |
96 } | 96 } |
97 | 97 |
98 //////////////////////////////////////////////////////////////////////////// | 98 //////////////////////////////////////////////////////////////////////////// |
99 | 99 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } | 172 } |
173 if (entry) { // we broke out with a file | 173 if (entry) { // we broke out with a file |
174 if (name) { | 174 if (name) { |
175 name->set(entry->d_name); | 175 name->set(entry->d_name); |
176 } | 176 } |
177 return true; | 177 return true; |
178 } | 178 } |
179 } | 179 } |
180 return false; | 180 return false; |
181 } | 181 } |
OLD | NEW |