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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ports/SkOSFile_none.cpp ('k') | src/ports/SkOSFile_win.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkOSFile_posix.cpp
===================================================================
--- src/ports/SkOSFile_posix.cpp (revision 9384)
+++ src/ports/SkOSFile_posix.cpp (working copy)
@@ -7,6 +7,8 @@
#include "SkOSFile.h"
+#include "SkTemplates.h"
+
#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
@@ -42,16 +44,18 @@
munmap(const_cast<void*>(addr), length);
}
-void* sk_fmmap(SkFILE* f, size_t* size) {
- size_t fileSize = sk_fgetsize(f);
- if (0 == fileSize) {
+void* sk_fdmmap(int fd, size_t* size) {
+ struct stat status;
+ if (0 != fstat(fd, &status)) {
return NULL;
}
-
- int fd = fileno((FILE*)f);
- if (fd < 0) {
+ if (!S_ISREG(status.st_mode)) {
return NULL;
}
+ if (!SkTFitsIn<size_t>(status.st_size)) {
+ return NULL;
+ }
+ size_t fileSize = static_cast<size_t>(status.st_size);
void* addr = mmap(NULL, fileSize, PROT_READ, MAP_PRIVATE, fd, 0);
if (MAP_FAILED == addr) {
@@ -61,3 +65,16 @@
*size = fileSize;
return addr;
}
+
+int sk_fileno(SkFILE* f) {
+ return fileno((FILE*)f);
+}
+
+void* sk_fmmap(SkFILE* f, size_t* size) {
+ int fd = sk_fileno(f);
+ if (fd < 0) {
+ return NULL;
+ }
+
+ return sk_fdmmap(fd, size);
+}
« 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