1 /*
2  * Copyright (C) 2024 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 ANDROID_DEVICE_GOOGLE_CUTTLEFISH_HOST_COMMANDS_PROCESS_SANDBOXER_UNIQUE_FD_H
17 #define ANDROID_DEVICE_GOOGLE_CUTTLEFISH_HOST_COMMANDS_PROCESS_SANDBOXER_UNIQUE_FD_H
18 
19 namespace cuttlefish {
20 namespace process_sandboxer {
21 
22 class UniqueFd {
23  public:
24   UniqueFd() = default;
25   explicit UniqueFd(int fd);
26   UniqueFd(UniqueFd&&);
27   UniqueFd(UniqueFd&) = delete;
28   ~UniqueFd();
29   UniqueFd& operator=(UniqueFd&&);
30 
31   int Get() const;
32   int Release();
33   void Reset(int fd);
34 
35  private:
36   void Close();
37 
38   int fd_ = -1;
39 };
40 
41 }  // namespace process_sandboxer
42 }  // namespace cuttlefish
43 
44 #endif
45