• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 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 LIBPANDABASE_OS_FILE_H
17 #define LIBPANDABASE_OS_FILE_H
18 
19 #include "macros.h"
20 
21 #if defined(PANDA_TARGET_UNIX)
22 #include "platforms/unix/libpandabase/file.h"
23 #elif defined(PANDA_TARGET_WINDOWS)
24 #include "platforms/windows/libpandabase/file.h"
25 #else
26 #error "Unsupported platform"
27 #endif
28 
29 #include <string>
30 
31 namespace panda::os::file {
32 
33 #if defined(PANDA_TARGET_UNIX)
34 using File = panda::os::unix::file::File;
35 #elif defined(PANDA_TARGET_WINDOWS)
36 using File = panda::os::windows::file::File;
37 #endif
38 
39 class FileHolder {
40 public:
FileHolder(File file)41     explicit FileHolder(File file) : file_(file) {}
42 
~FileHolder()43     ~FileHolder()
44     {
45         file_.Close();
46     }
47 
48 private:
49     File file_;
50 
51     NO_COPY_SEMANTIC(FileHolder);
52     NO_MOVE_SEMANTIC(FileHolder);
53 };
54 
55 enum class Mode : uint32_t { READONLY, WRITEONLY, READWRITE, READWRITECREATE };
56 
57 File Open(std::string_view filename, Mode mode);
58 
59 }  // namespace panda::os::file
60 
61 #endif  // LIBPANDABASE_OS_FILE_H
62