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

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: fix nits 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
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/utility.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..eaf525016f4b42e93bb8a231148f63d82920de8a 100644
--- a/ppapi/native_client/src/trusted/plugin/utility.cc
+++ b/ppapi/native_client/src/trusted/plugin/utility.cc
@@ -117,4 +117,34 @@ 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;
+ flags |= read_only ? _O_RDONLY : _O_RDWR;
+ 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
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/utility.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698