Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/linux/vm/ifaddrs/ScopedFd.h
48461 views
1
/*
2
* Copyright (C) 2009 The Android Open Source Project
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
#ifndef SCOPED_FD_H_included
17
#define SCOPED_FD_H_included
18
#include <unistd.h>
19
// A smart pointer that closes the given fd on going out of scope.
20
// Use this when the fd is incidental to the purpose of your function,
21
// but needs to be cleaned up on exit.
22
class ScopedFd {
23
public:
24
explicit ScopedFd(int fd) : fd(fd) {
25
}
26
~ScopedFd() {
27
close(fd);
28
}
29
int get() const {
30
return fd;
31
}
32
private:
33
int fd;
34
// Disallow copy and assignment.
35
ScopedFd(const ScopedFd&);
36
void operator=(const ScopedFd&);
37
};
38
#endif // SCOPED_FD_H_included
39
40