Index: ppapi/native_client/src/trusted/plugin/file_utils.cc |
diff --git a/ppapi/native_client/src/trusted/plugin/file_utils.cc b/ppapi/native_client/src/trusted/plugin/file_utils.cc |
index d83432785b2ac433404ec4ae8d35104eac3a6264..639c3e49b186f9b1a13a900d614f6650eefc435d 100644 |
--- a/ppapi/native_client/src/trusted/plugin/file_utils.cc |
+++ b/ppapi/native_client/src/trusted/plugin/file_utils.cc |
@@ -16,6 +16,7 @@ |
#include "native_client/src/include/nacl_scoped_ptr.h" |
#include "native_client/src/include/portability_io.h" |
#include "native_client/src/include/portability_string.h" |
+#include "ppapi/native_client/src/trusted/plugin/utility.h" |
namespace plugin { |
@@ -72,6 +73,25 @@ StatusCode SlurpFile(int32_t fd, |
return PLUGIN_FILE_SUCCESS; |
} |
+// Converts a PP_FileHandle to a POSIX file descriptor. |
+int32_t ConvertFileDescriptor(PP_FileHandle handle) { |
+ 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<uintptr_t>(handle); |
+ // Convert the Windows HANDLE from Pepper to a POSIX file descriptor. |
+ int32_t posix_desc = _open_osfhandle(file_desc, _O_RDWR | _O_BINARY); |
+ 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 file_utils |
} // namespace plugin |
- |