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

Unified Diff: src/ports/SkOSFile_win.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_posix.cpp ('k') | src/utils/win/SkDWriteFontFileStream.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkOSFile_win.cpp
===================================================================
--- src/ports/SkOSFile_win.cpp (revision 9384)
+++ src/ports/SkOSFile_win.cpp (working copy)
@@ -7,6 +7,8 @@
#include "SkOSFile.h"
+#include "SkTemplates.h"
+
#include <io.h>
#include <stdio.h>
#include <sys/stat.h>
@@ -65,19 +67,18 @@
UnmapViewOfFile(addr);
}
-void* sk_fmmap(SkFILE* f, size_t* length) {
- size_t fileSize = sk_fgetsize(f);
- if (0 == fileSize) {
+void* sk_fdmmap(int fileno, size_t* length) {
+ HANDLE file = (HANDLE)_get_osfhandle(fileno);
+ if (INVALID_HANDLE_VALUE == file) {
return NULL;
}
- int fileno = _fileno((FILE*)f);
- if (fileno < 0) {
+ LARGE_INTEGER fileSize;
+ if (0 == GetFileSizeEx(file, &fileSize)) {
+ //TODO: use SK_TRACEHR(GetLastError(), "Could not get file size.") to report.
return NULL;
}
-
- HANDLE file = (HANDLE)_get_osfhandle(fileno);
- if (INVALID_HANDLE_VALUE == file) {
+ if (!SkTFitsIn<size_t>(fileSize.QuadPart)) {
return NULL;
}
@@ -94,6 +95,19 @@
return NULL;
}
- *length = fileSize;
+ *length = static_cast<size_t>(fileSize.QuadPart);
return addr;
}
+
+int sk_fileno(SkFILE* f) {
+ return _fileno((FILE*)f);
+}
+
+void* sk_fmmap(SkFILE* f, size_t* length) {
+ int fileno = sk_fileno(f);
+ if (fileno < 0) {
+ return NULL;
+ }
+
+ return sk_fdmmap(fileno, length);
+}
« no previous file with comments | « src/ports/SkOSFile_posix.cpp ('k') | src/utils/win/SkDWriteFontFileStream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698