1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "ppapi/cpp/private/pass_file_handle.h" 6 7 #ifdef _WIN32 8 # include <windows.h> 9 #else 10 # include <unistd.h> 11 #endif 12 13 namespace pp { 14 PassFileHandle()15PassFileHandle::PassFileHandle() 16 : handle_(PP_kInvalidFileHandle) { 17 } 18 PassFileHandle(PP_FileHandle handle)19PassFileHandle::PassFileHandle(PP_FileHandle handle) 20 : handle_(handle) { 21 } 22 PassFileHandle(PassFileHandle & handle)23PassFileHandle::PassFileHandle(PassFileHandle& handle) 24 : handle_(handle.Release()) { 25 } 26 ~PassFileHandle()27PassFileHandle::~PassFileHandle() { 28 Close(); 29 } 30 Release()31PP_FileHandle PassFileHandle::Release() { 32 PP_FileHandle released = handle_; 33 handle_ = PP_kInvalidFileHandle; 34 return released; 35 } 36 Close()37void PassFileHandle::Close() { 38 if (handle_ != PP_kInvalidFileHandle) { 39 #ifdef _WIN32 40 CloseHandle(handle_); 41 #else 42 close(handle_); 43 #endif 44 handle_ = PP_kInvalidFileHandle; 45 } 46 } 47 48 } // namespace pp 49