• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 ECMASCRIPT_PLATFORM_FILE_H
17 #define ECMASCRIPT_PLATFORM_FILE_H
18 
19 #ifdef PANDA_TARGET_WINDOWS
20 #include <windef.h>
21 #include <winbase.h>
22 #include <winnt.h>
23 #else
24 #include <fcntl.h>
25 #include <dlfcn.h>
26 #endif
27 
28 #include <string>
29 
30 #include "ecmascript/ecma_string.h"
31 #include "ecmascript/js_tagged_value.h"
32 namespace panda::ecmascript {
33 class SourceTextModule;
34 #ifdef PANDA_TARGET_WINDOWS
35 using fd_t = HANDLE;
36 #define INVALID_FD INVALID_HANDLE_VALUE
37 
38 #define FILE_RDONLY GENERIC_READ
39 #define FILE_WRONLY GENERIC_WRITE
40 #define FILE_RDWR (GENERIC_READ | GENERIC_WRITE)
41 
42 #ifdef ERROR
43 #undef ERROR
44 #endif
45 
46 #ifdef VOID
47 #undef VOID
48 #endif
49 
50 #ifdef CONST
51 #undef CONST
52 #endif
53 #else
54 using fd_t = int;
55 #define INVALID_FD (-1)
56 
57 #define FILE_RDONLY O_RDONLY
58 #define FILE_WRONLY O_WRONLY
59 #define FILE_RDWR O_RDWR
60 #endif
61 
62 #define FILE_SUCCESS 1
63 #define FILE_FAILED 0
64 
65 std::string GetFileDelimiter();
66 bool RealPath(const std::string &path, std::string &realPath, bool readOnly = true);
67 void DPrintf(fd_t fd, const std::string &buffer);
68 void Close(fd_t fd);
69 void FSync(fd_t fd);
70 MemMap FileMap(const char *fileName, int flag, int prot, int64_t offset = 0);
71 int FileUnMap(MemMap addr);
72 JSHandle<EcmaString> ResolveFilenameFromNative(JSThread *thread, JSTaggedValue dirname,
73                                                JSTaggedValue request);
74 bool FileExist(const char *filename);
75 int Unlink(const char *filename);
76 bool TryToRemoveSO(JSThread *thread, JSHandle<SourceTextModule> module);
77 }  // namespace panda::ecmascript
78 #endif  // ECMASCRIPT_PLATFORM_FILE_H
79