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 #endif 26 27 #include <string> 28 29 #include "ecmascript/platform/map.h" 30 #include "ecmascript/ecma_string.h" 31 #include "ecmascript/js_tagged_value.h" 32 namespace panda::ecmascript { 33 #ifdef PANDA_TARGET_WINDOWS 34 using fd_t = HANDLE; 35 #define INVALID_FD INVALID_HANDLE_VALUE 36 37 #define FILE_RDONLY GENERIC_READ 38 #define FILE_WRONLY GENERIC_WRITE 39 #define FILE_RDWR (GENERIC_READ | GENERIC_WRITE) 40 41 #ifdef ERROR 42 #undef ERROR 43 #endif 44 45 #ifdef VOID 46 #undef VOID 47 #endif 48 49 #ifdef CONST 50 #undef CONST 51 #endif 52 #else 53 using fd_t = int; 54 #define INVALID_FD (-1) 55 56 #define FILE_RDONLY O_RDONLY 57 #define FILE_WRONLY O_WRONLY 58 #define FILE_RDWR O_RDWR 59 #endif 60 61 #define FILE_SUCCESS 1 62 #define FILE_FAILED 0 63 64 std::string GetFileDelimiter(); 65 bool RealPath(const std::string &path, std::string &realPath, bool readOnly = true); 66 void DPrintf(fd_t fd, const std::string &buffer); 67 void Close(fd_t fd); 68 void FSync(fd_t fd); 69 MemMap FileMap(const char *fileName, int flag, int prot, int64_t offset = 0); 70 int FileUnMap(MemMap addr); 71 JSHandle<EcmaString> ResolveFilenameFromNative(JSThread *thread, JSTaggedValue dirname, 72 JSTaggedValue request); 73 } // namespace panda::ecmascript 74 #endif // ECMASCRIPT_PLATFORM_FILE_H 75