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

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

Issue 15941025: Add SkData::NewFromFD. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Remove an indentation level. Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/ports/SkOSFile_none.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 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 "SkTemplates.h"
11
10 #include <stdio.h> 12 #include <stdio.h>
11 #include <sys/mman.h> 13 #include <sys/mman.h>
12 #include <sys/stat.h> 14 #include <sys/stat.h>
13 #include <sys/types.h> 15 #include <sys/types.h>
14 16
15 typedef struct { 17 typedef struct {
16 dev_t dev; 18 dev_t dev;
17 ino_t ino; 19 ino_t ino;
18 } SkFILEID; 20 } SkFILEID;
19 21
(...skipping 15 matching lines...) Expand all
35 SkFILEID aID, bID; 37 SkFILEID aID, bID;
36 return sk_ino(a, &aID) && sk_ino(b, &bID) 38 return sk_ino(a, &aID) && sk_ino(b, &bID)
37 && aID.ino == bID.ino 39 && aID.ino == bID.ino
38 && aID.dev == bID.dev; 40 && aID.dev == bID.dev;
39 } 41 }
40 42
41 void sk_fmunmap(const void* addr, size_t length) { 43 void sk_fmunmap(const void* addr, size_t length) {
42 munmap(const_cast<void*>(addr), length); 44 munmap(const_cast<void*>(addr), length);
43 } 45 }
44 46
45 void* sk_fmmap(SkFILE* f, size_t* size) { 47 void* sk_fdmmap(int fd, size_t* size) {
46 size_t fileSize = sk_fgetsize(f); 48 struct stat status;
47 if (0 == fileSize) { 49 if (0 != fstat(fd, &status)) {
48 return NULL; 50 return NULL;
49 } 51 }
50 52 if (!S_ISREG(status.st_mode)) {
51 int fd = fileno((FILE*)f);
52 if (fd < 0) {
53 return NULL; 53 return NULL;
54 } 54 }
55 if (!SkTFitsIn<size_t>(status.st_size)) {
56 return NULL;
57 }
58 size_t fileSize = static_cast<size_t>(status.st_size);
55 59
56 void* addr = mmap(NULL, fileSize, PROT_READ, MAP_PRIVATE, fd, 0); 60 void* addr = mmap(NULL, fileSize, PROT_READ, MAP_PRIVATE, fd, 0);
57 if (MAP_FAILED == addr) { 61 if (MAP_FAILED == addr) {
58 return NULL; 62 return NULL;
59 } 63 }
60 64
61 *size = fileSize; 65 *size = fileSize;
62 return addr; 66 return addr;
63 } 67 }
68
69 int sk_fileno(SkFILE* f) {
70 return fileno((FILE*)f);
71 }
72
73 void* sk_fmmap(SkFILE* f, size_t* size) {
74 int fd = sk_fileno(f);
75 if (fd < 0) {
76 return NULL;
77 }
78
79 return sk_fdmmap(fd, size);
80 }
OLDNEW
« no previous file with comments | « src/ports/SkOSFile_none.cpp ('k') | src/ports/SkOSFile_win.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698