14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_PLATFORM_FILE_H 174514f5e3Sopenharmony_ci#define ECMASCRIPT_PLATFORM_FILE_H 184514f5e3Sopenharmony_ci 194514f5e3Sopenharmony_ci#ifdef PANDA_TARGET_WINDOWS 204514f5e3Sopenharmony_ci#include <windef.h> 214514f5e3Sopenharmony_ci#include <winbase.h> 224514f5e3Sopenharmony_ci#include <winnt.h> 234514f5e3Sopenharmony_ci#else 244514f5e3Sopenharmony_ci#include <fcntl.h> 254514f5e3Sopenharmony_ci#include <dlfcn.h> 264514f5e3Sopenharmony_ci#endif 274514f5e3Sopenharmony_ci 284514f5e3Sopenharmony_ci#include <string> 294514f5e3Sopenharmony_ci 304514f5e3Sopenharmony_ci#include "ecmascript/ecma_string.h" 314514f5e3Sopenharmony_ci#include "ecmascript/js_tagged_value.h" 324514f5e3Sopenharmony_ci 334514f5e3Sopenharmony_cinamespace panda::ecmascript { 344514f5e3Sopenharmony_ciclass SourceTextModule; 354514f5e3Sopenharmony_ci#ifdef PANDA_TARGET_WINDOWS 364514f5e3Sopenharmony_ciusing fd_t = HANDLE; 374514f5e3Sopenharmony_ci#define INVALID_FD INVALID_HANDLE_VALUE 384514f5e3Sopenharmony_ci 394514f5e3Sopenharmony_ci#define FILE_RDONLY GENERIC_READ 404514f5e3Sopenharmony_ci#define FILE_WRONLY GENERIC_WRITE 414514f5e3Sopenharmony_ci#define FILE_RDWR (GENERIC_READ | GENERIC_WRITE) 424514f5e3Sopenharmony_ci 434514f5e3Sopenharmony_ci#ifdef ERROR 444514f5e3Sopenharmony_ci#undef ERROR 454514f5e3Sopenharmony_ci#endif 464514f5e3Sopenharmony_ci 474514f5e3Sopenharmony_ci#ifdef VOID 484514f5e3Sopenharmony_ci#undef VOID 494514f5e3Sopenharmony_ci#endif 504514f5e3Sopenharmony_ci 514514f5e3Sopenharmony_ci#ifdef CONST 524514f5e3Sopenharmony_ci#undef CONST 534514f5e3Sopenharmony_ci#endif 544514f5e3Sopenharmony_ci#else 554514f5e3Sopenharmony_ciusing fd_t = int; 564514f5e3Sopenharmony_ci#define INVALID_FD (-1) 574514f5e3Sopenharmony_ci 584514f5e3Sopenharmony_ci#define FILE_RDONLY O_RDONLY 594514f5e3Sopenharmony_ci#define FILE_WRONLY O_WRONLY 604514f5e3Sopenharmony_ci#define FILE_RDWR O_RDWR 614514f5e3Sopenharmony_ci#endif 624514f5e3Sopenharmony_ci 634514f5e3Sopenharmony_ci#define FILE_SUCCESS 1 644514f5e3Sopenharmony_ci#define FILE_FAILED 0 654514f5e3Sopenharmony_ci 664514f5e3Sopenharmony_cistd::string PUBLIC_API GetFileDelimiter(); 674514f5e3Sopenharmony_cistd::string PUBLIC_API GetPathSeparator(); 684514f5e3Sopenharmony_cibool PUBLIC_API RealPath(const std::string &path, std::string &realPath, bool readOnly = true); 694514f5e3Sopenharmony_cibool PUBLIC_API RealPathByChar(const char *path, char *realPath, int rowLength, bool readOnly); 704514f5e3Sopenharmony_civoid DPrintf(fd_t fd, const std::string &buffer); 714514f5e3Sopenharmony_civoid Close(fd_t fd); 724514f5e3Sopenharmony_civoid FSync(fd_t fd); 734514f5e3Sopenharmony_ciMemMap PUBLIC_API FileMap(const char *fileName, int flag, int prot, int64_t offset = 0); 744514f5e3Sopenharmony_ciMemMap PUBLIC_API FileMapForAlignAddress(const char *fileName, int flag, int prot, 754514f5e3Sopenharmony_ci int64_t offset, uint32_t offStart); 764514f5e3Sopenharmony_ciint PUBLIC_API FileUnMap(MemMap addr); 774514f5e3Sopenharmony_ciCString ResolveFilenameFromNative(JSThread *thread, const CString &dirname, CString request); 784514f5e3Sopenharmony_cibool PUBLIC_API FileExist(const char *filename); 794514f5e3Sopenharmony_ciint PUBLIC_API Unlink(const char *filename); 804514f5e3Sopenharmony_cibool TryToRemoveSO(JSThread *thread, JSHandle<SourceTextModule> module); 814514f5e3Sopenharmony_civoid *LoadLib(const std::string &libname); 824514f5e3Sopenharmony_civoid *FindSymbol(void *handle, const char *symbol); 834514f5e3Sopenharmony_ciint CloseLib(void *handle); 844514f5e3Sopenharmony_cichar *LoadLibError(); 854514f5e3Sopenharmony_ci} // namespace panda::ecmascript 864514f5e3Sopenharmony_ci#endif // ECMASCRIPT_PLATFORM_FILE_H 87