OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include <stdarg.h> | 7 #include <stdarg.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 static const PPB_NaCl_Private* g_nacl_interface = NULL; | 110 static const PPB_NaCl_Private* g_nacl_interface = NULL; |
111 | 111 |
112 const PPB_NaCl_Private* GetNaClInterface() { | 112 const PPB_NaCl_Private* GetNaClInterface() { |
113 return g_nacl_interface; | 113 return g_nacl_interface; |
114 } | 114 } |
115 | 115 |
116 void SetNaClInterface(const PPB_NaCl_Private* nacl_interface) { | 116 void SetNaClInterface(const PPB_NaCl_Private* nacl_interface) { |
117 g_nacl_interface = nacl_interface; | 117 g_nacl_interface = nacl_interface; |
118 } | 118 } |
119 | 119 |
| 120 void CloseFileHandle(PP_FileHandle file_handle) { |
| 121 #if NACL_WINDOWS |
| 122 CloseHandle(file_handle); |
| 123 #else |
| 124 close(file_handle); |
| 125 #endif |
| 126 } |
| 127 |
| 128 // Converts a PP_FileHandle to a POSIX file descriptor. |
| 129 int32_t ConvertFileDescriptor(PP_FileHandle handle, bool read_only) { |
| 130 PLUGIN_PRINTF(("ConvertFileDescriptor, handle=%d\n", handle)); |
| 131 #if NACL_WINDOWS |
| 132 int32_t file_desc = NACL_NO_FILE_DESC; |
| 133 // On Windows, valid handles are 32 bit unsigned integers so this is safe. |
| 134 file_desc = reinterpret_cast<intptr_t>(handle); |
| 135 // Convert the Windows HANDLE from Pepper to a POSIX file descriptor. |
| 136 int flags = _O_BINARY; |
| 137 flags |= read_only ? _O_RDONLY : _O_RDWR; |
| 138 int32_t posix_desc = _open_osfhandle(file_desc, flags); |
| 139 if (posix_desc == -1) { |
| 140 // Close the Windows HANDLE if it can't be converted. |
| 141 CloseHandle(reinterpret_cast<HANDLE>(file_desc)); |
| 142 return -1; |
| 143 } |
| 144 return posix_desc; |
| 145 #else |
| 146 return handle; |
| 147 #endif |
| 148 } |
| 149 |
120 } // namespace plugin | 150 } // namespace plugin |
OLD | NEW |