• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
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 at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * 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 and
13  * limitations under the License.
14  */
15 
16 #ifndef FD_GUARD_H
17 #define FD_GUARD_H
18 
19 namespace OHOS {
20 namespace DistributedFS {
21 class FDGuard {
22 public:
23     FDGuard() = default;
24     FDGuard(int fd, bool autoDestruct);
25     FDGuard(const FDGuard& fdg);
26     FDGuard& operator=(const FDGuard& fdg);
27     explicit FDGuard(int fd);
28     ~FDGuard();
29 
30     int GetFD() const;
31     void SetFD(int fd, bool autoDestruct = true);
32     void ClearFD();
33     void operator=(int fd);
34 
35 private:
36     int fd_ = -1;
37     bool autoDestruct_ = true;
38 };
39 } // namespace DistributedFS
40 } // namespace OHOS
41 #endif