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

Unified Diff: ppapi/native_client/src/trusted/plugin/utility.cc

Issue 291973002: Pepper: DescWrapper cleanup in PnaclResources. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 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
Index: ppapi/native_client/src/trusted/plugin/utility.cc
diff --git a/ppapi/native_client/src/trusted/plugin/utility.cc b/ppapi/native_client/src/trusted/plugin/utility.cc
index ea4a4942bdf0e2168c76dd5ea1d00edb7aa13dc0..e694a28e18c575e710ac2ee230b47ce1c2910e67 100644
--- a/ppapi/native_client/src/trusted/plugin/utility.cc
+++ b/ppapi/native_client/src/trusted/plugin/utility.cc
@@ -117,4 +117,37 @@ void SetNaClInterface(const PPB_NaCl_Private* nacl_interface) {
g_nacl_interface = nacl_interface;
}
+void CloseFileHandle(PP_FileHandle file_handle) {
+#if NACL_WINDOWS
+ CloseHandle(file_handle);
+#else
+ close(file_handle);
+#endif
+}
+
+// Converts a PP_FileHandle to a POSIX file descriptor.
+int32_t ConvertFileDescriptor(PP_FileHandle handle, bool read_only) {
+ PLUGIN_PRINTF(("ConvertFileDescriptor, handle=%d\n", handle));
+#if NACL_WINDOWS
+ int32_t file_desc = NACL_NO_FILE_DESC;
+ // On Windows, valid handles are 32 bit unsigned integers so this is safe.
+ file_desc = reinterpret_cast<intptr_t>(handle);
+ // Convert the Windows HANDLE from Pepper to a POSIX file descriptor.
+ int flags = _O_BINARY;
+ if (read_only)
+ flags |= _O_RDONLY;
+ else
+ flags |= _O_RDWR;
bbudge 2014/05/21 02:04:24 Consider conditional expression: flags |= read_on
+ int32_t posix_desc = _open_osfhandle(file_desc, flags);
+ if (posix_desc == -1) {
+ // Close the Windows HANDLE if it can't be converted.
+ CloseHandle(reinterpret_cast<HANDLE>(file_desc));
+ return -1;
+ }
+ return posix_desc;
+#else
+ return handle;
+#endif
+}
+
} // namespace plugin

Powered by Google App Engine
This is Rietveld 408576698