Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/os/linux/vm/ifaddrs/ScopedFd.h
48785 views
/*1* Copyright (C) 2009 The Android Open Source Project2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/15#ifndef SCOPED_FD_H_included16#define SCOPED_FD_H_included17#include <unistd.h>18// A smart pointer that closes the given fd on going out of scope.19// Use this when the fd is incidental to the purpose of your function,20// but needs to be cleaned up on exit.21class ScopedFd {22public:23explicit ScopedFd(int fd) : fd(fd) {24}25~ScopedFd() {26close(fd);27}28int get() const {29return fd;30}31private:32int fd;33// Disallow copy and assignment.34ScopedFd(const ScopedFd&);35void operator=(const ScopedFd&);36};37#endif // SCOPED_FD_H_included383940