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.
1 // Copyright (c) 2006-2008 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.
5 #ifndef BASE_SCOPED_HANDLE_H_
6 #define BASE_SCOPED_HANDLE_H_
8 #include <stdio.h>
10 #include "base/basictypes.h"
12 #if defined(OS_WIN)
13 #include "base/scoped_handle_win.h"
14 #endif
16 class ScopedStdioHandle {
17 public:
18 ScopedStdioHandle()
19 : handle_(NULL) { }
21 explicit ScopedStdioHandle(FILE* handle)
22 : handle_(handle) { }
24 ~ScopedStdioHandle() {
25 Close();
26 }
28 void Close() {
29 if (handle_) {
30 fclose(handle_);
31 handle_ = NULL;
32 }
33 }
35 FILE* get() const { return handle_; }
37 FILE* Take() {
38 FILE* temp = handle_;
39 handle_ = NULL;
40 return temp;
41 }
43 void Set(FILE* newhandle) {
44 Close();
45 handle_ = newhandle;
46 }
48 private:
49 FILE* handle_;
51 DISALLOW_EVIL_CONSTRUCTORS(ScopedStdioHandle);
52 };
54 #endif // BASE_SCOPED_HANDLE_H_