ipc/chromium/src/base/scoped_handle.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/scoped_handle.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#ifndef BASE_SCOPED_HANDLE_H_
     1.9 +#define BASE_SCOPED_HANDLE_H_
    1.10 +
    1.11 +#include <stdio.h>
    1.12 +
    1.13 +#include "base/basictypes.h"
    1.14 +
    1.15 +#if defined(OS_WIN)
    1.16 +#include "base/scoped_handle_win.h"
    1.17 +#endif
    1.18 +
    1.19 +class ScopedStdioHandle {
    1.20 + public:
    1.21 +  ScopedStdioHandle()
    1.22 +      : handle_(NULL) { }
    1.23 +
    1.24 +  explicit ScopedStdioHandle(FILE* handle)
    1.25 +      : handle_(handle) { }
    1.26 +
    1.27 +  ~ScopedStdioHandle() {
    1.28 +    Close();
    1.29 +  }
    1.30 +
    1.31 +  void Close() {
    1.32 +    if (handle_) {
    1.33 +      fclose(handle_);
    1.34 +      handle_ = NULL;
    1.35 +    }
    1.36 +  }
    1.37 +
    1.38 +  FILE* get() const { return handle_; }
    1.39 +
    1.40 +  FILE* Take() {
    1.41 +    FILE* temp = handle_;
    1.42 +    handle_ = NULL;
    1.43 +    return temp;
    1.44 +  }
    1.45 +
    1.46 +  void Set(FILE* newhandle) {
    1.47 +    Close();
    1.48 +    handle_ = newhandle;
    1.49 +  }
    1.50 +
    1.51 + private:
    1.52 +  FILE* handle_;
    1.53 +
    1.54 +  DISALLOW_EVIL_CONSTRUCTORS(ScopedStdioHandle);
    1.55 +};
    1.56 +
    1.57 +#endif // BASE_SCOPED_HANDLE_H_

mercurial