Chromium Code Reviews| 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 if (read_only) | |
| 138 flags |= _O_RDONLY; | |
| 139 else | |
| 140 flags |= _O_RDWR; | |
|
bbudge
2014/05/21 02:04:24
Consider conditional expression:
flags |= read_on
| |
| 141 int32_t posix_desc = _open_osfhandle(file_desc, flags); | |
| 142 if (posix_desc == -1) { | |
| 143 // Close the Windows HANDLE if it can't be converted. | |
| 144 CloseHandle(reinterpret_cast<HANDLE>(file_desc)); | |
| 145 return -1; | |
| 146 } | |
| 147 return posix_desc; | |
| 148 #else | |
| 149 return handle; | |
| 150 #endif | |
| 151 } | |
| 152 | |
| 120 } // namespace plugin | 153 } // namespace plugin |
| OLD | NEW |