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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698