Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef BASE_SCOPED_HANDLE_H_ |
michael@0 | 6 | #define BASE_SCOPED_HANDLE_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include <stdio.h> |
michael@0 | 9 | |
michael@0 | 10 | #include "base/basictypes.h" |
michael@0 | 11 | |
michael@0 | 12 | #if defined(OS_WIN) |
michael@0 | 13 | #include "base/scoped_handle_win.h" |
michael@0 | 14 | #endif |
michael@0 | 15 | |
michael@0 | 16 | class ScopedStdioHandle { |
michael@0 | 17 | public: |
michael@0 | 18 | ScopedStdioHandle() |
michael@0 | 19 | : handle_(NULL) { } |
michael@0 | 20 | |
michael@0 | 21 | explicit ScopedStdioHandle(FILE* handle) |
michael@0 | 22 | : handle_(handle) { } |
michael@0 | 23 | |
michael@0 | 24 | ~ScopedStdioHandle() { |
michael@0 | 25 | Close(); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | void Close() { |
michael@0 | 29 | if (handle_) { |
michael@0 | 30 | fclose(handle_); |
michael@0 | 31 | handle_ = NULL; |
michael@0 | 32 | } |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | FILE* get() const { return handle_; } |
michael@0 | 36 | |
michael@0 | 37 | FILE* Take() { |
michael@0 | 38 | FILE* temp = handle_; |
michael@0 | 39 | handle_ = NULL; |
michael@0 | 40 | return temp; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | void Set(FILE* newhandle) { |
michael@0 | 44 | Close(); |
michael@0 | 45 | handle_ = newhandle; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | private: |
michael@0 | 49 | FILE* handle_; |
michael@0 | 50 | |
michael@0 | 51 | DISALLOW_EVIL_CONSTRUCTORS(ScopedStdioHandle); |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | #endif // BASE_SCOPED_HANDLE_H_ |