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 INTERFACES_KITS_JS_SRC_MOD_FILEIO_COMMON_FUNC_H 17 #define INTERFACES_KITS_JS_SRC_MOD_FILEIO_COMMON_FUNC_H 18 19 #include "../common/napi/uni_header.h" 20 21 namespace OHOS { 22 namespace DistributedFS { 23 namespace ModuleFileIO { 24 constexpr int64_t INVALID_POSITION = std::numeric_limits<decltype(INVALID_POSITION)>::max(); 25 constexpr int RDONLY = 00; 26 constexpr int WRONLY = 01; 27 constexpr int RDWR = 02; 28 constexpr int CREATE = 0100; 29 constexpr int TRUNC = 01000; 30 constexpr int APPEND = 02000; 31 constexpr int NONBLOCK = 04000; 32 constexpr int DIRECTORY = 0200000; 33 constexpr int NOFOLLOW = 0400000; 34 constexpr int SYNC = 04010000; 35 36 void InitOpenMode(napi_env env, napi_value exports); 37 38 struct CommonFunc { 39 static unsigned int ConvertJsFlags(unsigned int &flags); 40 static std::tuple<bool, void *, size_t, int64_t, int64_t> GetReadArg(napi_env env, 41 napi_value readBuf, 42 napi_value option); 43 static std::tuple<bool, void *, int64_t, bool, int64_t> GetReadArgV9(napi_env env, 44 napi_value readBuf, 45 napi_value option); 46 static std::tuple<bool, std::unique_ptr<char[]>, void *, size_t, int64_t> GetWriteArg(napi_env env, 47 napi_value argWBuf, 48 napi_value argOption); 49 static std::tuple<bool, std::unique_ptr<char[]>, void *, int64_t, bool, int64_t> GetWriteArgV9(napi_env env, 50 napi_value argWBuf, napi_value argOption); 51 static std::tuple<bool, std::unique_ptr<char[]>, std::unique_ptr<char[]>> GetCopyPathArg(napi_env env, 52 napi_value srcPath, napi_value dstPath); 53 }; 54 } // namespace ModuleFileIO 55 } // namespace DistributedFS 56 } // namespace OHOS 57 #endif